mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Provide rpc api for other mods
This commit is contained in:
parent
d5e7f54ef1
commit
3e93f3741c
3 changed files with 40 additions and 0 deletions
11
quant.ew/files/api/ew_api.lua
Normal file
11
quant.ew/files/api/ew_api.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
local ew_api = {}
|
||||
|
||||
-- Creates an rpc namespace. See ew_api_example for how to use it.
|
||||
ew_api.new_rpc_namespace = net.new_rpc_namespace_with_id
|
||||
|
||||
-- In rpc, returns player_data of a peer who called that rpc.
|
||||
function ew_api.rpc_player_data()
|
||||
return ctx.rpc_player_data
|
||||
end
|
||||
|
||||
return ew_api
|
|
@ -67,6 +67,11 @@ local rpc_meta = {
|
|||
__newindex = function (t, k, v)
|
||||
table.insert(rpc_inner.rpcs, v)
|
||||
local index = #rpc_inner.rpcs
|
||||
if t._ew_id ~= nil then
|
||||
index = t._ew_id..t._ew_index
|
||||
t._ew_index = t._ew_index + 1
|
||||
print("Created API rpc: "..index)
|
||||
end
|
||||
local reliable = rpc_inner.opts.reliable == true
|
||||
local everywhere = rpc_inner.opts.everywhere == true
|
||||
rawset(t, k, function(...)
|
||||
|
@ -97,6 +102,14 @@ function net.new_rpc_namespace()
|
|||
return ret
|
||||
end
|
||||
|
||||
function net.new_rpc_namespace_with_id(id)
|
||||
local ret = {}
|
||||
ret._ew_id = id
|
||||
ret._ew_index = 0
|
||||
setmetatable(ret, rpc_meta)
|
||||
return ret
|
||||
end
|
||||
|
||||
function net.init()
|
||||
local ready = false
|
||||
local addr = os.getenv("NP_NOITA_ADDR") or "127.0.0.1:21251"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue