A framework for the Godot engine to create TTRPG games for Advanced 5th Edition, Pathfinder 2nd Edition, and more

Moving to Rust, MessagePack, and WASM

+16 -144
+15 -42
.gitignore
··· 1 - # Created by https://www.toptal.com/developers/gitignore/api/lua 2 - # Edit at https://www.toptal.com/developers/gitignore?templates=lua 1 + # Created by https://www.toptal.com/developers/gitignore/api/rust 2 + # Edit at https://www.toptal.com/developers/gitignore?templates=rust 3 3 4 - ### Lua ### 5 - # Compiled Lua sources 6 - luac.out 4 + ### Rust ### 5 + # Generated by Cargo 6 + # will have compiled files and executables 7 + debug/ 8 + target/ 7 9 8 - # luarocks build files 9 - *.src.rock 10 - *.zip 11 - *.tar.gz 10 + # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 11 + # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 12 + Cargo.lock 12 13 13 - # Object files 14 - *.o 15 - *.os 16 - *.ko 17 - *.obj 18 - *.elf 14 + # These are backup files generated by rustfmt 15 + **/*.rs.bk 19 16 20 - # Precompiled Headers 21 - *.gch 22 - *.pch 17 + # MSVC Windows builds of rustc generate these, which store debugging information 18 + *.pdb 23 19 24 - # Libraries 25 - *.lib 26 - *.a 27 - *.la 28 - *.lo 29 - *.def 30 - *.exp 31 - 32 - # Shared objects (inc. Windows DLLs) 33 - *.dll 34 - *.so 35 - *.so.* 36 - *.dylib 37 - 38 - # Executables 39 - *.exe 40 - *.out 41 - *.app 42 - *.i*86 43 - *.x86_64 44 - *.hex 45 - 46 - 47 - # End of https://www.toptal.com/developers/gitignore/api/lua 20 + # End of https://www.toptal.com/developers/gitignore/api/rust
-3
.gitmodules
··· 1 - [submodule "pf2e"] 2 - path = pf2e 3 - url = https://tangled.org/@cass.cityboundforest.com/dice-wire-pf2e
+1 -9
README.md
··· 27 27 28 28 ## Usage 29 29 30 - You can, of course, just use this as a usual Lua program. The code assumes you load the class file, call it, and assign the resulting function returned to a global variable `class`. You can then load the `hooks` file, along with any other libraries you'd like (i.e. the different systems). Due to the nature of this framework, I will not be writing code to load a system's code, but it shouldn't be too difficult to do so. 31 - 32 - After loading everything, call the following code: 33 - 34 - ```lua 35 - Hooks:emit("init") 36 - ``` 37 - 38 - This will call every function callback under the `init` event. 30 + **TODO**: Need to add this later for Rust and MessagePack
-47
class.lua
··· 1 - -- class.lua 2 - -- Compatible with Lua 5.1 (not 5.0). 3 - function class(base, init) 4 - local c = {} -- a new class instance 5 - if not init and type(base) == 'function' then 6 - init = base 7 - base = nil 8 - elseif type(base) == 'table' then 9 - -- our new class is a shallow copy of the base class! 10 - for i,v in pairs(base) do 11 - c[i] = v 12 - end 13 - c._base = base 14 - end 15 - -- the class will be the metatable for all its objects, 16 - -- and they will look up their methods in it. 17 - c.__index = c 18 - 19 - -- expose a constructor which can be called by <classname>(<args>) 20 - local mt = {} 21 - mt.__call = function(class_tbl, ...) 22 - local obj = {} 23 - setmetatable(obj,c) 24 - if init then 25 - init(obj,...) 26 - else 27 - -- make sure that any stuff from the base class is initialized! 28 - if base and base.init then 29 - base.init(obj, ...) 30 - end 31 - end 32 - return obj 33 - end 34 - c.init = init 35 - c.is_a = function(self, klass) 36 - local m = getmetatable(self) 37 - while m do 38 - if m == klass then return true end 39 - m = m._base 40 - end 41 - return false 42 - end 43 - setmetatable(c, mt) 44 - return c 45 - end 46 - 47 - return class
-43
hooks.lua
··· 1 - hooks = class(function(self) 2 - self.events = {} 3 - end) 4 - 5 - function hooks:on(event, callback) 6 - if not self.events[event] then 7 - self.events[event] = {} 8 - end 9 - 10 - table.insert(self.events[event], callback) 11 - end 12 - 13 - function hooks:once(event, callback) 14 - local wrapper 15 - wrapper = function(...) 16 - callback(...) 17 - self:off(event, wrapper) 18 - end 19 - 20 - self:on(event, wrapper) 21 - end 22 - 23 - function hooks:off(event, callback) 24 - local list = self.events[event] 25 - if not list then return end 26 - for i, cb in ipairs(list) do 27 - if cb == callback then 28 - table.remove(list, i) 29 - return 30 - end 31 - end 32 - end 33 - 34 - function hooks:emit(event, ...) 35 - local list = self.events[event] 36 - if not list then return end 37 - for _, cb in ipairs(list) do 38 - cb(...) 39 - end 40 - end 41 - 42 - local Hooks = hooks() 43 - return Hooks