Compare commits

...

6 commits
v4.0 ... main

Author SHA1 Message Date
Justin van der Leij
848652f688
Make example for how to use Concord.utils.loadNamespace for systems more concrete 2024-06-30 10:45:46 +02:00
Justin van der Leij
30b21c4c25
Merge pull request #78 from denisdefreyne/patch-1
Fix typo in README.md
2024-06-30 10:38:53 +02:00
Justin van der Leij
9f187f12e5
Merge pull request #76 from lambtoken/typo-fix
Added missing do keyword in the loops
2024-06-30 10:38:15 +02:00
Denis Defreyne
6575686b3b
Fix typo in README.md
A piece of example code was missing a `,`.
2024-06-29 10:28:12 +02:00
Justin van der Leij
1aaf501401
Update README.md to hint that components should be loaded for systems 2024-05-27 13:53:55 +02:00
lambtoken
f9da8dbe92 Added missing do keyword in the loops 2023-12-23 09:37:03 +01:00

View file

@ -133,16 +133,21 @@ Concord does a few things that might not be immediately clear. This segment shou
Since you'll have lots of Components and Systems in your game Concord makes it a bit easier to load things in. Since you'll have lots of Components and Systems in your game Concord makes it a bit easier to load things in.
```lua ```lua
-- Loads all files in the directory, and puts the return value in the table Systems. The key is their filename without any extension
local Systems = {}
Concord.utils.loadNamespace("path/to/systems", Systems)
print(Systems.systemName)
-- Loads all files in the directory. Components automatically register into Concord.components, so loading them into a namespace isn't necessary. -- Loads all files in the directory. Components automatically register into Concord.components, so loading them into a namespace isn't necessary.
Concord.utils.loadNamespace("path/to/components") Concord.utils.loadNamespace("path/to/components")
print(Concord.components.componentName) print(Concord.components.componentName)
-- Loads all files in the directory, and puts the return value in the table Systems. The key is their filename without any extension
local Systems = {}
Concord.utils.loadNamespace("path/to/systems", Systems)
myWorld:addSystems(
Systems.healthSystem
Systems.damageSystem,
Systems.moveSystem,
-- etc
)
``` ```
#### Method chaining #### Method chaining
@ -170,7 +175,7 @@ When defining a ComponentClass you need to pass in a name and usually a `populat
-- Create the position class with a populate function -- Create the position class with a populate function
-- The component variable is the actual Component given to an Entity -- The component variable is the actual Component given to an Entity
-- The x and y variables are values we pass in when we create the Component -- The x and y variables are values we pass in when we create the Component
Concord.component("position" function(component, x, y) Concord.component("position", function(component, x, y)
component.x = x or 0 component.x = x or 0
component.y = y or 0 component.y = y or 0
end) end)
@ -294,14 +299,14 @@ end
-- Defining a function -- Defining a function
function mySystemClass:update(dt) function mySystemClass:update(dt)
-- Iterate over all entities in the Pool -- Iterate over all entities in the Pool
for _, e in ipairs(self.pool) for _, e in ipairs(self.pool) do
-- Do something with the Components -- Do something with the Components
e.position.x = e.position.x + e.velocity.x * dt e.position.x = e.position.x + e.velocity.x * dt
e.position.y = e.position.y + e.velocity.y * dt e.position.y = e.position.y + e.velocity.y * dt
end end
-- Iterate over all entities in the second Pool -- Iterate over all entities in the second Pool
for _, e in ipairs(self.secondPool) for _, e in ipairs(self.secondPool) do
-- Do something -- Do something
end end
end end