Skip to content

Commit c873cfa

Browse files
committed
* Fixed SetUnitOpacity can't be called in storyboard Initialize function
* Added `LoadDEPLS2Image` storyboard function * Moved `DEPLS.LoadConfig` function to global namespace
1 parent 2b08990 commit c873cfa

7 files changed

+92
-33
lines changed

docs/Storyboard.md

+36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ Please note that Lua script running as Lua storyboard is sandboxed, which means
66
functions doesn't exist in here or modified to prevent alteration of the rendering state, and
77
to prevent malicious Lua storyboard script writing anywhere.
88

9+
Storyboard Entry Points
10+
=======================
11+
12+
Lua storyboard needs to create this function in global namespace. Although there's way to use
13+
it without this entry points by using coroutines, but it's usage is discouraged and only
14+
provided for legacy DEPLS storyboard lua script.
15+
16+
*************************************************
17+
18+
### `void Initialize()`
19+
20+
Storyboard initialization. This function is called everytime storyboard is loaded. Load your
21+
images here
22+
23+
*************************************************
24+
25+
### `void Update(number deltaT)`
26+
27+
Storyboard frame update. Draw and calculate everything for the storyboard in here.
28+
29+
Parameters:
30+
31+
* deltaT - The delta-time, in milliseconds
32+
933
Storyboard Functions
1034
====================
1135

@@ -136,3 +160,15 @@ Parameters:
136160
Returns: Stereo audio sample with size `size` (index 1 is L channel, index 2 is R channel)
137161

138162
> This function handles mono/stereo input and this function still works even if no audio is found, where in that case the sample is simply 0
163+
164+
*************************************************
165+
166+
### `Image|nil LoadDEPLS2Image(string path)`
167+
168+
Loads game image (not relative to beatmap directory)
169+
170+
Parameters:
171+
172+
* `path` - The image path
173+
174+
Returns: Image handle or `nil` on failure

livesim.lua

+27-30
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ local DEPLS = {
3838
{569, 465}, {416, 496}, {262, 465},
3939
{133, 378}, {46 , 249}, {16 , 96 },
4040
},
41-
IdolImageData = {}, -- [idol positon] = {image handle, opacity}
41+
IdolImageData = { -- [idol positon] = {image handle, opacity}
42+
{nil, 255}, {nil, 255}, {nil, 255},
43+
{nil, 255}, {nil, 255}, {nil, 255},
44+
{nil, 255}, {nil, 255}, {nil, 255}
45+
},
4246
NoteAccuracy = {{16, nil}, {40, nil}, {64, nil}, {112, nil}, {128, nil}}, -- Note accuracy
4347
NoteManager = nil,
4448
NoteLoader = nil,
@@ -647,26 +651,6 @@ function DEPLS.LoadImageSafe(path)
647651
else return token_image end
648652
end
649653

650-
--! @brief Load configuration
651-
--! @param config_name The configuration name
652-
--! @param default_value The default value of the configuration
653-
--! @returns Configuration value or `default_value` (and save it as `default_value`)
654-
function DEPLS.LoadConfig(config_name, default_value)
655-
local file = love.filesystem.newFile(config_name..".txt", "r")
656-
657-
if file == nil then
658-
file = io.open(DEPLS.SaveDirectory.."/"..config_name..".txt", "wb")
659-
file:write(tostring(default_value))
660-
file:close()
661-
662-
return default_value
663-
end
664-
665-
local data = file:read()
666-
667-
return tonumber(data) or data
668-
end
669-
670654
--! @brief Load audio
671655
--! @param path The audio path
672656
--! @param noorder Force existing extension?
@@ -899,6 +883,19 @@ do
899883
end
900884
end
901885

886+
--! @brief Loads DEPLS2 image file
887+
--! @param path The image path
888+
--! @returns Image handle or nil on failure
889+
function DEPLS.StoryboardFunctions.LoadDEPLSImage(path)
890+
local _, a = pcall(love.graphics.newImage, path)
891+
892+
if _ then
893+
return a
894+
end
895+
896+
return nil
897+
end
898+
902899
-----------------------------
903900
-- The Live simuator logic --
904901
-----------------------------
@@ -944,14 +941,14 @@ function DEPLS.Start(argv)
944941
love.filesystem.createDirectory("beatmap")
945942

946943
-- Load configuration
947-
local BackgroundID = DEPLS.LoadConfig("BACKGROUND_IMAGE", 11)
948-
local Keys = DEPLS.LoadConfig("IDOL_KEYS", "a\ts\td\tf\tspace\tj\tk\tl\t;")
949-
local Auto = DEPLS.LoadConfig("AUTOPLAY", 0)
950-
DEPLS.LiveDelay = DEPLS.LoadConfig("LIVESIM_DELAY", 1000)
944+
local BackgroundID = LoadConfig("BACKGROUND_IMAGE", 11)
945+
local Keys = LoadConfig("IDOL_KEYS", "a\ts\td\tf\tspace\tj\tk\tl\t;")
946+
local Auto = LoadConfig("AUTOPLAY", 0)
947+
DEPLS.LiveDelay = LoadConfig("LIVESIM_DELAY", 1000)
951948
DEPLS.ElapsedTime = -DEPLS.LiveDelay
952-
DEPLS.NotesSpeed = DEPLS.LoadConfig("NOTE_SPEED", 800)
953-
DEPLS.Stamina = DEPLS.LoadConfig("STAMINA_DISPLAY", 32)
954-
DEPLS.ScoreBase = DEPLS.LoadConfig("SCORE_ADD_NOTE", 1024)
949+
DEPLS.NotesSpeed = LoadConfig("NOTE_SPEED", 800)
950+
DEPLS.Stamina = LoadConfig("STAMINA_DISPLAY", 32)
951+
DEPLS.ScoreBase = LoadConfig("SCORE_ADD_NOTE", 1024)
955952
DEPLS.Keys = {}
956953
do
957954
local i = 9
@@ -1051,14 +1048,14 @@ function DEPLS.Start(argv)
10511048
noteloader_data.units = noteloader_data.units or {}
10521049
local IdolImagePath = {}
10531050
do
1054-
local idol_img = DEPLS.LoadConfig("IDOL_IMAGE", "a.png,a.png,a.png,a.png,a.png,a.png,a.png,a.png,a.png")
1051+
local idol_img = LoadConfig("IDOL_IMAGE", "a.png,a.png,a.png,a.png,a.png,a.png,a.png,a.png,a.png")
10551052

10561053
for w in idol_img:gmatch("[^,]+") do
10571054
IdolImagePath[#IdolImagePath + 1] = w
10581055
end
10591056
end
10601057
for i = 1, 9 do
1061-
DEPLS.IdolImageData[i] = {noteloader_data.units[i] or DEPLS.LoadUnitIcon(IdolImagePath[10 - i]), 255}
1058+
DEPLS.IdolImageData[i][1] = noteloader_data.units[i] or DEPLS.LoadUnitIcon(IdolImagePath[10 - i])
10621059
end
10631060

10641061
-- Load stamina image (bar and number)

luastoryboard.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ function LuaStoryboard.Draw(deltaT)
197197
status, msg = pcall(StoryboardLua[1], deltaT)
198198
end
199199

200-
graphics.pop()
200+
for i = 1, PushPopCount do
201+
graphics.pop()
202+
end
203+
PushPopCount = 0
201204

202205
-- Cleanup
203206
graphics.setCanvas()

main.lua

+20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ local loader = {
2222
local function error_printer(msg, layer)
2323
print((debug.traceback("Error: " .. tostring(msg), 1+(layer or 1)):gsub("\n[^\n]+$", "")))
2424
end
25+
26+
--! @brief Load configuration
27+
--! @param config_name The configuration name
28+
--! @param default_value The default value of the configuration
29+
--! @returns Configuration value or `default_value` (and save it as `default_value`)
30+
function LoadConfig(config_name, default_value)
31+
local file = love.filesystem.newFile(config_name..".txt")
32+
33+
if not(file:open("r")) then
34+
assert(file:open("w"))
35+
file:write(tostring(default_value))
36+
file:close()
37+
38+
return default_value
39+
end
40+
41+
local data = file:read()
42+
43+
return tonumber(data) or data
44+
end
2545

2646
function love.errhand(msg)
2747
msg = tostring(msg)

noteloader/load_cbf.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function CBFBeatmap.Load(file)
5858
end
5959

6060
local notes_data = {}
61-
local desired_attribute = DEPLS.LoadConfig("LLP_SIFT_DEFATTR", 1)
61+
local desired_attribute = LoadConfig("LLP_SIFT_DEFATTR", 1)
6262

6363
if cbf.SONG_ATTRIBUTE == "Pure" then
6464
desired_attribute = 2

noteloader/load_llp.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local LLPBeatmap = {
2020
--! @note Modify `LLP_SIFT_DEFATTR` config to change default attribute
2121
function LLPBeatmap.Load(file)
2222
local llp = JSON:decode(love.filesystem.newFileData(file[1]..".llp"):getString())
23-
local attribute = DEPLS.LoadConfig("LLP_SIFT_DEFATTR", 1) -- Smile is default
23+
local attribute = LoadConfig("LLP_SIFT_DEFATTR", 1) -- Smile is default
2424
local sif_map = {}
2525

2626
for n, v in pairs(llp.lane) do

setting_view.lua

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- DEPLS settings
2+
3+
local Settings = {}

0 commit comments

Comments
 (0)