new SharedVars class, made public too

This commit is contained in:
entar 2025-06-30 00:03:45 +07:00
parent 6d2db400d9
commit f0e9943e67
15 changed files with 128 additions and 64 deletions

View File

@ -8,7 +8,7 @@ local module = {}
function module.onCreate(songName)
if songName == "Guns" then
module.shared.canStart = false
sharedVars.canStart = false
song = songName
videoStream = love.video.newVideoStream(love.filesystem.newFile(videoPath))
videoStream:play()
@ -20,7 +20,7 @@ end
function module.onUpdate()
if videoStream then
if not videoStream:isPlaying() then
module.shared.canStart = true
sharedVars.canStart = true
video = nil
videoStream = nil
end

View File

@ -29,7 +29,7 @@ local degree = -45
function module.onCreate()
lastChange = 0
for index, receptor in next, module.shared.receptors do
for index, receptor in next, sharedVars.receptors do
-- receptor.position.x = 100
-- receptor.position.y = 500 + 70 * (index - 1)
-- receptor.rotation = degree
@ -38,17 +38,17 @@ end
function module.onUpdate(dt, elapsed)
if enabled then
-- for index, note in next, module.shared.notes do
-- for index, note in next, sharedVars.notes do
-- if note.mustPress then
-- note.offset.x = math.sin(math.rad(degree)) * (note.position - elapsed) * module.shared.speed
-- note.offset.y = (math.cos(math.rad(degree)) * (note.position - elapsed) * module.shared.speed) - (note.position - elapsed)
-- note.offset.x = math.sin(math.rad(degree)) * (note.position - elapsed) * sharedVars.speed
-- note.offset.y = (math.cos(math.rad(degree)) * (note.position - elapsed) * sharedVars.speed) - (note.position - elapsed)
-- -- note.sprite.rotation = degree
-- end
-- end
-- for index, hold in next, module.shared.holds do
-- for index, hold in next, sharedVars.holds do
-- if hold.mustPress then
-- hold.offset.x = math.sin(math.rad(degree)) * (hold.position - elapsed) * module.shared.speed
-- hold.offset.y = (math.cos(math.rad(degree)) * (hold.position - elapsed) * module.shared.speed) - (hold.position - elapsed)
-- hold.offset.x = math.sin(math.rad(degree)) * (hold.position - elapsed) * sharedVars.speed
-- hold.offset.y = (math.cos(math.rad(degree)) * (hold.position - elapsed) * sharedVars.speed) - (hold.position - elapsed)
-- hold.sprite.rotation = degree
-- end
-- end

View File

@ -8,7 +8,7 @@ local module = {}
function module.onCreate(songName)
if songName == "Stress" then
module.shared.canStart = false
sharedVars.canStart = false
song = songName
videoStream = love.video.newVideoStream(love.filesystem.newFile(videoPath))
videoStream:play()
@ -20,7 +20,7 @@ end
function module.onUpdate()
if videoStream then
if not videoStream:isPlaying() then
module.shared.canStart = true
sharedVars.canStart = true
video = nil
videoStream = nil
end

View File

@ -11,15 +11,15 @@ local module = {}
function module.onCreate(songName)
random = math.random(1, 25)
if not module.shared.tankmanLoaded then
module.shared.tankmanLoaded = {}
if not sharedVars.tankmanLoaded then
sharedVars.tankmanLoaded = {}
end
if not module.shared.tankmanLoaded[random] then
module.shared.tankmanLoaded[random] = love.audio.newSource(string.format("sounds/week7/death/jeffGameover-%s.ogg", random), "stream")
if not sharedVars.tankmanLoaded[random] then
sharedVars.tankmanLoaded[random] = love.audio.newSource(string.format("sounds/week7/death/jeffGameover-%s.ogg", random), "stream")
end
if songName == "Ugh" then
module.shared.canStart = false
sharedVars.canStart = false
song = songName
videoStream = love.video.newVideoStream(love.filesystem.newFile(videoPath))
videoStream:play()
@ -31,7 +31,7 @@ end
function module.onUpdate()
if videoStream then
if not videoStream:isPlaying() then
module.shared.canStart = true
sharedVars.canStart = true
video = nil
videoStream = nil
else
@ -61,7 +61,7 @@ function module.onClose()
end
function module.onDeath()
module.shared.tankmanLoaded[random]:play()
sharedVars.tankmanLoaded[random]:play()
end
return module

View File

@ -6,7 +6,7 @@ local time = 0
local started = false
function module.onCreate()
module.shared.canStart = false
sharedVars.canStart = false
render.cameraPosition = Vector2(500, 1000)
started = false
time = 0
@ -16,7 +16,7 @@ function module.onUpdate(dt)
time = time + dt
if time > 5 and not started then
started = true
module.shared.canStart = true
sharedVars.canStart = true
end
end

View File

@ -6,10 +6,12 @@ local files = require("modules.files")
local json = require("modules.json")
print("evil")
---Character class, child of Sprite class. Makes work with characters easier by calling some sprite functions with preset character file arguments.
---@class Character
local CharacterClass = {}
CharacterClass.__index = CharacterClass
--- @param name string
function CharacterClass:PlayAnimation(name)
local animName = self.animations[name]
@ -35,7 +37,9 @@ function CharacterClass:Destroy()
self = nil
end
function Character(name)
--- @param name string
--- @return Character
function _G.Character(name)
local charFile = files.read_file(string.format("characters/%s.json", name))
if not charFile then
error("Failed to load character "..name)

View File

@ -1,9 +1,7 @@
for index, type in next, love.filesystem.getDirectoryItems("modules/types") do
if type == "init.lua" then goto continue end
print(type)
local file = type:split(".")[1]
print("modules.types."..file)
require("modules.types."..file)

View File

@ -11,6 +11,12 @@ local sprites = {
"red"
}
--- Make a note.
--- @param raw table
--- @param mustHitSection boolean
--- @param hold boolean
--- @param holdEnd boolean
--- @return Note
function _G.Note(raw, mustHitSection, hold, holdEnd)
local newNote = setmetatable({
@ -31,7 +37,8 @@ function _G.Note(raw, mustHitSection, hold, holdEnd)
return newNote
end
function NoteClass:spawn()
--- Make the note sprite
function NoteClass:Spawn()
local sprite = Rect("sprites/NOTE_assets.png", "sprites/NOTE_assets.json")
self.sprite = sprite
@ -62,7 +69,8 @@ function NoteClass:spawn()
self.spawned = true
end
function NoteClass:destroy()
--- Destroy the note
function NoteClass:Destroy()
if self.sprite then
self.sprite:Destroy()
end

View File

@ -5,10 +5,12 @@ local module = {}
_G.render = module
---@class Sprite
---Sprite Sheet animatable class
local Sprite = {}
Sprite.__index = Sprite
---@class Image
---Image class
local Image = {}
Image.__index = Image
@ -19,6 +21,10 @@ local loadedShaders = {}
local Sprites, Rects, Images, Atlases = {}, {}, {}, {}
--- Makes a sprite object.
--- @param image string
--- @param sheet string
--- @return Sprite
function _G.Sprite(image, sheet)
if not cachedQuads[sheet] then
local sheetString = files.read_file(sheet)
@ -95,6 +101,11 @@ function _G.Sprite(image, sheet)
end
end
--- Plays a animation on the sprite.
--- @param name string
--- @param fps number
--- @param loop boolean
--- @param allowed table?
function Sprite:PlayAnimation(name, fps, loop, allowed)
self.animation = name
self.fps = fps
@ -110,6 +121,7 @@ function Sprite:PlayAnimation(name, fps, loop, allowed)
self.ended = false
end
--- Destroys the Sprite / Rect object.
function Sprite:Destroy()
if self.rect then
for index, rect in next, Rects do
@ -138,6 +150,7 @@ function Sprite:Destroy()
end
end
--- Destroys the image object.
function Image:Destroy()
for index, image in next, Images do
if image == self then
@ -339,12 +352,16 @@ function module.drawUI()
end
end
--- Makes a new Rect object.
--- @param image string
--- @param sheet string
--- @return Sprite
function _G.Rect(image, sheet)
if not cachedQuads[sheet] then
local sheetString = files.read_file(sheet)
if not sheetString then
error("Failed to load", sheet)
error("Failed to load".. sheet)
end
local atlas = json.parse(sheetString).TextureAtlas.SubTexture
@ -415,11 +432,15 @@ function _G.Rect(image, sheet)
end
end
--- Puts a specific frame on the Rect.
--- @param name string
--- @param frame number
function Sprite:Frame(name, frame)
self.animation = name
self.frame = frame
end
--- Stops the sprite animation (Sprite will become invisible)
function Sprite:StopAnimation()
self.animation = nil
self.frame = 0
@ -433,6 +454,10 @@ function module.destroyAllSprites()
Atlases = {}
end
--- Makes an image.
--- @param path string
--- @param scrollFactor number?
--- @return Image
function _G.Image(path, scrollFactor)
if not cachedImages[path] then
cachedImages[path] = love.graphics.newImage(path)
@ -504,17 +529,24 @@ function module.getShader(name)
end
---@class Atlas
---Texture Atlas animatable object.
local Atlas = {}
Atlas.__index = Atlas
--- Plays a symbol on the atlas
--- @param name string
function Atlas:PlayAnimation(name)
self.atlas:play(name)
end
--- Destroys the atlas
function Atlas:Destroy()
Atlases[self.index] = nil
end
--- Makes an atlas.
--- @param folder string
--- @return Atlas
function _G.Atlas(folder)
local newAtlas = setmetatable({
atlas = love.animate.newTextureAtlas(),

View File

@ -1,31 +1,47 @@
--- @class Vector2
--- @field x number
--- @field y number
local Vector2Class = {}
Vector2Class.__index = Vector2Class
--- @param newVector2 Vector2
--- @param position number
--- @return Vector2
function Vector2Class:Lerp(newVector2, position)
return Vector2(Lerp(self.x, newVector2.x, position), Lerp(self.y, newVector2.y, position))
end
--- @return number, number
function Vector2Class:Get()
return self.x, self.y
end
--- @return Vector2
function Vector2Class:Negate()
return Vector2(-self.x, -self.y)
end
--- @param addVector2 Vector2
--- @return Vector2
function Vector2Class:Add(addVector2)
return Vector2(self.x + addVector2.x, self.y + addVector2.y)
end
--- @param num number
--- @return Vector2
function Vector2Class:Mul(num)
return Vector2(self.x * num, self.y * num)
end
--- @param num number
--- @return Vector2
function Vector2Class:Div(num)
return Vector2(self.x / num, self.y / num)
end
--- @param x number?
--- @param y number?
--- @return Vector2
function _G.Vector2(x, y)
return setmetatable({x = x or 0, y = y or 0}, Vector2Class)
end

View File

@ -167,7 +167,21 @@ local function state(songName, songDifficulty, show)
cdLength = cdLength + audio:getDuration() * 1000
end
local sharedVars = {
--- @class SharedVars
--- @field canStart boolean
--- @field screenSize Vector2
--- @field canvasSize Vector2
--- @field singVectors table<Vector2>
--- @field settings table
--- @field receptors table<Sprite>
--- @field splashes table<Sprite>
--- @field opponentReceptors table<Sprite>
--- @field health number
--- @field speed number
--- @field ui table<boolean>
--- @field notes table<Note>
--- @field characters table<Character>
_G.sharedVars = {
canStart = true,
screenSize = Vector2(1280, 720),
canvasSize = Vector2(1920,1080),
@ -598,7 +612,7 @@ local function state(songName, songDifficulty, show)
hold.sprite.position = Vector2(receptors[hold.direction].position.x + hold.offset.x, settings.Downscroll and receptors[hold.direction].position.y - (hold.position-elapsed) * speed or receptors[hold.direction].position.y + (hold.position - elapsed) * speed)
if (hold.position - elapsed) * speed < 10 then
if love.keyboard.isDown(keyBinds[hold.direction]) then
if characters.bf.animInfo["sing"..directions[hold.direction].."-alt"] and (section.altAnim or hold.altAnim) then
if characters.bf.animInfo["sing"..directions[hold.direction].."-alt"] and (section and section.altAnim or hold.altAnim) then
characters.bf:PlayAnimation("sing"..directions[hold.direction].."-alt")
else
characters.bf:PlayAnimation("sing"..directions[hold.direction])
@ -616,7 +630,7 @@ local function state(songName, songDifficulty, show)
else
hold.sprite.position = Vector2(opponentReceptors[hold.direction].position.x + hold.offset.x, settings.Downscroll and opponentReceptors[hold.direction].position.y - (hold.position-elapsed) * speed or opponentReceptors[hold.direction].position.y + (hold.position - elapsed) * speed)
if (hold.position - elapsed) * speed < 10 then
if characters.dad.animInfo["sing"..directions[hold.direction].."-alt"] and (section.altAnim or hold.altAnim) then
if characters.dad.animInfo["sing"..directions[hold.direction].."-alt"] and ( section and section.altAnim or hold.altAnim) then
characters.dad:PlayAnimation("sing"..directions[hold.direction].."-alt")
else
characters.dad:PlayAnimation("sing"..directions[hold.direction])
@ -960,8 +974,6 @@ local function state(songName, songDifficulty, show)
for i, module in next, modules do
if type(module) ~= "boolean" then
module.shared = sharedVars
if module.onCreate then
module.onCreate(chart.song)
end

View File

@ -70,7 +70,7 @@ function module.onCreate()
asset1.position.y = -270
asset1.position.x = -400
for index, receptor in next, module.shared.opponentReceptors do
for index, receptor in next, sharedVars.opponentReceptors do
receptor.ui = false
receptor.position = Vector2(100 * (index - 1), 300)
receptor.layer = -5
@ -89,27 +89,27 @@ function module.onCreate()
evilAtlas.position = Vector2(50000,50000)
evilAtlas.layer = 1
module.shared.settings.Downscroll = true -- forcing downscroll because i am not coding upscroll positions dawg
sharedVars.settings.Downscroll = true -- forcing downscroll because i am not coding upscroll positions dawg
moveAway = false
end
function module.onEvent(event)
if event.name == "ill make" then
if event.var1 == "anim" then
oldPosition = module.shared.characters.dad.stagePosition
oldSpritePosition = module.shared.characters.dad.sprite.position
module.shared.characters.dad.stagePosition = Vector2(50000,5000)
module.shared.characters.dad.sprite.position = Vector2(50000,5000)
oldPosition = sharedVars.characters.dad.stagePosition
oldSpritePosition = sharedVars.characters.dad.sprite.position
sharedVars.characters.dad.stagePosition = Vector2(50000,5000)
sharedVars.characters.dad.sprite.position = Vector2(50000,5000)
evilAtlas.position = Vector2(920, 600)
evilAtlas:PlayAnimation("story_of_yourtalebilly")
elseif event.var1 == "vid" then
evilAtlas:Destroy()
module.shared.characters.dad.stagePosition = oldPosition
module.shared.characters.dad.sprite.position = oldPosition
sharedVars.characters.dad.stagePosition = oldPosition
sharedVars.characters.dad.sprite.position = oldPosition
sillyVideo:play()
startedEvilVideo = true
nextplayerReceptorPosition = Vector2(324, -90)
for index, receptor in next, module.shared.opponentReceptors do
for index, receptor in next, sharedVars.opponentReceptors do
receptor.ui = false
receptor.position = Vector2(10000,10000) -- not visible honk mimimi
receptor.layer = -5
@ -120,10 +120,10 @@ function module.onEvent(event)
elseif event.var1 == "pre" then
nextplayerReceptorPosition = Vector2(600, -90) --Those are tweened to look bettah
moveAway = true
module.shared.ui.timebar = false
module.shared.ui.health = false
module.shared.ui.score = false
module.shared.ui.ratings = false
sharedVars.ui.timebar = false
sharedVars.ui.health = false
sharedVars.ui.score = false
sharedVars.ui.ratings = false
--[[
local ui = {
timebar = true,
@ -146,26 +146,26 @@ function module.onUpdate(dt, el)
rain:send("u_time", el/1000)
currentplayerReceptorPosition = currentplayerReceptorPosition:Lerp(nextplayerReceptorPosition, .05)
for index, note in next, module.shared.notes do
for index, note in next, sharedVars.notes do
if not note.mustPress then
note.sprite.ui = false
note.sprite.layer = -3
end
end
for index, note in next, module.shared.holds do
for index, note in next, sharedVars.holds do
if not note.mustPress then
note.sprite.ui = false
note.sprite.layer = -4
end
end
for index, receptor in next, module.shared.receptors do
for index, receptor in next, sharedVars.receptors do
receptor.position = Vector2(currentplayerReceptorPosition.x + 79 * (index - 1), currentplayerReceptorPosition.y)
end
for index, receptor in next, module.shared.splashes do
for index, receptor in next, sharedVars.splashes do
receptor.position = Vector2(currentplayerReceptorPosition.x - 30 + 79 * (index - 1), currentplayerReceptorPosition.y - 30)
end
for index, receptor in next, module.shared.opponentReceptors do
for index, receptor in next, sharedVars.opponentReceptors do
receptor.position = receptor.position:Lerp(moveAway and Vector2(100 * (index - 1), -100) or Vector2(100 * (index - 1), 300), .05)
end
@ -178,7 +178,7 @@ function module.onUpdate(dt, el)
if not sillyVideo:isPlaying() and not paused and startedEvilVideo and not endedEvilVideo then
endedEvilVideo = true
nextplayerReceptorPosition = Vector2(600, 430)
module.shared.globalShader = evilShader
sharedVars.globalShader = evilShader
end
end
@ -217,7 +217,7 @@ function module.onClose()
introVideo:pause()
introVideo = nil
end
module.shared.globalShader = nil
sharedVars.globalShader = nil
end
return module

View File

@ -1,15 +1,9 @@
local dancers = {}
local curSong
return {
onCreate = function(song)
curSong = song
dancers = {}
local sunset = Image("images/limo/limoSunset.png", .2)
sunset.position = Vector2(-1000, -100)
sunset.resize = Vector2(1.5, 1.5)

View File

@ -1,11 +1,11 @@
local module = {}
function module.onCreate()
module.shared.canvasSize = Vector2(311, 161)
module.shared.screenSize = Vector2(967, 500)
sharedVars.canvasSize = Vector2(311, 161)
sharedVars.screenSize = Vector2(967, 500)
for index, dir in next, module.shared.singVectors do
module.shared.singVectors[index] = dir:Div(5)
for index, dir in next, sharedVars.singVectors do
sharedVars.singVectors[index] = dir:Div(5)
end
love.graphics.setDefaultFilter("nearest", "nearest", 0)

View File

@ -25,8 +25,8 @@ return {
if lightningCountdown == 0 then
mansion:PlayAnimation("halloweem bg lightning strike", 24, false)
module.shared.characters.bf:PlayAnimation("scared")
module.shared.characters.gf:PlayAnimation("scared")
sharedVars.characters.bf:PlayAnimation("scared")
sharedVars.characters.gf:PlayAnimation("scared")
lightningCountdown = love.math.random(15, 20)