Skip to content

Commit

Permalink
Fix documentation, several various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudospective committed Aug 30, 2022
1 parent 005fb10 commit 7ad4d1f
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 150 deletions.
49 changes: 31 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ Kitsu template is special in the sense that you don't have to use a built-in mod

You can include libraries in `mods.lua` by using the `import` function.
```lua
local std = import 'stdlib' -- Kitsu Standard Library
local Node = import 'konko-node' -- Konko Node
local Mods = import 'konko-mods' -- Konko Mods
import 'stdlib' -- Kitsu Standard Library
import 'konko-node' -- Konko Node
import 'konko-mods' -- Konko Mods
local TweensEXT = import 'extended-tweens' -- Extended Tweens Library
```

There are more libraries you can find [here](https://github.com/Tiny-Foxes/kitsu-template-libraries/).

## Using Konko Node
Konko Node allows a new, streamlined syntax that reduces the need for actor tables.To create a node, simply call the `Node.new` function.
Konko Node allows a new, streamlined syntax that reduces the need for actor tables. To create a node, simply call the `Node.new` function.
```lua
local MyNode = Node.new('Sprite') -- You can pass in a string naming the type of Actor, or an entire Actor itself.
```
Expand All @@ -35,7 +36,7 @@ MyNode:SetUpdate(function(self, dt)
self:addrotationz(360 * dt) -- dt stands for "delta time" - the amount of seconds since last frame.
end)
MyNode:SetInput(function(self, event)
if event.type == "InputEventType_FirstPress" then
if event.type:find('Press') then
SCREENMAN:SystemMessage(event.button)
end
end)
Expand All @@ -48,7 +49,7 @@ MyNode:SetAttribute('Texture', 'path/to/texture.png')

Finally, you can add your node to the node tree. You can give it a name, and index, both, or neither. Giving it a name will allow you to use this node in its Actor form after its construction.
```lua
MyNode:AddToTree('MyNode', 1)
MyNode:AddToTree(1, 'MyNode')
```
More documentation avaiable in `konko-nodes.lua`.

Expand All @@ -62,16 +63,17 @@ This will ease `invert` at its current percent to `100` starting at beat `0` for

You can insert mods using three different functions. These examples all do the same thing, but each with their own syntax and advantages.
```lua
-- In-house method - Recommended for inserting tables of percent-mod pairs
-- In-house method
Mods:Insert(0, 4, Tweens.outelastic, {
{100, 'invert'},
{100, 'tipsy'}
-- You can also specify a starting percent.
{100, 'tipsy', -100}
})

-- Mirin Method - Recommended for fast mod prototyping
-- Mirin Method
Mods:Mirin {0, 4, Tweens.outelastic, 100, 'invert', 100, 'tipsy'}

-- Exschwasion Method - Recommended for easy troubleshooting
-- Exschwasion Method
Mods:Exsch(0, 4, 0, 100, 'invert', 'len', Tweens.outelastic)
Mods:Exsch(0, 4, 0, 100, 'tipsy', 'len', Tweens.outelastic)
```
Expand All @@ -94,30 +96,41 @@ There's really no limit to what you can write for a library. Since the only requ

1. If you need a certain library to function, include it! remember to use `import` for anything you'll need.
1. Try to keep your library local to avoid interfering with other libraries. Even the included standard library is local!
2. If you write a library and you need to add an actor, you should do this with `FG[#FG + 1] = Def.ActorFrame {}`. This is the same `FG` that is created in `env.lua` and added to the ActorFrame in `init.lua`. This `FG` ActorFrame has an update loop already provided that will call `UpdateCommand` every frame.
3. Another thing to consider if you write your own standard library is that you may need to write your own mod loader as well. This is why one is included. It may not make writing a mod loader clear, but it will give you an idea of what it may expect from your standard library.
4. You're more than welcome to submit your library to the [Template Library Repository](https://github.com/Tiny-Foxes/kitsu-template-libraries/)! Once approved, it will be listed with others in an easy-to-find location.
1. If you write a library and you need to add an actor, you should do this with `FG[#FG + 1] = Def.ActorFrame {}`. This is the same `FG` that is created in `env.lua` and added to the ActorFrame in `init.lua`. This `FG` ActorFrame has an update loop already provided that will call `UpdateCommand` every frame.
1. Another thing to consider if you write your own standard library is that you may need to write your own mod loader as well. This is why one is included. It may not make writing a mod loader clear, but it will give you an idea of what it may expect from your standard library.
1. You're more than welcome to submit your library to the [Template Library Repository](https://github.com/Tiny-Foxes/kitsu-template-libraries/)! Once approved, it will be listed with others in an easy-to-find location.

Generally, a library is written as follows:
```lua
-- mylib.lua --

-- You can import libraries in your library, too! That's what we call a dependency.
local std = import 'stdlib'
depend ('mylib', std, 'stdlib')
-- If the library does not have a global namespace, you can simply import it directly.
local OtherLib = import 'otherlib'

-- We will fill this and return it in the end.
local MyLib = {}
setmetatable(MyLib, {})

-- We write our library definitions here.
local MyVar = std.SCX
local function GetVar()
return MyVar
end
local function MyFunc(n)
return MyVar + n
end
local function AddVars()
return OtherLib.GetVar() + MyVar
end

-- List only what you want to export. Internal variables should stay hidden to prevent other things from messing with them.
MyLib = {
VERSION = '1.0',
var = MyVar,
func = MyFunc
var = GetVar,
func = MyFunc,
otherfunc = AddVars
}
MyLib.__index = MyLib

Expand All @@ -128,9 +141,9 @@ return MyLib

You should name be able to import your library into `mods.lua` or other libraries by using `import`.
```lua
local lib = import 'MyLib'
local lib = import 'mylib'

print(lib.var) -- Will print the value of SCREEN_CENTER_X
print(lib.var()) -- Will print the value of SCREEN_CENTER_X
local newvar = lib.func(7)
print(newvar) -- Will print the value of SCREEN_CENTER_X + 7
```
8 changes: 8 additions & 0 deletions docs/outfox/staging-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Staging Notes

### August 29, 2022 7:07pm
Jesus Christ the docs are so out of date.

I did my best to fix up what I could with the README, but it's gonna take a while before I get to the API reference documentation. There's just a lot on my plate and it'll take a while for me to get through all of it.

I almost accidentally deleted the entire docs, by the way. What the hell is my goddamn problem.

---
### October 15, 2021 1:19am
I've finally gotten back into the swing of working on the template again. During the time I haven't been around this I've made [an entire theme](https://github.com/Tiny-Foxes/superuser-outfox "god it took forever to actually push myself to do this").
Expand Down
48 changes: 25 additions & 23 deletions lib/konko-mods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ local AUTHOR = 'Sudospective'
local POptions = {}
local plrcount = 0
for i, v in ipairs( GAMESTATE:GetEnabledPlayers() ) do
POptions[i] = GAMESTATE:GetPlayerState(v):GetPlayerOptions('ModsLevel_Song')
POptions[i] = GAMESTATE:GetPlayerState(v):GetPlayerOptions('ModsLevel_Current')
end

local instant_tween = function(t) return 1 end
local modlist = {}
local mod_percents = {}
local note_percents = {}
Expand Down Expand Up @@ -141,8 +142,8 @@ local function UpdateMods()
if m.Player and not POptions[m.Player] then break end
local BEAT = std.BEAT
local pn = m.Player
if (BEAT >= m.Start and BEAT < (m.Start + m.Length)) then
if m.Type == 'Player' then
if (BEAT >= m.Start and BEAT <= (m.Start + m.Length)) then
if m.Type == 'Blend' then
-- Ease blending is a work in progress. Try to make sure two eases don't use the same mod.
v[3] = v[3] or mod_percents[pn][v[2]] or 0
active[pn][v[2]] = active[pn][v[2]] or {}
Expand All @@ -162,7 +163,7 @@ local function UpdateMods()
end
end
mod_percents[pn][v[2]] = perc
elseif m.Type == 'bup' then
elseif m.Type == 'Player' then
v[3] = v[3] or mod_percents[pn][v[2]] or default_mods[pn][v[2]] or 0
local ease = m.Ease((BEAT - m.Start) / m.Length)
if m.Length == 0 then ease = m.Ease(1) end
Expand All @@ -189,48 +190,36 @@ local function UpdateMods()
end
note_percents[pn][notemod] = perc
end
elseif BEAT >= (m.Start + m.Length) then
elseif BEAT > (m.Start + m.Length) then
if m.Type == 'Player' then
v[3] = v[3] or mod_percents[pn][v[2]] or 0
mod_percents[pn][v[2]] = m.Ease(1) * (v[1] - v[3]) + v[3]
if v[4] and active[pn][v[2]] then
active[pn][v[2]][v[4]] = nil
--active[pn][v[2]][v[4]] = nil
end
elseif m.Type == 'Note' then
v[5] = v[5] or note_percents[pn][notemod] or 0
local notemod = v[4]..'|'..v[1]..'|'..v[2]
note_percents[pn][notemod] = m.Ease(1) * (v[3] - v[5]) + v[5]
if v[6] and active[pn][notemod] then
active[pn][notemod][v[6]] = nil
--active[pn][notemod][v[6]] = nil
end
end
if j == #m.Modifiers then
m.Modifiers = {}
--m.Modifiers = {}
end
end
end
end
end

FG[#FG + 1] = Def.Actor {
ReadyCommand = function(self)
for pn = 1, plrcount do
POptions[pn]:FromString('*-1 clearall')
end
end,
UpdateCommand = function(self)
UpdateMods()
ApplyMods()
end
}

local function RegisterField(notefield, pn)
POptions[pn] = notefield:GetPlayerOptions('ModsLevel_Current')
end

-- Load a mod file.
local function FromFile(self, scriptpath)
--printerr('Mods:LoadFromFile')
--printerr('Mods:FromFile')
run('lua/'..scriptpath)
return self
end
Expand All @@ -242,7 +231,7 @@ local function Default(self, modtable)
table.insert(default_mods[pn], modtable[i])
end
end
local res = self:Insert(std.START, 0, function(x) return 1 end, modtable)
local res = self:Insert(std.START, 0, instant_tween, modtable)
return res
end
-- Define a new mod.
Expand Down Expand Up @@ -397,6 +386,20 @@ local function Mirin(self, t, offset, pn)
return res
end

FG[#FG + 1] = Def.Actor {
ReadyCommand = function(self)
for pn = 1, plrcount do
if POptions[pn] then POptions[pn]:FromString('*-1 clearall') end
end
-- Before we include the Note function, make sure we can actually call the required command.
if std.PL[1].Player.AddNoteMod then Mods.Note = Note end
end,
UpdateCommand = function(self)
UpdateMods()
ApplyMods()
end
}

Mods = {
VERSION = VERSION,
AUTHOR = AUTHOR,
Expand All @@ -405,7 +408,6 @@ Mods = {
FromFile = FromFile,
Define = Define,
Insert = Insert,
--Note = Note,
Mirin = Mirin,
Exsch = Exsch,
Default = Default,
Expand Down
Loading

0 comments on commit 7ad4d1f

Please sign in to comment.