Add skin state persistence using data api
This commit is contained in:
parent
7f64ee43c9
commit
74608ed27c
18
script.lua
18
script.lua
@ -5,8 +5,18 @@ TEXTURE_WIDTH = 128
|
|||||||
TEXTURE_HEIGHT = 128
|
TEXTURE_HEIGHT = 128
|
||||||
|
|
||||||
-- local state variables (do not access within pings) --
|
-- local state variables (do not access within pings) --
|
||||||
armor_enabled=true
|
armor_enabled=data.load("armor_enabled")
|
||||||
vanilla_enabled=false
|
if armor_enabled==nil then
|
||||||
|
armor_enabled=true
|
||||||
|
else
|
||||||
|
armor_enabled=armor_enabled=="true"
|
||||||
|
end
|
||||||
|
vanilla_enabled=data.load("vanilla_enabled")
|
||||||
|
if vanilla_enabled==nil then
|
||||||
|
vanilla_enabled=false
|
||||||
|
else
|
||||||
|
vanilla_enabled=vanilla_enabled=="true"
|
||||||
|
end
|
||||||
|
|
||||||
-- utility functions -- {{{
|
-- utility functions -- {{{
|
||||||
--- dump table --
|
--- dump table --
|
||||||
@ -128,6 +138,7 @@ function setArmor(state)
|
|||||||
else
|
else
|
||||||
armor_enabled=state
|
armor_enabled=state
|
||||||
end
|
end
|
||||||
|
data.save("armor_enabled", armor_enabled)
|
||||||
ping.setArmor(armor_enabled)
|
ping.setArmor(armor_enabled)
|
||||||
end
|
end
|
||||||
function ping.setArmor(state)
|
function ping.setArmor(state)
|
||||||
@ -139,6 +150,7 @@ end
|
|||||||
|
|
||||||
function syncState()
|
function syncState()
|
||||||
ping.setArmor(armor_enabled)
|
ping.setArmor(armor_enabled)
|
||||||
|
ping.setVanilla(vanilla_enabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Toggle Vanilla ---
|
--- Toggle Vanilla ---
|
||||||
@ -148,6 +160,7 @@ function setVanilla(state)
|
|||||||
else
|
else
|
||||||
vanilla_enabled=state
|
vanilla_enabled=state
|
||||||
end
|
end
|
||||||
|
data.save("vanilla_enabled", vanilla_enabled)
|
||||||
ping.setVanilla(vanilla_enabled)
|
ping.setVanilla(vanilla_enabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -203,6 +216,7 @@ end
|
|||||||
-- initialize values --
|
-- initialize values --
|
||||||
function player_init()
|
function player_init()
|
||||||
old_health=player.getHealth()
|
old_health=player.getHealth()
|
||||||
|
syncState()
|
||||||
end
|
end
|
||||||
-- Initial configuration --
|
-- Initial configuration --
|
||||||
if meta.getCanModifyVanilla() then
|
if meta.getCanModifyVanilla() then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user