Compare commits
No commits in common. "d0a926302e55b732498e2b1c24cf0f05d44bcbf6" and "a3a82b9c670984f0047577c94941571973f93c83" have entirely different histories.
d0a926302e
...
a3a82b9c67
@ -67,7 +67,7 @@ end
|
||||
---@param name? string for debug purposes
|
||||
---@param max? number pool max size
|
||||
---@param efn? fun(...):boolean equal Function
|
||||
-- ---@return Pool self
|
||||
---@return Pool self
|
||||
function pool:new(fn, rfn, name, max, efn)
|
||||
-- local self = setmetatable({}, pool)
|
||||
self.active = {}
|
||||
@ -77,6 +77,7 @@ function pool:new(fn, rfn, name, max, efn)
|
||||
self.efn = efn or defaultEqual
|
||||
self.max = max > 0 and max or nil
|
||||
self.name = name or "pool"
|
||||
return self
|
||||
end
|
||||
|
||||
--- put entity to pool
|
||||
|
||||
@ -1,37 +1,45 @@
|
||||
local world = {
|
||||
require("src.world.race")(),
|
||||
require("src.world.train")()
|
||||
local mode = {
|
||||
require("src.modes.racing"),
|
||||
require("src.modes.raising_sim")
|
||||
};
|
||||
|
||||
local world_i = 1
|
||||
local actor = require("src.entities.shared.actor")
|
||||
local player = actor.load("player")
|
||||
|
||||
local source_cls = require("wrapper.lappy.new.source")
|
||||
local source = source_cls.obj
|
||||
|
||||
local mode_i = 1
|
||||
|
||||
function love.load()
|
||||
world[world_i]:load()
|
||||
source:load_to("asset/audio/bgm/Ensemble.mp3", "asset/audio/bgm/Ensemble.mp3", "stream")
|
||||
source:load_from("asset/audio/bgm/Ensemble.mp3"):play()
|
||||
mode[mode_i].load(player)
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
world[world_i]:update(dt)
|
||||
mode[mode_i].update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
world[world_i]:draw()
|
||||
mode[mode_i].draw()
|
||||
end
|
||||
|
||||
function love.keyreleased(key, scancode)
|
||||
if (key == "right") then
|
||||
world_i = world_i + 1
|
||||
if (world_i > 2) then
|
||||
world_i = 1
|
||||
mode_i = mode_i + 1
|
||||
if (mode_i > 2) then
|
||||
mode_i = 1
|
||||
end
|
||||
world[world_i]:reload()
|
||||
mode[mode_i].load(player)
|
||||
end
|
||||
world[world_i]:keyreleased(key, scancode)
|
||||
mode[mode_i].keyreleased(key, scancode)
|
||||
end
|
||||
|
||||
function love.keypressed(key, scancode, isrepeat)
|
||||
world[world_i]:keypressed(key, scancode, isrepeat)
|
||||
mode[mode_i].keypressed(key, scancode, isrepeat)
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, button, istouch, presses)
|
||||
world[world_i]:mousereleased(x, y, button, istouch, presses)
|
||||
mode[mode_i].mousereleased(x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
local components = {}
|
||||
|
||||
components.dict = {
|
||||
debug_label = "debug_label",
|
||||
}
|
||||
|
||||
function components.debug_label (c, label)
|
||||
c.data = label
|
||||
end
|
||||
|
||||
return components
|
||||
@ -1,23 +0,0 @@
|
||||
local vm = require("lib.vornmath")
|
||||
|
||||
local components = {}
|
||||
|
||||
components.dict = {
|
||||
position = "position",
|
||||
scale = "scale",
|
||||
rotation = "rotation"
|
||||
}
|
||||
|
||||
function components.position (c, x, y, z)
|
||||
c.data = vm.vec3(x or 0, y or 0, z or 0)
|
||||
end
|
||||
|
||||
function components.scale (c, sx, sy, sz)
|
||||
c.data = vm.vec3(sx or 1, sy or 1, sz or 1)
|
||||
end
|
||||
|
||||
function components.rotation (c, rx, ry, rz)
|
||||
c.data = vm.vec3(rx or 0, ry or 0, rz or 0)
|
||||
end
|
||||
|
||||
return components
|
||||
@ -1,48 +0,0 @@
|
||||
local system_constructor = require("wrapper.Concord.system")
|
||||
local debug_label = require("src.world.common.component.debug_label")
|
||||
local transform = require("src.world.common.component.transform")
|
||||
|
||||
local system = {}
|
||||
|
||||
system.__index = system
|
||||
|
||||
system.pool = {
|
||||
pool = {
|
||||
debug_label.dict.debug_label,
|
||||
transform.dict.position
|
||||
}
|
||||
}
|
||||
|
||||
system.components = {
|
||||
[debug_label.dict.debug_label] = debug_label.debug_label,
|
||||
[transform.dict.position] = transform.position
|
||||
}
|
||||
|
||||
function system.new()
|
||||
local new_system = system_constructor.new("debug_world_draw", 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
|
||||
|
||||
local function draw(text, x, y)
|
||||
love.graphics.push()
|
||||
love.graphics.print(text, x, y)
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
function system:draw()
|
||||
for _, e in ipairs(self.pool) do
|
||||
local text = e[debug_label.dict.debug_label].data
|
||||
local x = e[transform.dict.position].data[1]
|
||||
local y = e[transform.dict.position].data[2]
|
||||
draw(text, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
return system
|
||||
@ -1,14 +0,0 @@
|
||||
local debug_world_draw = require("src.world.common.system.debug_world_draw")
|
||||
|
||||
local template = {}
|
||||
|
||||
template.default_data = {
|
||||
position = {0, 0},
|
||||
label = "debug"
|
||||
}
|
||||
function template.assembleDebug(e, data)
|
||||
e:give(debug_world_draw.pool.pool[1], data.label)
|
||||
e:give(debug_world_draw.pool.pool[2], data.position[1], data.position[2])
|
||||
end
|
||||
|
||||
return template
|
||||
@ -1,29 +0,0 @@
|
||||
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 wrapper = world:extend()
|
||||
|
||||
function wrapper:new()
|
||||
wrapper.super.new(self, BASE, ".race")
|
||||
end
|
||||
|
||||
function wrapper:load(_args)
|
||||
wrapper.super.load(self, {
|
||||
"src/world/common/system/"
|
||||
}, {
|
||||
{
|
||||
assemblage = debug_entity.assembleDebug,
|
||||
data = {
|
||||
position = {0, 0},
|
||||
label = "race world"
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return wrapper
|
||||
@ -1,29 +0,0 @@
|
||||
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 wrapper = world:extend()
|
||||
|
||||
function wrapper:new()
|
||||
wrapper.super.new(self, BASE, ".train")
|
||||
end
|
||||
|
||||
function wrapper:load(_args)
|
||||
wrapper.super.load(self, {
|
||||
"src/world/common/system/"
|
||||
}, {
|
||||
{
|
||||
assemblage = debug_entity.assembleDebug,
|
||||
data = {
|
||||
position = {0, 0},
|
||||
label = "train world"
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return wrapper
|
||||
@ -1,37 +0,0 @@
|
||||
local Concord = require("lib.Concord")
|
||||
|
||||
-- Modules
|
||||
local Entity = Concord.entity
|
||||
local Component = Concord.component
|
||||
local System = Concord.system
|
||||
local World = Concord.world
|
||||
|
||||
-- Containers
|
||||
local Components = Concord.components
|
||||
|
||||
local constructor = {}
|
||||
|
||||
function constructor.default_component_lambda(c, data)
|
||||
c.data = data
|
||||
end
|
||||
|
||||
--- build component ecs component
|
||||
---@param name string
|
||||
---@param lambda? function(c, data)
|
||||
function constructor.component(name, lambda)
|
||||
local ok, value = Components.try(name)
|
||||
if not ok then
|
||||
return Component(name, lambda or constructor.default_component_lambda)
|
||||
end
|
||||
end
|
||||
|
||||
--- build component ecs state
|
||||
---@param name string
|
||||
function constructor.state(name)
|
||||
local ok, value = Components.try(name)
|
||||
if not ok then
|
||||
return Component(name)
|
||||
end
|
||||
end
|
||||
|
||||
return constructor
|
||||
@ -1,91 +0,0 @@
|
||||
local format = string.format
|
||||
|
||||
local reap = require("lib.reap")
|
||||
|
||||
local BASE = reap.base_path(...)
|
||||
local component_builder = require(format("%s.component", BASE))
|
||||
|
||||
local Concord = require("lib.Concord")
|
||||
|
||||
-- Modules
|
||||
local Entity = Concord.entity
|
||||
local Component = Concord.component
|
||||
local System = Concord.system
|
||||
local World = Concord.world
|
||||
|
||||
-- Containers
|
||||
local Components = Concord.components
|
||||
|
||||
local constructor = {}
|
||||
|
||||
--- build entity ecs
|
||||
function constructor.new(system)
|
||||
if (type(system) == "table") then
|
||||
local e = Entity()
|
||||
for _, s in pairs(system) do
|
||||
for c, f in pairs(s.components) do
|
||||
if (type(c) == "string") then
|
||||
component_builder.component(c, f)
|
||||
else
|
||||
component_builder.state(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
return e
|
||||
elseif (system == nil) then
|
||||
return Entity()
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- ensure component
|
||||
---@param entity any
|
||||
---@param name string
|
||||
function constructor.ensure(entity, name, ...)
|
||||
if (#{...} == 0) then
|
||||
component_builder.state(name)
|
||||
entity:ensure(name)
|
||||
else
|
||||
component_builder.component(name)
|
||||
entity:ensure(name, ...)
|
||||
end
|
||||
end
|
||||
|
||||
--- give component
|
||||
---@param entity any
|
||||
---@param name string
|
||||
function constructor.give(entity, name, ...)
|
||||
if (#{...} == 0) then
|
||||
component_builder.state(name)
|
||||
entity:give(name)
|
||||
else
|
||||
component_builder.component(name)
|
||||
entity:give(name, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function constructor.remove(entity, name)
|
||||
if Components.has(name) == false then
|
||||
return false, nil
|
||||
else
|
||||
if entity:has(name) then
|
||||
local data = entity[name]
|
||||
entity:remove(name)
|
||||
return true, data
|
||||
else
|
||||
return false, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function constructor.destroy(entity)
|
||||
local all_c = entity:getComponents()
|
||||
for c_id, c in ipairs(all_c) do
|
||||
entity:remove(c)
|
||||
print("destroy", c_id, c)
|
||||
end
|
||||
entity:destroy()
|
||||
end
|
||||
|
||||
return constructor
|
||||
@ -1,84 +0,0 @@
|
||||
local insert = table.insert
|
||||
|
||||
local Concord = require("lib.Concord")
|
||||
|
||||
-- Modules
|
||||
local Entity = Concord.entity
|
||||
local Component = Concord.component
|
||||
local System = Concord.system
|
||||
local World = Concord.world
|
||||
|
||||
-- Containers
|
||||
local Components = Concord.components
|
||||
|
||||
|
||||
local constructor = {}
|
||||
|
||||
constructor.systems = {}
|
||||
|
||||
local function is_component_complete(pool)
|
||||
local is_complete = true
|
||||
for _, v in pairs(pool) do
|
||||
for _, c in ipairs(v) do
|
||||
if (Components.has(c) == false) then
|
||||
is_complete = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if (not is_complete) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return is_complete
|
||||
end
|
||||
|
||||
function constructor.new(name, pool)
|
||||
if (constructor.systems[name]) then
|
||||
return constructor.systems[name]
|
||||
else
|
||||
if (type(pool) == "table") then
|
||||
if (is_component_complete(pool)) then
|
||||
local self = System(pool)
|
||||
self.name = name
|
||||
constructor.systems[name] = self
|
||||
return self
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
error("new system register error. pool and wrapper should be a table.")
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function constructor.add(world, path)
|
||||
local namespace = {}
|
||||
if (type(path) == "string") then
|
||||
Concord.utils.loadNamespace(path, namespace)
|
||||
else
|
||||
for k,v in pairs(path) do
|
||||
if type(v) == "string" then
|
||||
local new_namespace = {}
|
||||
Concord.utils.loadNamespace(v, new_namespace)
|
||||
for l, w in pairs(new_namespace) do
|
||||
namespace[l] = w
|
||||
end
|
||||
else
|
||||
insert(namespace, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
for k,v in pairs(namespace) do
|
||||
local new_sys = v.new()
|
||||
if (new_sys == nil) then
|
||||
|
||||
else
|
||||
if not world:hasSystem(new_sys) then
|
||||
world:addSystems(new_sys)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return constructor
|
||||
@ -1,12 +1,12 @@
|
||||
local format = string.format
|
||||
|
||||
local reap = require("lib.reap")
|
||||
local reap = require("libs.reap")
|
||||
|
||||
local BASE = reap.base_path(...)
|
||||
local component_builder = require(format("%s.component", BASE))
|
||||
local entity_builder = require(format("%s.entity", BASE))
|
||||
|
||||
local Concord = require("lib.Concord")
|
||||
local Concord = require("libs.Concord")
|
||||
|
||||
-- Modules
|
||||
local Entity = Concord.entity
|
||||
@ -20,7 +20,6 @@ local wrapper = main_wrapper:extend()
|
||||
|
||||
function wrapper:new(path, name)
|
||||
wrapper.super.new(self, path, name)
|
||||
self.is_loaded = false
|
||||
self.world = World()
|
||||
end
|
||||
|
||||
@ -57,17 +56,9 @@ end
|
||||
function wrapper:load(system_paths, entities_data)
|
||||
load_systems(self.world, system_paths)
|
||||
load_entities(self.world, entities_data)
|
||||
self.is_loaded = true
|
||||
self.world:emit("load")
|
||||
end
|
||||
|
||||
function wrapper:reload(system_paths, entities_data)
|
||||
if not self.is_loaded then
|
||||
self:load(system_paths, entities_data)
|
||||
end
|
||||
self.world:emit("reload")
|
||||
end
|
||||
|
||||
function wrapper:draw()
|
||||
self.world:emit("draw")
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
local classic = require "lib.classic.classic"
|
||||
local classic = require "lib.classic"
|
||||
---@class lappy.world : lib.classic.class
|
||||
local wrapper = classic:extend()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user