libraries_setup #3

Merged
fnicon merged 13 commits from libraries_setup into main 2026-03-18 14:29:14 +00:00
9 changed files with 185 additions and 12 deletions
Showing only changes of commit a5d8478a58 - Show all commits

Binary file not shown.

View File

@ -1,36 +1,39 @@
local world = {
local wm = require("world_map")
world = {
["main_menu"] = require("src.world.main_menu")(),
["1_intro"] = require("src.world.1_intro")(),
["race"] = require("src.world.race")(),
["train"] = require("src.world.train")(),
};
local world_i = "main_menu"
current = wm["main_menu"]
function load_world(world_to_load)
world_i = world_to_load
world[world_i]:reload()
current = world_to_load
world[current]:reload()
end
function love.load()
world[world_i]:load()
world[current]:load()
end
function love.update(dt)
world[world_i]:update(dt)
world[current]:update(dt)
end
function love.draw()
world[world_i]:draw()
world[current]:draw()
end
function love.keyreleased(key, scancode)
world[world_i]:keyreleased(key, scancode)
world[current]:keyreleased(key, scancode)
end
function love.keypressed(key, scancode, isrepeat)
world[world_i]:keypressed(key, scancode, isrepeat)
world[current]:keypressed(key, scancode, isrepeat)
end
function love.mousereleased(x, y, button, istouch, presses)
world[world_i]:mousereleased(x, y, button, istouch, presses)
world[current]:mousereleased(x, y, button, istouch, presses)
end

View File

@ -0,0 +1,68 @@
local reap = require("lib.reap")
local BASE = reap.base_path(...)
local world = require("wrapper.Concord.world")
local debug_entity = require("src.world.common.template.debug_entity")
local button = require("src.world.common.template.button")
local video = require("src.world.common.template.video")
local c_video = require("src.world.common.component.video")
local wm = require("world_map")
local wrapper = world:extend()
local function button_func()
load_world(wm["race"])
end
function wrapper:new()
wrapper.super.new(self, BASE, ".1_intro")
end
function wrapper:load(_args)
wrapper.super.load(self, {
"src/world/common/system/"
}, {
{
assemblage = debug_entity.assembleDebug,
data = {
position = {0, 0},
label = "1_intro"
}
},
{
assemblage = button.assemble,
data = {
collider = {
x = 20,
y = 20,
w = 20,
h = 20
},
func = button_func,
label = "skip"
}
},
{
assemblage = video.assemble,
data = {
path = "asset/video/1_intro.ogv"
}
}
})
end
function wrapper:update(dt)
wrapper.super.update(self, dt)
for k, v in pairs(self.entities) do
local c_v = v[c_video.dict.video]
if c_v ~= nil then
if (not c_v.data.video:isPlaying()) then
load_world(wm["race"])
end
end
end
end
return wrapper

View File

@ -0,0 +1,16 @@
local video = require("wrapper.lappy.new.video").obj
local components = {}
components.dict = {
video = "video",
}
function components.video (c, path)
c.data = {
video = video:load_to(path, path),
path = path
}
end
return components

View File

@ -0,0 +1,50 @@
local system_constructor = require("wrapper.Concord.system")
local c_video = require("src.world.common.component.video")
local system = {}
system.__index = system
system.pool = {
pool = {
c_video.dict.video,
}
}
system.components = {
[c_video.dict.video] = c_video.video,
}
function system.new()
local new_system = system_constructor.new("video_render", system.pool)
if (new_system) then
for k, v in pairs(system) do
new_system[k] = v
end
return new_system
else
return nil
end
end
function system:load()
for _, e in ipairs(self.pool) do
video = e[c_video.dict.video].data.video
video:play()
end
end
function system:update(dt)
for _, e in ipairs(self.pool) do
video = e[c_video.dict.video].data.video
end
end
function system:draw()
for _, e in ipairs(self.pool) do
video = e[c_video.dict.video].data.video
love.graphics.draw(video, 0, 0)
end
end
return system

View File

@ -0,0 +1,12 @@
local video = require("src.world.common.component.video")
local template = {}
template.default_data = {
path = ""
}
function template.assemble(e, data)
e:give(video.dict.video, data.path)
end
return template

View File

@ -6,11 +6,12 @@ local world = require("wrapper.Concord.world")
local debug_entity = require("src.world.common.template.debug_entity")
local button = require("src.world.common.template.button")
local wm = require("world_map")
local wrapper = world:extend()
local function button_func()
load_world("race")
load_world(wm["1_intro"])
end
function wrapper:new()
@ -38,7 +39,7 @@ function wrapper:load(_args)
h = 20
},
func = button_func,
label = "race"
label = "play"
}
}
})

6
game/world_map.lua Normal file
View File

@ -0,0 +1,6 @@
return {
["main_menu"] = "main_menu",
["1_intro"] = "1_intro",
["race"] = "race",
["train"] = "train"
}

View File

@ -0,0 +1,17 @@
local cache = require("lib.reoof.cache")
---@class lappy.video : Cache
---@field cache any
local _cache = cache:extend()
--- new function
function _cache:new()
_cache.super.new(self, love.graphics.newVideo, ".video")
self.cache = {}
end
local obj = _cache()
return {
class = _cache,
obj = obj
}