From f22131dbced1179dd299cedb5a95eef68e7937c3 Mon Sep 17 00:00:00 2001 From: entar Date: Sun, 8 Jun 2025 06:56:02 +0700 Subject: [PATCH] Event stuff --- charts/bopeebo/events.json | 346 +++++++++++++++++++++++++++++++++++ modules/states/playstate.lua | 113 ++++++++++-- modules/types.lua | 2 +- modules/types/character.lua | 15 ++ 4 files changed, 462 insertions(+), 14 deletions(-) create mode 100644 charts/bopeebo/events.json diff --git a/charts/bopeebo/events.json b/charts/bopeebo/events.json new file mode 100644 index 0000000..f6a5c29 --- /dev/null +++ b/charts/bopeebo/events.json @@ -0,0 +1,346 @@ +{ + "song": { + "player1": "bf", + "song": "Bopeebo", + "player2": "dad", + "notes": [ + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 4290, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 9090, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 13890, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 18690, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 23490, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 28290, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 33090, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 37890, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 42690, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 47490, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 52290, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 57090, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 61890, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 66690, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 71490, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "lengthInSteps": 16, + "sectionNotes": [], + "mustHitSection": false + }, + { + "lengthInSteps": 16, + "sectionNotes": [ + [ + 76290, + -1, + "Hey!", + "0", + "" + ] + ], + "mustHitSection": true + }, + { + "sectionNotes": [], + "typeOfSection": 0, + "lengthInSteps": 16, + "altAnim": false, + "mustHitSection": true, + "changeBPM": false, + "bpm": 100 + }, + { + "sectionNotes": [], + "typeOfSection": 0, + "lengthInSteps": 16, + "altAnim": false, + "mustHitSection": true, + "changeBPM": false, + "bpm": 100 + }, + { + "sectionNotes": [], + "typeOfSection": 0, + "lengthInSteps": 16, + "altAnim": false, + "mustHitSection": true, + "changeBPM": false, + "bpm": 100 + }, + { + "sectionNotes": [], + "typeOfSection": 0, + "lengthInSteps": 16, + "altAnim": false, + "mustHitSection": true, + "changeBPM": false, + "bpm": 100 + }, + { + "lengthInSteps": 16, + "altAnim": false, + "typeOfSection": 0, + "sectionNotes": [], + "bpm": 100, + "changeBPM": false, + "mustHitSection": true + } + ], + "needsVoices": true, + "validScore": true, + "bpm": 100, + "speed": 1.3 + } +} \ No newline at end of file diff --git a/modules/states/playstate.lua b/modules/states/playstate.lua index 21cc49b..984c322 100644 --- a/modules/states/playstate.lua +++ b/modules/states/playstate.lua @@ -56,6 +56,8 @@ local function state(songName, songDifficulty) local unspawnedHoldNotes = {} local holdNotes = {} + local events = {} + local characters = {} local icons = {} @@ -441,6 +443,20 @@ local function state(songName, songDifficulty) end end + for index, event in next, events do + if event.time - elapsed < 0 then + events[index] = nil + + if event.name == "change character" then + characters[event.var1] = myTypes.character(event.var2) + elseif event.name == "play animation" then + characters[event.var2]:PlayAnimation(event.var1) + elseif event.name == "hey!" then + characters.bf:PlayAnimation("hey") + end + end + end + zoom = myMath.lerp(zoom, 1, .05) if inst and inst:getVolume() ~= volume / 100 then @@ -602,24 +618,95 @@ local function state(songName, songDifficulty) -- Load the notes AFTER the receptors to make sure they are always above them for index, section in next, chart.notes do for index, note in next, section.sectionNotes do - local newNote = myTypes.note(note, section.mustHitSection) - unspawnedNotes[#unspawnedNotes+1] = newNote + if note[2] >= 0 then + local newNote = myTypes.note(note, section.mustHitSection) + unspawnedNotes[#unspawnedNotes+1] = newNote - if note[3] > 0 then - local length = math.floor(note[3] / conductor.stepCrochet) + if note[3] > 0 then + local length = math.floor(note[3] / conductor.stepCrochet) - for i = 0, length - .1, .1 do - local newHold = myTypes.note({note[1] + i * conductor.stepCrochet, note[2], note[3], note[4]}, section.mustHitSection, true) - + for i = 0, length - .1, .1 do + local newHold = myTypes.note({note[1] + i * conductor.stepCrochet, note[2], note[3], note[4]}, section.mustHitSection, true) + + unspawnedHoldNotes[#unspawnedHoldNotes+1] = newHold + end + local newHold = myTypes.note({note[1] + length * conductor.stepCrochet, note[2], note[3], note[4]}, section.mustHitSection, true, true) unspawnedHoldNotes[#unspawnedHoldNotes+1] = newHold + newHold.holdEnd = true + if settings.Downscroll then + newHold.flipY = true + end + newHold.speed = speed end - local newHold = myTypes.note({note[1] + length * conductor.stepCrochet, note[2], note[3], note[4]}, section.mustHitSection, true, true) - unspawnedHoldNotes[#unspawnedHoldNotes+1] = newHold - newHold.holdEnd = true - if settings.Downscroll then - newHold.flipY = true + else + local newEvent = { + time = note[1], + name = string.lower(note[3]), + var1 = string.lower(note[4]), + var2 = string.lower(note[5]) + } + events[#events+1] = newEvent + + if newEvent.name == "change character" then + myTypes.preloadChar(newEvent.var2) end - newHold.speed = speed + end + end + end + + local eventChartFile = files.read_file(string.format("charts/%s/events.json", songName)) + if eventChartFile then + local eventChart = json.parse(eventChartFile) + + if eventChart.notes then + for index, section in next, eventChart.notes do + for index, note in next, section.sectionNotes do + local newEvent = { + time = note[1], + name = string.lower(note[3]), + var1 = string.lower(note[4]), + var2 = string.lower(note[5]) + } + events[#events+1] = newEvent + + if newEvent.name == "change character" then + myTypes.preloadChar(newEvent.var2) + end + end + end + end + + if eventChart.events then + for index, event in next, eventChart.events do + for index in next, event[2] do + local newEvent = { + time = event[1], + name = string.lower(event[2][index][1]), + var1 = string.lower(event[2][index][2]), + var2 = string.lower(event[2][index][3]) + } + events[#events+1] = newEvent + + if newEvent.name == "change character" then + myTypes.preloadChar(newEvent.var2) + end + end + end + end + end + + for index, event in next, chart.events do + for index in next, event[2] do + local newEvent = { + time = event[1], + name = string.lower(event[2][index][1]), + var1 = string.lower(event[2][index][2]), + var2 = string.lower(event[2][index][3]) + } + events[#events+1] = newEvent + + if newEvent.name == "change character" then + myTypes.preloadChar(newEvent.var2) end end end diff --git a/modules/types.lua b/modules/types.lua index 3b88f96..a692532 100644 --- a/modules/types.lua +++ b/modules/types.lua @@ -18,10 +18,10 @@ module.Image = renderClasses.Image module.destroyAllSprites = renderClasses.destroyAllSprites module.drawSprites = renderClasses.drawSprites module.updateSprites = renderClasses.updateSprites +module.preload = renderClasses.preLoad module.Vector2 = vectorClass.Vector2 module.render = renderClasses - return module diff --git a/modules/types/character.lua b/modules/types/character.lua index 39bbc92..2196509 100644 --- a/modules/types/character.lua +++ b/modules/types/character.lua @@ -72,4 +72,19 @@ function module.character(name) return newCharacter end +function module.preload(name) + local charFile = files.read_file(string.format("characters/%s.json", name)) + if not charFile then + error("Failed to load character "..name) + end + + + local parsed = json.parse(charFile) + + local image = parsed.image..".png" + local sheet = parsed.image..".json" + + module.myTypes.preload(image, sheet) +end + return module