Fix compatibility with Figura 0.1.0-rc8

- change player:exists() to player (nil if player doesn't exist)
- re-enable edit permission checks (meta.getCanModifyVanilla() ->
  avatar.canEditVanillaModel)
- resetVisible() -> setVisible(nil)
- fix init event register
This commit is contained in:
NullBite 2022-09-26 01:11:48 -04:00
parent ef6b307c0e
commit fa11b3a3f6
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A

View File

@ -214,35 +214,6 @@ function recurseModelGroup(group)
end end
-- }}} -- }}}
-- Model switcher (credit to dragekk#7300) {{{
-- TODO: determine if needs removed for rewrite
-- Note: use host:sendChatMessage("/figura load <whatever>")
-- Note: no way to upload avatar yet
function switch_model(path)
if avatar then
if not avatar.isLocal() then
local name = data.getName()
data.setName("avatar_switch")
data.save("upload", "yes")
data.setName(name)
end
avatar.set(path)
end
end
if avatar then
local name = data.getName()
data.setName("avatar_switch")
local loaded = data.load("upload")
if loaded == "yes" then
data.save("upload", "no")
data.setName(name)
avatar.uploadToBackend()
else
data.setName(name)
end
end
-- }}}
-- Timer (not mine lol) -- {{{ -- Timer (not mine lol) -- {{{
-- TODO investigate if events can replace some of this -- TODO investigate if events can replace some of this
do do
@ -259,7 +230,7 @@ do
end end
end end
events.TICK:register(function() if player:exists() then tick() end end, "timer") events.TICK:register(function() if player then tick() end end, "timer")
end end
-- named timers (this one is mine but heavily based on the other) -- -- named timers (this one is mine but heavily based on the other) --
@ -279,7 +250,7 @@ do
end end
end end
end end
events.TICK:register(function() if player:exists() then tick() end end, "named_timer") events.TICK:register(function() if player then tick() end end, "named_timer")
end end
-- named cooldowns -- named cooldowns
@ -299,7 +270,7 @@ do
end end
end end
end end
events.TICK:register(function() if player:exists() then tick() end end, "cooldown") events.TICK:register(function() if player then tick() end end, "cooldown")
end end
function rateLimit(ticks, next, name) function rateLimit(ticks, next, name)
@ -730,8 +701,7 @@ end
do do
-- TODO -- TODO
-- local can_modify_vanilla=meta.getCanModifyVanilla() local can_modify_vanilla=avatar.canEditVanillaModel
local can_modify_vanilla=true
local function vanillaPartial() local function vanillaPartial()
if local_state.vanilla_enabled then if local_state.vanilla_enabled then
@ -1140,26 +1110,22 @@ function player_init()
local all_parts=recurseModelGroup(model) local all_parts=recurseModelGroup(model)
for k, v in pairs(all_parts) do for k, v in pairs(all_parts) do
v:resetVisible(true) v:setVisible(nil)
end end
setLocalState() setLocalState()
pmRefresh() pmRefresh()
syncState() syncState()
events.ENTITY_INIT:remove("player_init")
end end
events:runOnce(function() return player:exists() end, player_init) events.ENTITY_INIT:register(function() return player_init() end, "player_init")
-- Initial configuration -- -- Initial configuration --
-- TODO x2 fix below, this entire block may not be needed with PartsManager -- TODO x2 fix below, this entire block may not be needed with PartsManager
-- if meta.getCanModifyVanilla() then if avatar.canEditVanillaModel then
if true then vanilla_model.PLAYER:setVisible(false)
for key, value in pairs(vanilla_model) do
value:setVisible(false)
end
else else
for _, v in pairs(model) do model:setVisible(false)
v:setVisible(false)
end
end end
anim_tick=0 anim_tick=0
-- }}} -- }}}
@ -1218,7 +1184,7 @@ function tick()
old_state.color_check=color_check old_state.color_check=color_check
local_state.anim=player:getPose() local_state.anim=player:getPose()
end end
events.TICK:register(function() if player:exists() then tick() end end, "main_tick") events.TICK:register(function() if player then tick() end end, "main_tick")
-- }}} -- }}}
-- Render function {{{ -- Render function {{{
@ -1234,5 +1200,5 @@ function render(delta)
end end
end end
-- TODO this may break animation during death -- TODO this may break animation during death
events.RENDER:register(function(delta) if player:exists() then render(delta) end end, "main_render") events.RENDER:register(function(delta) if player then render(delta) end end, "main_render")
-- }}} -- }}}