-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.lua
44 lines (36 loc) · 1.15 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local lecs = require("lecs.init")
local Component = lecs.Component
local System = lecs.System
local World = lecs.World
local PlayerComponent = class("PlayerComponent", Component)
function PlayerComponent:ctor(...)
PlayerComponent.super.ctor(self, ...)
self.name = "Joe"
self.phrase = "I'm a plumber."
self.mass = 150
self.hairColor = "brown"
end
local TalkingSystem = class("TalkingSystem", System)
function TalkingSystem:CreateFilter()
return self.filter.RequireAll(PlayerComponent)
end
function TalkingSystem:Update(entities, dt)
for _, e in ipairs(entities) do
local PlayerComp = e:GetComponent("PlayerComponent")
PlayerComp.mass = PlayerComp.mass + dt * 3
Log.i(("%s who weighs %d pounds, says %q."):format(PlayerComp.name, PlayerComp.mass, PlayerComp.phrase))
end
end
local world = World.new()
local talk_system = TalkingSystem.new()
world:AddSystem(talk_system)
local playerEntity = world:CreateEntity()
playerEntity:AddComponent(PlayerComponent.new())
return function()
for _ = 1, 20 do
world:Update(1)
end
end
-- skynet.timeout(20 * 100, function ()
-- require("fecs.test")()
-- end)