Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit b3c3863

Browse files
committed
Initial commit
0 parents  commit b3c3863

22 files changed

+848
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
8+
[*.json]
9+
indent_style = space
10+
indent_size = 2
11+
12+
[*.lua]
13+
indent_style = tab
14+
indent_size = 4

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/workflows/deploy.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
deploy:
9+
name: Deploy
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/[email protected]
14+
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: "14"
18+
name: Setup node
19+
20+
- run: npm i -g moonwave@latest
21+
name: Install moonwave
22+
23+
- run: moonwave build
24+
name: Build website
25+
26+
- name: Deploy
27+
run: |
28+
set -ex
29+
git config --global user.email "[email protected]"
30+
git config --global user.name "DreamcraftPackageUser"
31+
REPO="$HOME/docs"
32+
PROJECT_NAME="${GITHUB_REPOSITORY/UpliftGames\//}"
33+
git clone "https://DreamcraftPackageUser:${GITHUB_TOKEN}@github.com/UpliftGames/docs.git" "$REPO"
34+
rm -rf "$REPO/$PROJECT_NAME"
35+
cp -r build "$REPO/$PROJECT_NAME"
36+
cd "$REPO"
37+
git add .
38+
git diff-index --quiet HEAD || git commit --message "Deploy docs"
39+
git push "https://DreamcraftPackageUser:${GITHUB_TOKEN}@github.com/UpliftGames/docs.git"
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.DOCS_PAT }}

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Compiled Lua sources
2+
luac.out
3+
4+
# luarocks build files
5+
*.src.rock
6+
*.zip
7+
*.tar.gz
8+
9+
# Object files
10+
*.o
11+
*.os
12+
*.ko
13+
*.obj
14+
*.elf
15+
16+
# Precompiled Headers
17+
*.gch
18+
*.pch
19+
20+
# Libraries
21+
*.lib
22+
*.a
23+
*.la
24+
*.lo
25+
*.def
26+
*.exp
27+
28+
# Shared objects (inc. Windows DLLs)
29+
*.dll
30+
*.so
31+
*.so.*
32+
*.dylib
33+
34+
# Executables
35+
*.exe
36+
*.out
37+
*.app
38+
*.i*86
39+
*.x86_64
40+
*.hex
41+
42+
Packages
43+
roblox.toml

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Matter
2+
3+
An ECS

default.project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "matter",
3+
"tree": {
4+
"$path": "lib"
5+
}
6+
}

lib/Archetype.lua

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
local Llama = require(script.Parent.Parent.Llama)
2+
3+
local valueIds = {}
4+
local nextValueId = 0
5+
local compatibilityCache = {}
6+
7+
local function getValueId(value)
8+
if valueIds[value] == nil then
9+
valueIds[value] = nextValueId
10+
nextValueId += 1
11+
end
12+
13+
return valueIds[value]
14+
end
15+
16+
function archetypeOf(values)
17+
local list = Llama.List.map(values, getValueId)
18+
table.sort(list)
19+
20+
return table.concat(list, "_")
21+
end
22+
23+
function archetypeOfDict(dict)
24+
return archetypeOf(Llama.Dictionary.keys(dict))
25+
end
26+
27+
function areArchetypesCompatible(query, target)
28+
local cachedCompatibility = compatibilityCache[query .. "-" .. target]
29+
if cachedCompatibility ~= nil then
30+
return cachedCompatibility
31+
end
32+
33+
local queryIds = string.split(query, "_")
34+
local targetIds = Llama.List.toSet(string.split(target, "_"))
35+
36+
for _, queryId in ipairs(queryIds) do
37+
if targetIds[queryId] == nil then
38+
compatibilityCache[query .. "-" .. target] = false
39+
return false
40+
end
41+
end
42+
43+
compatibilityCache[query .. "-" .. target] = true
44+
return true
45+
end
46+
47+
function getCompatibleArchetypes(query, archetypeMap)
48+
local listOfMaps = {}
49+
50+
for targetArchetype, map in pairs(archetypeMap) do
51+
if areArchetypesCompatible(query, targetArchetype) then
52+
table.insert(listOfMaps, map)
53+
end
54+
end
55+
56+
return listOfMaps
57+
end
58+
59+
return {
60+
archetypeOf = archetypeOf,
61+
archetypeOfDict = archetypeOfDict,
62+
getCompatibleArchetypes = getCompatibleArchetypes,
63+
areArchetypesCompatible = areArchetypesCompatible,
64+
}

lib/Archetype.spec.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local Archetype = require(script.Parent.Archetype)
2+
local component = require(script.Parent).component
3+
4+
return function()
5+
describe("Archetype", function()
6+
it("should report same sets as same archetype", function()
7+
local a = component()
8+
local b = component()
9+
expect(Archetype.archetypeOf({ a, b })).to.equal(Archetype.archetypeOf({ b, a }))
10+
end)
11+
it("should identify compatible archetypes", function()
12+
local a = component()
13+
local b = component()
14+
local c = component()
15+
16+
local archetypeA = Archetype.archetypeOf({ a, b, c })
17+
local archetypeB = Archetype.archetypeOf({ a, b })
18+
local archetypeC = Archetype.archetypeOf({ b, c })
19+
20+
expect(Archetype.areArchetypesCompatible(archetypeA, archetypeB)).to.equal(false)
21+
expect(Archetype.areArchetypesCompatible(archetypeB, archetypeA)).to.equal(true)
22+
23+
expect(Archetype.areArchetypesCompatible(archetypeC, archetypeA)).to.equal(true)
24+
expect(Archetype.areArchetypesCompatible(archetypeB, archetypeC)).to.equal(false)
25+
end)
26+
end)
27+
end

lib/Component.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local function newComponent(name)
2+
name = name or debug.info(2, "s") .. "@" .. debug.info(2, "l")
3+
4+
local component = {}
5+
component.__index = component
6+
7+
function component.new(data)
8+
return setmetatable(data or {}, component)
9+
end
10+
11+
setmetatable(component, {
12+
__call = function(_, ...)
13+
return component.new(...)
14+
end,
15+
__tostring = function()
16+
return name
17+
end,
18+
})
19+
20+
return component
21+
end
22+
23+
return {
24+
newComponent = newComponent,
25+
}

lib/Component.spec.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local Component = require(script.Parent.Component)
2+
local component = Component.newComponent
3+
4+
return function()
5+
describe("Component", function()
6+
it("should create components", function()
7+
local a = component()
8+
local b = component()
9+
10+
expect(getmetatable(a)).to.be.ok()
11+
12+
expect(getmetatable(a)).to.never.equal(getmetatable(b))
13+
14+
expect(typeof(a.new)).to.equal("function")
15+
end)
16+
17+
it("should allow calling the table to construct", function()
18+
local a = component()
19+
20+
expect(getmetatable(a())).to.equal(getmetatable(a.new()))
21+
end)
22+
end)
23+
end

0 commit comments

Comments
 (0)