packaging: Add pesde support, feat: Add searching and clearing to ref
+ Added pesde support + Added `.search()` to `ref` and made `ref()` (`.set_ref()`) & `.search()` return a clearer which removes the reference + Bumped to 0.1.6
This commit is contained in:
parent
d235e883a1
commit
b4cc94f369
14 changed files with 109 additions and 15 deletions
8
.github/workflows/release.yml
vendored
8
.github/workflows/release.yml
vendored
|
@ -69,5 +69,11 @@ jobs:
|
|||
- name: Wally Login
|
||||
run: wally login --token ${{ secrets.WALLY_AUTH_TOKEN }}
|
||||
|
||||
- name: Publish
|
||||
- name: Wally Publish
|
||||
run: wally publish
|
||||
|
||||
- name: Pesde Login
|
||||
run: pesde auth login --token "Bearer ${{ secrets.WALLY_AUTH_TOKEN }}"
|
||||
|
||||
- name: Pesde Publish
|
||||
run: pesde publish
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
--!strict
|
||||
local fs = require("@lune/fs")
|
||||
local spawn = require("util/spawn")
|
||||
|
||||
spawn.start("rojo sourcemap dev.project.json -o sourcemap.json")
|
||||
spawn.start("lune run install-packages")
|
||||
spawn.start("darklua process --config .darklua.json lib/ dist/", { env = { ROBLOX_DEV = "false" } })
|
||||
|
||||
for _, path in fs.readDir("dist") do
|
||||
path = `dist/{path}`
|
||||
if not fs.isFile(path) then
|
||||
continue
|
||||
end
|
||||
|
||||
print("found working file")
|
||||
|
||||
local file = fs.readFile(path)
|
||||
local new_contents =
|
||||
string.gsub(file, `require%("%.%./jecs"%)`, `require(script.Parent.Parent:FindFirstChild('jecs'))`)
|
||||
fs.writeFile(path, new_contents)
|
||||
end
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
"mode": "relativeToFile",
|
||||
"fileAliases": {
|
||||
"@jecs_utils": "lib",
|
||||
"@jecs": "Packages/jecs",
|
||||
"@testkit": "test/testkit"
|
||||
"@testkit": "test/testkit",
|
||||
"@jecs": "Packages/jecs"
|
||||
},
|
||||
"directoryAliases": {
|
||||
"@lune": ".lune/.lune-defs/"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
type entity<T = nil> = jecs.Entity<T>
|
||||
type id<T = nil> = jecs.Id<T>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
type entity<T = nil> = jecs.Entity<T>
|
||||
type id<T = nil> = entity<T> | jecs.Pair
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
|
||||
local WORLD = require("./world")
|
||||
|
||||
|
|
42
lib/ref.luau
42
lib/ref.luau
|
@ -1,17 +1,23 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local handle = require("./handle")
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
local WORLD = require("./world").get
|
||||
|
||||
local refs: { [jecs.World]: { [any]: jecs.Entity<any> } } = {}
|
||||
|
||||
local function serve_clearer(key: any, world: jecs.World): () -> ()
|
||||
return function()
|
||||
refs[world][key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets an entity the given key references to.
|
||||
--- If the key is nil, an entirely new entity is created and returned.
|
||||
--- If the key doesn't reference an entity, a new entity is made for it to reference and returned.
|
||||
--- @param key any
|
||||
--- @return handle
|
||||
local function ref(key: any): handle.handle
|
||||
local function ref(key: any): (handle.handle, () -> ()?)
|
||||
local world = WORLD()
|
||||
if not key then
|
||||
return handle(world:entity())
|
||||
|
@ -27,7 +33,35 @@ local function ref(key: any): handle.handle
|
|||
refs[world][key] = entity
|
||||
end
|
||||
|
||||
return handle(entity)
|
||||
return handle(entity), serve_clearer(key, world)
|
||||
end
|
||||
|
||||
return ref
|
||||
-- For the `__call`` metamethod
|
||||
local function __call(_, key: any): (handle.handle, () -> ()?)
|
||||
return ref(key)
|
||||
end
|
||||
|
||||
local function search(key: any): (handle.handle?, () -> ()?)
|
||||
local world = WORLD()
|
||||
if not key then
|
||||
return nil
|
||||
end
|
||||
local entity = refs[world][key]
|
||||
|
||||
if not entity then
|
||||
return nil
|
||||
end
|
||||
|
||||
return handle(entity), serve_clearer(key, world)
|
||||
end
|
||||
|
||||
local metatable = {
|
||||
__call = __call,
|
||||
__index = {
|
||||
search = search,
|
||||
set_ref = ref,
|
||||
},
|
||||
}
|
||||
|
||||
local REF = setmetatable({}, metatable) :: typeof(ref) & typeof(metatable.__index)
|
||||
return REF
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
type entity<T = nil> = jecs.Entity<T>
|
||||
type i53 = number
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--!strict
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
type entity<T = nil> = jecs.Entity<T>
|
||||
type id<T = nil> = jecs.Id<T>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local jecs = require("@jecs")
|
||||
local jecs = require("../jecs")
|
||||
|
||||
local WORLD: jecs.World
|
||||
|
||||
|
|
17
pesde.toml
Normal file
17
pesde.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
name = "mark_marks/jecs_utils"
|
||||
version = "0.1.6"
|
||||
description = "A set of utilities for jecs"
|
||||
authors = ["marked/Mark-Marks"]
|
||||
repository = "https://github.com/mark-marks/jecs-utils"
|
||||
license = "MIT"
|
||||
|
||||
include = ["src", "src/**", "LICENSE", "pesde.toml", "README.md"]
|
||||
|
||||
[target]
|
||||
environment = "luau"
|
||||
|
||||
[indices]
|
||||
default = "https://github.com/daimond113/pesde-index"
|
||||
|
||||
[dependencies]
|
||||
jecs = { repo = "https://git.devmarked.win/marked/jecs-pesde", rev = "main" }
|
|
@ -12,3 +12,4 @@ luau-lsp = "johnnymorganz/luau-lsp@1.32.4"
|
|||
stylua = "johnnymorganz/stylua@0.20.0"
|
||||
wally-package-types = "johnnymorganz/wally-package-types@1.3.2"
|
||||
darklua = "seaofvoices/darklua@0.13.1"
|
||||
pesde = "daimond113/pesde@0.5.0-rc.8"
|
||||
|
|
|
@ -10,6 +10,7 @@ local collect = jecs_utils.collect
|
|||
local handle = jecs_utils.handle
|
||||
local replicator = jecs_utils.replicator
|
||||
local ref = jecs_utils.ref
|
||||
local ref_search = ref.search
|
||||
local command_buffer = jecs_utils.command_buffer
|
||||
local spawner = jecs_utils.spawner
|
||||
|
||||
|
@ -104,7 +105,7 @@ TEST("jecs_utils.handle()", function()
|
|||
end)
|
||||
|
||||
TEST("jecs_utils.ref()", function()
|
||||
do CASE "ref(abc) == ref(abc)"
|
||||
do CASE "set_ref"
|
||||
local world = jecs.World.new()
|
||||
jecs_utils.initialize(world)
|
||||
|
||||
|
@ -112,6 +113,26 @@ TEST("jecs_utils.ref()", function()
|
|||
local b: number = ref(1234):id()
|
||||
CHECK(a == b)
|
||||
end
|
||||
|
||||
do CASE "search"
|
||||
local world = jecs.World.new()
|
||||
jecs_utils.initialize(world)
|
||||
|
||||
local a: number = ref(1234):id()
|
||||
local b = ref_search(1234)
|
||||
assert(b) -- give me the type refinements...
|
||||
CHECK(a == b:id() :: number)
|
||||
end
|
||||
|
||||
do CASE "clearer"
|
||||
local world = jecs.World.new()
|
||||
jecs_utils.initialize(world)
|
||||
|
||||
local a, a_clear = ref(1234);
|
||||
(a_clear :: any)()
|
||||
local b = ref(1234)
|
||||
CHECK(b:id() :: number ~= a:id() :: number)
|
||||
end
|
||||
end)
|
||||
|
||||
TEST("jecs_utils.replicator()", function()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mark-marks/jecs-utils"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
license = "MIT"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue