Skip to content

Commit 54e4365

Browse files
committed
Kitsu Template v3.1.0
1 parent c93689c commit 54e4365

File tree

10 files changed

+782
-556
lines changed

10 files changed

+782
-556
lines changed

CHANGES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Kitsu Template v3.1.0
2+
3+
## Changes
4+
- Reformatted `mods.lua` to streamline mod implementation
5+
- Added `bg.lua` and `fg.lua` for background and foreground actors
6+
- Added `using` function to allow for scoping of namespaces (useful for repeated use of a library such as `mirin-syntax`)
7+
- Fixed environment behavior to support `using`
8+
- Reimplemented `mirin-syntax` as a built-in library (you may remove this if you wish)
9+
- Configured `mods.lua` with `using 'mirin'` to streamline mod implementation (you may remove this if you wish)
10+
- Edited `print` to support tables
11+
- Edited chart to have appropriate BPM and time signatures
12+
- Fixed broken functions in `konko-node` getting variables in wrong environment
13+
- Fixed `run` and `import` using default `sudo` environment to load files
14+
- Moved player proxies to `fg.lua`
15+
- Created background for `bg.lua`
16+
- Added default mods in `mods.lua`

lib/konko-node.lua

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ local Node = {}
2424
-- Version number
2525
local VERSION = '1.1'
2626

27+
local env = getfenv(2)
28+
2729
local ease_table = {}
2830
local func_table = {}
2931
local msg_table = {}
@@ -36,7 +38,7 @@ local function UpdateEases()
3638
for i, v in ipairs(ease_table) do
3739
local actor
3840
if type(v[1]) == 'string' then
39-
actor = _G.sudo[v[1]]
41+
actor = env[v[1]]
4042
else
4143
actor = v[1]
4244
end
@@ -61,7 +63,7 @@ local function UpdateFuncs()
6163
for i, v in ipairs(func_table) do
6264
local actor
6365
if type(v[1]) == 'string' then
64-
actor = _G.sudo[v[1]]
66+
actor = env[v[1]]
6567
else
6668
actor = v[1]
6769
end
@@ -88,6 +90,11 @@ local function UpdateSignals()
8890
end
8991
end
9092

93+
local function GetActor(this)
94+
for i, v in ipairs(Node.GetTree()) do
95+
if v.Name == this then return v end
96+
end
97+
end
9198
local NodeTree = Def.ActorFrame {
9299
InitCommand = function(self)
93100
local s = self
@@ -96,7 +103,7 @@ local NodeTree = Def.ActorFrame {
96103
local function NameActors(actor)
97104
for i = 1, actor:GetNumChildren() do
98105
local this = actor:GetChildAt(i)
99-
_G.sudo[this:GetName()] = this
106+
env[this:GetName()] = this
100107
if this.GetChildren then NameActors(this) end
101108
end
102109
end
@@ -213,7 +220,7 @@ end
213220
local function SetName(self, name)
214221
--print('Node:SetName')
215222
self.Name = name
216-
--_G.sudo[name] = self
223+
--env[name] = self
217224
return self
218225
end
219226
local function SetTexture(self, path)
@@ -328,9 +335,9 @@ local function AddChild(self, child, idx, name)
328335
return self
329336
end
330337
local function GetChildIndex(self, name)
331-
--print('Node:GetChildIndex')
338+
print('Node:GetChildIndex')
332339
if self.Type ~= 'ActorFrame' and self.Type ~= 'ActorFrameTexture' then
333-
printerr('Node.AddChild: Cannot add child to type '..self.Type)
340+
printerr('Node.GetChildIndex: Cannot add child to type '..self.Type)
334341
return
335342
end
336343
for i, v in ipairs(self) do
@@ -339,6 +346,19 @@ local function GetChildIndex(self, name)
339346
end
340347
end
341348
end
349+
local function HideOverlay(b)
350+
if not std.SCREEN.HideGameplayElements then return end
351+
if b == nil then
352+
printerr('Node.HideOverlay: Must have boolean argument')
353+
return
354+
elseif type(b) ~= 'boolean' then
355+
printerr('Node.HideOverlay: Argument must be boolean')
356+
return
357+
end
358+
if b then
359+
std.SCREEN:HideGameplayElements()
360+
end
361+
end
342362
local function AddToTree(self, idx, name)
343363
--print('Node:AddToTree')
344364
if type(idx) == 'string' then
@@ -355,26 +375,6 @@ local function AddToTree(self, idx, name)
355375
end
356376
return self
357377
end
358-
local function GetOverlay()
359-
local ret = {}
360-
ret[#ret + 1] = std.SCREEN:GetChild('Underlay')
361-
for i = 1, #std.PL do
362-
ret[#ret + 1] = std.PL[i].Life
363-
ret[#ret + 1] = std.PL[i].Score
364-
end
365-
ret[#ret + 1] = std.SCREEN:GetChild('Overlay')
366-
return ret
367-
end
368-
local function HideOverlay(b)
369-
--print('Node.HideOverlay')
370-
if type(b) == 'boolean' then
371-
for _, v in ipairs(GetOverlay()) do
372-
v:visible(tobool(not b))
373-
end
374-
else
375-
printerr('Node.HideOverlay: argument must be boolean value')
376-
end
377-
end
378378
local function GetTree()
379379
--print('Node.GetTree')
380380
return NodeTree
@@ -404,11 +404,10 @@ Node = {
404404
SetDraw = SetDraw,
405405
AddChild = AddChild,
406406
GetChildIndex = GetChildIndex,
407-
AddToTree = AddToTree,
408-
GetOverlay = GetOverlay,
409407
HideOverlay = HideOverlay,
408+
AddToTree = AddToTree,
410409
GetTree = GetTree,
411-
GetActor = function(this) printerr('Node.GetActor: Function not available before ready()') end,
410+
GetActor = GetActor,
412411
}
413412
Node.__index = Node
414413

lib/mirin-syntax.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
-- mirin-syntax.lua --
2+
3+
--[[
4+
Available commands:
5+
- set {start, percent, mod, ...}
6+
- ease {start, length, ease, percent, mod, ...}
7+
- definemod {name, funtion, return}
8+
- setdefault {percent, mod, ...}
9+
10+
Mirin documentation available at https://xerool.github.io/notitg-mirin
11+
--]]
12+
13+
local Mods = import 'konko-mods'
14+
15+
local mirin = {}
16+
17+
local function set(t)
18+
table.insert(t, 2, 0)
19+
table.insert(t, 3, Tweens.instant)
20+
local pn = (type(t.plr) ~= 'table' and t.plr) or nil
21+
t.plr = nil
22+
Mods:Mirin(t, 0, pn)
23+
return set
24+
end
25+
26+
local function ease(t)
27+
local pn = (type(t.plr) ~= 'table' and t.plr) or nil
28+
t.plr = nil
29+
Mods:Mirin(t, 0, pn)
30+
return ease
31+
end
32+
33+
-- WIP: Not a one-to-one implementation, define mods one at a time
34+
local function definemod(t)
35+
Mods:Define(table.unpack(t))
36+
return definemod
37+
end
38+
39+
local function setdefault(t)
40+
local t2 = {}
41+
for i = 1, #t, 2 do
42+
table.insert(t2, {t[i], t[i + 1]})
43+
end
44+
Mods:Default(t2)
45+
return setdefault
46+
end
47+
48+
mirin = {
49+
VERSION = '1.1',
50+
ease = ease,
51+
set = set,
52+
definemod = definemod,
53+
setdefault = setdefault
54+
}
55+
mirin.__index = mirin
56+
57+
print('Loaded Mirin Syntax v'..mirin.VERSION)
58+
59+
return mirin

lib/stdlib.lua

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ std.BEAT = std.POS:GetSongBeat() -- current beat
2121
std.BPS = std.POS:GetCurBPS() -- current beats per second
2222
std.BPM = std.BPS * 60 -- beats per minute
2323
std.SPB = 1 / std.BPS -- seconds per beat
24+
2425
std.PL = {}
2526

2627
-- A bit of work to get the true start of our FG changes.
@@ -39,19 +40,22 @@ fgfirst = nil
3940
chart = nil
4041
f = nil
4142

43+
local env = getfenv(2)
44+
4245
-- This might not be added on the engine side yet.
4346
if not Tweens.instant then
4447
Tweens.instant = function(x) return 1 end
4548
end
4649

4750

4851
local InputHandler = function(event)
49-
if sudo.input then
50-
sudo.input(event)
52+
if env.input then
53+
env.input(event)
5154
end
5255
MESSAGEMAN:Broadcast('Input', {event})
5356
end
5457

58+
5559
-- Our foreground to put everything in. If FG is not set, this will take its place.
5660
if FG.stdlib then
5761
--print('We have stdlib already, loading mini-actor instead')
@@ -106,8 +110,8 @@ else
106110
FG[#FG + 1] = Def.ActorFrame {
107111
Name = 'stdlib',
108112
InitCommand = function(self)
109-
if sudo.init then
110-
sudo.init()
113+
if init then
114+
init()
111115
end
112116
end,
113117
ReadyCommand = function(self)
@@ -156,11 +160,11 @@ else
156160
std.BPM = std.BPS * 60 -- beats per minute
157161
std.SPB = 1 / std.BPS -- seconds per beat
158162
std.DT = self:GetEffectDelta() -- time since last frame in seconds
159-
if sudo.ready then
160-
sudo.ready()
163+
if ready then
164+
ready()
161165
end
162-
if sudo.draw then
163-
self:SetDrawFunction(sudo.draw)
166+
if draw then
167+
self:SetDrawFunction(draw)
164168
end
165169
end,
166170
UpdateCommand = function(self)
@@ -169,15 +173,14 @@ else
169173
std.BPM = std.BPS * 60
170174
std.SPB = 1 / std.BPS
171175
std.DT = self:GetEffectDelta()
172-
if sudo.update then
173-
sudo.update(std.DT)
176+
if update then
177+
update(std.DT)
174178
end
175179
end,
176180
OffCommand = function(self)
177181
std.SCREEN:RemoveInputCallback(InputHandler)
178182
end,
179183
}
180-
print('Loaded Kitsu Standard Library v'..std.VERSION)
181184
end
182185

183186

@@ -248,4 +251,6 @@ end
248251

249252
std.__index = std
250253

254+
print('Loaded Kitsu Standard Library v'..std.VERSION)
255+
251256
return std

lua/bg.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- Libraries
2+
local std = import 'stdlib'
3+
local Node = import 'konko-node'
4+
5+
6+
-- Variables
7+
local SW, SH = std.SW, std.SH
8+
local SCX, SCY = std.SCX, std.SCY
9+
10+
-- Nodes
11+
Node.new('Quad'):AddToTree(1, 'HideEvent')
12+
:SetInit(function(self)
13+
self
14+
:FullScreen()
15+
:diffuse(color('#000000'))
16+
end)
17+
18+
19+
-- Called on InitCommand
20+
function init()
21+
22+
end
23+
24+
-- Called on ReadyCommand
25+
function ready()
26+
HideEvent
27+
:sleep(math.abs(std.POS:GetMusicSeconds()))
28+
:easeoutexpo(1)
29+
:diffusebottomedge(color('#101010'))
30+
:diffuserightedge(color('#202020'))
31+
end
32+
33+
-- Called on InputMessageCommand
34+
function input(event)
35+
36+
end
37+
38+
-- Called on UpdateCommand
39+
function update(dt)
40+
41+
end
42+
43+
-- Called on FG.Draw
44+
function draw()
45+
46+
end
47+
48+
49+
-- Actors
50+
table.insert(FG, Def.ActorFrame {
51+
52+
Node.GetTree()
53+
54+
})

0 commit comments

Comments
 (0)