If you're viewing this in VSCode, it's recommended that you open it in a preview with `Ctrl+Shift+V`!
</sub>
---
<br>
<centerid="start">
<h2style="font-size: 42px">
<imgsrc="docs/uranium.png"height="42px"alt="">
<b>Uranium Template</b><em>α</em>
</h2>
<emstyle="font-family: 'Comic Sans MS', 'Comic Sans', Impact, Arial">Official manual!!!!</em>
</center>
<br>
**Uranium Template** is a Love2D-inspired NotITG game development template, focusing on keeping things as **Lua-pure** as possible with enough abstractions to make you feel like you're not dealing with Stepmania jank at all.
Uranium Template originally formed during the creation of a currently unreleased project, and since then I've went ahead and refined and polished it up to be usable on its own. Most of the design decisions came from experience using prototype versions of it!
- [Testimonies](#testimonies)
- [Installation](#installation)
- [Distribution](#distribution)
- [How do I start writing code?](#how-do-i-start-writing-code)
- "this template really adds some spice to your modfiles. think industrial glitter in your next chilli!" _- Mayflower_
- "a good template that i have definitely used! jill can i go now. jill please i just want to see my family" _- Aura_
## Installation
Installation is the exact same as any other NotITG template:
1. Unzip your installation zip, as you would a modfile
2. Edit `Song.sm` in your editor of choice (ArrowVortex, NotITG) to include necessary metadata; replace `silence.ogg` with an actual track, if necessary
3. Edit `main.lua` to do whatever you wish to do with it! The entirety of the `src/` folder is yours!
4._(Recommended)_ Install [sumneko's Lua LSP](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) and grab the latest NotITG typings [here](https://gitlab.com/CraftedCart/notitg_docs/-/archive/master/notitg_docs-master.zip?path=lua) (put them in a folder like `.typings`!)
## Distribution
After you're done with writing your file, be sure to take these steps to reduce the filesize and get your game ready for zipping up!
- Remove `MANUAL.md`, `jillo_png.png`, `docs/`, `.vscode/`, `.gitconfig`, `.gitignore` and `template/typings.lua`. These are files that aren't necessary outside of a development environment!
- Optionally, remove `Song.sm.auto` and `Song.sm.old`. These files may not exist depending on certain factors.
- If you've followed step 4 during [Installation](#installation), be sure to remove your typings folder (likely `.typings`)
- If you're using Git, **PLEASE REMOVE YOUR `.git/` FOLDER!!!**
Afterwards, it should be safe to zip everything up and send it over!
## How do I start writing code?
`main.lua` is the entry-point for your code! From there, you can do the following:
- [Define some actors](#defining-actors), and [call initialization methods on those actors](#initializing-actors) to set them up
- [Define callbacks](#callback-usage), such as the [update](#uraniumupdatedt-number) callback
All actors that take in filenames have their filenames starting from the root of the project; meaning if you had a file in `myModFile/src/test.png`, you'd have to pass in a filename of `src/test.png`. **If an image is blank, or a single pink pixel, it hasn't loaded properly.**
Once you have an actor defined, you can run whatever methods you want.
> **Note**
> Even though you get a fully functional actor, what you actually get is a _proxied actor_! What this means for you is that you really shouldn't call any getters on the actor, as it'll just return `nil`.
```lua
local text = BitmapText('common', 'hello, world!')
text:xy(scx, scy)
text:zoom(2.3)
text:rotationz(30)
text:diffuse(1, 0.8, 0.8, 1)
```
All methods that you run upon definition will be ran again at the start of every frame:
```lua
local quad = Quad()
quad:xy(scx, scy)
quad:zoomto(60, 60)
quad:diffusealpha(1)
function uranium.update()
-- doesn't need a reset! it'll automatically zoomto 60, 60 and set its alpha to 1
quad:Draw()
quad:zoomto(120, 120)
quad:diffusealpha(0.5)
quad:Draw()
end
```
If you want to avoid this, or otherwise call getter methods, use the [`uranium.init`](#uraniuminit) callback:
```lua
local sprite = Sprite()
function uranium.init()
someTexture = sprite:GetTexture()
end
```
Alternatively, you can also use the actors' individual `InitCommand`s:
See [the AFT example](#afts) for a quick setup to play around with, or the example in the [aft library](#aft) for a barebones setup. The ability to dynamically adjust at which point in the stack they render makes them _a lot_ more powerful than you'd expect.
Due to Uranium Template's recursive actor loader, these are impossible to implement in a meaningful way. Actors are loaded in a manner like so:
```lua
local actor1 = Quad()
local actor2 = Sprite()
local actor3 = BitmapText()
```
```xml
<LayerType="ActorFrame"/>
<children>
<LayerType="Quad"/>
<LayerType="ActorFrame"/>
<children>
<LayerType="Sprite"/>
<LayerType="ActorFrame"/>
<children>
<LayerType="BitmapText"/>
</children>
</children>
</children>
```
This is a technical limitation; NotITG does not allow loading a dynamic amount of arbitrary actors defined via Lua in any way other than this (as far as I know). Meaning, if you defined an `ActorFrame` or `ActorScroller`, you would not be able to add anything to its' children.
However, if you're looking to do what `ActorFrame` does, the standard library `transform` module can handle that for you! (NYI)
Uranium uses a unique callback system - to define a callback, you define a function under `uranium.` with your desired callback name:
```lua
function uranium.update(dt)
-- runs every frame
end
```
You can do this as many times as you like - it'll call every single function that's defined as `uranium.update`, not just the last!
If you return a non-falsy value in a callback, however, it'll cancel every other callback after it. This can be useful for, eg. capturing inputs and ensuring they don't get passed through to other callbacks on accident.
### Default callbacks
These are the callbacks that are built into Uranium:
#### `uranium.update(dt: number)`
Called every frame. `dt` is the time passed since the last frame, the "deltatime".
#### `uranium.init()`
Called once on `OnCommand`. Every actor has been created, and the game should be starting shortly.
### Custom callbacks
Custom callbacks require no extra setup. Define your callback like usual:
`vector2D` is a simple 2D vector class system. For example, to define a vector:
```lua
local vec = vector2D(0, 0)
-- or
local vec = vector(0, 0)
-- or
local vec = vector(0)
-- or
local vec = vector()
```
Then add another vector to it:
```lua
vec = vec + vector(1)
print(vec) --> (1, 1)
```
Then measure its length:
```lua
local len = vec:length()
print(len) --> 1.4142135623730951
-- (sqrt of 2)
```
Then rotate it and index it:
```lua
vec:rotate(180)
local x = vec.x
-- or
local x = vec[1]
print(x) --> -1
```
#### `vector2D(x: number | nil, y: number | nil): vector2D`
Creates a new vector. If only `x` is passed in, `y` = `x`. If no arguments are passed, `x` = `y` = `0`.
#### `vectorFromAngle(ang: number | nil, amp: number | nil): vector2D`
Creates a new vector pointing in a specific angle. **Specify `ang` in degrees.**`ang` defaults to 0, `amp` defaults to 1.
#### `vector2D:length(): number`
Returns the vector's length. Equal to `vector:distance(vector())`.
#### `vector2D:lengthSquared(): number`
Returns the vector's length, squared. Here mainly for optimization purposes; this is a cheaper version of [`length()`](#vectorlength-number) that's less accurate.
#### `vector2D:angle(): number`
Returns the vector's angle in radians. <!--(TODO: why?)-->
#### `vector2D:normalize(): vector2D`
Normalizes the vector, setting its length to 1 but keeping its angle. Equal to `vector:resize(1)`
#### `vector2D:resize(length: number): vector2D`
Resizes the vector, setting its length but keeping its angle.
#### `vector2D:unpack(): number, number`
Unpacks the vector into its X and Y coordinates. Useful for quickly unpacking it into a function call:
Gets the distance between one vector and another, squared. Here mainly for optimization purposes; this is a cheaper version of [`distance()`](#vectordistancevect-vector-number) that's less accurate.
#### Operations
Here are all valid operations for vectors:
-`vector2D + number`: equal to `vector2D + vector2D(number)`
-`vector2D + vector2D`: adds the vectors' X and Y coordinates together, respectively, forming a new vector
-`vector2D - number`: equal to `vector2D - vector2D(number)`
-`vector2D - vector2D`: subtracts the vectors' X and Y coordinates, respectively, forming a new vector
-`vector2D * number`: equal to `vector2D * vector2D(number)`
-`vector2D * vector2D`: multiplies the vectors' X and Y coordinates together, respectively, forming a new vector
-`vector2D / number`: equal to `vector2D / vector2D(number)`
-`vector2D / vector2D`: divides the vectors' X and Y coordinates, respectively, forming a new vector
-`vector2D == vector2D`: checks if the two vectors' X and Y coordinates are equivalent; returns false with any other type
-`-vector2D`: negates the X and Y coordinates of the vector
Constructs a new color using the `h`, `s`, `l` and `a` values using the [HSL color model](https://en.wikipedia.org/wiki/HSL_and_HSV). Assumes all values are contained in the set [0, 1]. `a` defaults to 1; `h` wraps around.
Constructs a new color using the `h`, `s`, `v` and `a` values using the [HSV color model](https://en.wikipedia.org/wiki/HSL_and_HSV). Assumes all values are contained in the set [0, 1]. `a` defaults to 1; `h` wraps around.
Equal to [`hsv()`](#hsvh-number-s-number-v-number-a-number--nil), except the hue value is smoothed using cubic smoothing. Not accurate, but produces neater-looking color blends for rainbow-shifting colors.
```lua
local rainbow = shsv(t, 1, 0.5)
```
#### `hex(hex: string): color`
Reads in a hex string and parses it into a `color`. Accepted hex string formats are `#ffffff`, `ffffff`, `#fff` and `fff`.
Unpacks the color into its R, G, B and A values. Useful for `diffuse`:
```lua
local quad = Quad()
quad:diffuse(col:unpack())
```
#### `color:rgb(): number, number, number`
Returns the color's R, G and B values.
#### `color:hsl(): number, number, number`
Returns the color's H, S and L values in the [HSL color model](https://en.wikipedia.org/wiki/HSL_and_HSV).
#### `color:hsv(): number, number, number`
Returns the color's H, S and V values in the [HSV color model](https://en.wikipedia.org/wiki/HSL_and_HSV).
#### `color:hex(): string`
Returns the color's hex string representation in the format `ffffff`.
#### `color:hue(h: number): color`
Sets the color's hue value in the [HSL/HSV color model](https://en.wikipedia.org/wiki/HSL_and_HSV).
#### `color:huesmooth(h: number): color`
Equivalent to [`color:hue()`](#colorhueh-number-color), except the hue value is smoothed using cubic smoothing. Not accurate, but produces neater-looking color blends for rainbow-shifting colors.
#### `color:alpha(a: number): color`
Sets the color's alpha channel.
#### `color:malpha(a: number): color`
Sets the color's alpha channel, multiplying the previous value with `a`.
#### `color:invert(): color`
Inverts the color.
#### `color:grayscale(): color`
Makes the color grayscale using a more accurate formula than just multiplying every value by `0.5`.
#### `color:hueshift(a: number): color`
Shifts the color's hue by `a`.
#### Operations
Here are all valid operations for colors:
-`color + number`: equal to `color + rgb(number, number, number)`
-`color + color`: adds the colors' R, G and B values together, respectively, forming a new color
-`color - number`: equal to `color - rgb(number, number, number)`
-`color - color`: subtracts the colors' R, G and B values, respectively, forming a new color
-`color * number`: equal to `color * rgb(number, number, number)`
-`color * color`: multiplies the colors' R, G and B values together, respectively, forming a new color
-`color / number`: equal to `color / rgb(number, number, number)`
-`color / color`: divides the colors' R, G and B values, respectively, forming a new color
-`color == color`: checks if the two colors' R, G and B values are equivalent; returns false with any other type
-- each time you want to set it, call this instead
n:set(value)
-- or
n:add(value)
-- to avoid the ease, do this instead
n:reset(value)
-- then, in your update function
function uranium.update(dt)
n(dt) -- multiply this image by some value to speed it up
print(n.a) -- retrieve the eased value
print(n.toa) -- retrieve the target value it's easing towards
end
```
#### `easable(default: number): easable`
Creates a new easable, setting the default to `default`. Can technically be anything that has `T * number`, `number - T` and `T + T` defined, including a `vector2D`.
#### `easable:set(new: number): void`
Sets the target value (`toa`) to `new`, easing the current value to the new value.
#### `easable:add(new: number): void`
Equivalent to `easable:add(easable.toa + new)`.
#### `easable:reset(new: number): void`
Sets the current (`a`) and target (`toa`) values to `new`, **not** easing the current value to the new value.
#### Operations
Every operation supported on the eased value is supported with an `easable`.
`input` is the library that handles everything input-related. Its main feature is providing the `press` and `release` callbacks, but you can also access the raw inputs with the `inputs` table (each value is `-1` if the key is not pressed and the time at which it was pressed, estimated with `t` if it is pressed) and the _raw_ inputs (ignoring callback returns) with `rawInputs`. Additionally, for your convinience, it provides a `directions` enum:
Called when the player presses on a certain key. **Currently only supports arrow keys!!**`direction` can be `Left`, `Down`, `Up` or `Right` (TODO: change this to an enum).
#### `uranium.release(direction: string)`
Same as [`uranium.press`](#uraniumpressdirection-string), except for releasing a key.
Working with left/down/up/right inputs can be tiring at times and it's hard to always fit designs to work with them. However, if you're willing to take a little compromise, you can also _access all keyboard inputs_. However, it's worth noting that this **depends on NotITG's Simply Love** (any forks will work fine too) both for your development environment and for all players. That being said, if you want to access the keyboard API, this is how you do it:
```lua
-- check if the user is using simply love at all
if not stitch then error('This modfile requires the Simply Love theme! https://github.com/TaroNuke/Simply-love-NotITG-ver.-') end
keyboard = stitch('lua.keyboard')
-- table that contains every keyboard key as the key and a boolean as the value
local buffer = keyboard.buffer
-- for example:
local isDebugKeyHeld = buffer['F3']
-- contains booleans for shift, ctrl, alt, win and altgr
local special = keyboard.special
local isDebugKeyAndShiftHeld = isDebugKeyHeld and special.shift
```
### `bitop`
A Lua 5.0 port of [bitop-lua](https://github.com/AlberTajuelo/bitop-lua). See their repository for documentation.
Initializes a new RNG class. `seed` must be a table of size 4; if it is not provided, `os.time()` is used in its place. _(Not `os.clock()`!!! Two RNG values created at the same time with no provided seed will be the same.)_
#### `rng(a: number | nil, b: number | nil): number`
Acts identical to `math.random()`. Pass in no arguments to get a random float from 0 to 1, pass in one argument to get a random inclusive integer from 1 to `a`, pass in two arguments to get a random integer from `a` to `b`.
#### `rng:int(min: number, max: number | nil): number`
Generates an inclusive random integer. Pass in one argument to get a random integer from 1 to `a`, pass in two arguments to get a random integer from `a` to `b`.
#### `rng:float(max: number | nil): number`
Generates a random fractional number from `0` to `max`. `max` defaults to 1.
#### `rng:bool(): boolean`
Generates either a `true` or a `false` randomly.
#### `rng:seed(seed: number): void`
Sets the seed and advances the state.
#### `rng:next(): number`
Gets the next pseudo-random value. Recommended to use [`int`](#rngintmin-number-max-number-number), [`float`](#rngfloatmax-number--nil-number), etc. over this.
#### `rng:jump(): void`
The jump function:
> This is the jump function for the generator. It is equivalent
> to 2^64 calls to next(); it can be used to generate 2^64
> non-overlapping subsequences for parallel computations.
#### `rng:longJump(): void`
The long-jump function:
> This is the long-jump function for the generator. It is equivalent to
> 2^96 calls to next(); it can be used to generate 2^32 starting points,
> from each of which jump() will generate 2^32 non-overlapping
> subsequences for parallel distributed computations.
A direct copy of [Mirin Template's `ease.lua`](https://github.com/XeroOl/notitg-mirin/blob/master/template/ease.lua), for convinience. See the docs for those [**here**](https://xerool.github.io/notitg-mirin/docs/eases.html).
**XeroOl** - Mirin Template was a massive design inspiration; early stages of this template borrowed lots of code from it and the current `require` implementation has been grabbed directly from it<br>