Switch to new sharedstate/sharedconfig libraries
This commit is contained in:
parent
e1617fb880
commit
57aaaf1baa
78
script.lua
78
script.lua
@ -21,37 +21,12 @@ logging=require("nulllib.logging")
|
|||||||
nmath=require("nulllib.math")
|
nmath=require("nulllib.math")
|
||||||
timers=require("nulllib.timers")
|
timers=require("nulllib.timers")
|
||||||
util=require("nulllib.util")
|
util=require("nulllib.util")
|
||||||
|
sharedstate=require("nulllib.sharedstate")
|
||||||
|
sharedconfig=require("nulllib.sharedconfig")
|
||||||
|
|
||||||
wave=nmath.wave
|
wave=nmath.wave
|
||||||
lerp=math.lerp
|
lerp=math.lerp
|
||||||
|
|
||||||
-- -- syncState {{{
|
|
||||||
-- function syncState()
|
|
||||||
-- ping.syncState(setLocalState())
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- do
|
|
||||||
-- local pm_refresh=false
|
|
||||||
-- function pmRefresh()
|
|
||||||
-- pm_refresh=true
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- function doPmRefresh()
|
|
||||||
-- if pm_refresh then
|
|
||||||
-- PartsManager.refreshAll()
|
|
||||||
-- pm_refresh=false
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- function ping.syncState(tbl)
|
|
||||||
-- for k, v in pairs(tbl) do
|
|
||||||
-- local_state[k]=v
|
|
||||||
-- end
|
|
||||||
-- pmRefresh()
|
|
||||||
-- end
|
|
||||||
-- -- }}}
|
|
||||||
|
|
||||||
-- Master and local state variables -- {{{
|
-- Master and local state variables -- {{{
|
||||||
-- Local State (these are copied by pings at runtime) --
|
-- Local State (these are copied by pings at runtime) --
|
||||||
local_state={}
|
local_state={}
|
||||||
@ -66,57 +41,16 @@ do
|
|||||||
["print_settings"]=false,
|
["print_settings"]=false,
|
||||||
["tail_enabled"]=true,
|
["tail_enabled"]=true,
|
||||||
}
|
}
|
||||||
function setLocalState()
|
|
||||||
if is_host then
|
|
||||||
for k, v in pairs(skin_state) do
|
|
||||||
local_state[k]=v
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for k, v in pairs(defaults) do
|
|
||||||
if local_state[k] == nil then local_state[k]=v end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return local_state
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO reimplement with new data API
|
|
||||||
-- if is_host then
|
|
||||||
if false then
|
|
||||||
local savedData=data.loadAll()
|
|
||||||
if savedData == nil then
|
|
||||||
for k, v in pairs(defaults) do
|
|
||||||
data.save(k, v)
|
|
||||||
end
|
|
||||||
savedData=data.loadAll()
|
|
||||||
end
|
|
||||||
skin_state=mergeTable(
|
|
||||||
map(unstring,data.loadAll()),
|
|
||||||
defaults)
|
|
||||||
else
|
|
||||||
skin_state=defaults
|
|
||||||
end
|
|
||||||
setLocalState()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function printSettings()
|
function printSettings()
|
||||||
print("Settings:")
|
print("Settings:")
|
||||||
for k, v in pairs(skin_state) do
|
printTable(sharedconfig.load())
|
||||||
print(tostring(k)..": "..tostring(v))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if skin_state.print_settings==true then
|
if sharedconfig.load("print_settings") then
|
||||||
printSettings()
|
printSettings()
|
||||||
end
|
end
|
||||||
|
|
||||||
function setState(name, state)
|
|
||||||
if state == nil then
|
|
||||||
skin_state[name]=not skin_state[name]
|
|
||||||
else
|
|
||||||
skin_state[name]=state
|
|
||||||
end
|
|
||||||
data.save(name, skin_state[name])
|
|
||||||
end
|
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- Part groups {{{
|
-- Part groups {{{
|
||||||
@ -253,8 +187,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function setArmor()
|
function setArmor()
|
||||||
setState("armor_enabled")
|
sharedconfig.save("armor_enabled", not sharedconfig.load("armor_enabled"))
|
||||||
syncState()
|
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
@ -262,7 +195,6 @@ function player_init()
|
|||||||
-- for k, v in pairs(reduce(mergeTable, map(recurseModelGroup, model))) do
|
-- for k, v in pairs(reduce(mergeTable, map(recurseModelGroup, model))) do
|
||||||
-- v.setEnabled(true)
|
-- v.setEnabled(true)
|
||||||
-- end
|
-- end
|
||||||
setLocalState()
|
|
||||||
-- syncState()
|
-- syncState()
|
||||||
events.ENTITY_INIT:remove("player_init")
|
events.ENTITY_INIT:remove("player_init")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user