Stop using deprecated code
This commit is contained in:
parent
02cd7e6ea1
commit
8abdc839be
111
script.lua
111
script.lua
@ -27,6 +27,16 @@ sharedconfig=require("nulllib.sharedconfig")
|
|||||||
lerp=math.lerp -- this is implemented in figura now
|
lerp=math.lerp -- this is implemented in figura now
|
||||||
wave=nmath.wave
|
wave=nmath.wave
|
||||||
|
|
||||||
|
-- for global state tracking, post syncState era
|
||||||
|
-- this isn't entirely necessary but it's good to know what has and hasn't been
|
||||||
|
-- migrated yet. I should probably rewrite stuff that uses it, but most of it
|
||||||
|
-- isn't nearly as bad as the old syncState/setLocalState/etc. It's currently
|
||||||
|
-- only used for a somewhat scattered color check funciton.
|
||||||
|
STATE={
|
||||||
|
["current"]={},
|
||||||
|
["old"]={}
|
||||||
|
}
|
||||||
|
|
||||||
-- this is too horrifying to put into nulllib for now
|
-- this is too horrifying to put into nulllib for now
|
||||||
-- HELL YEAH TIME TO DEPRECATE THIS BITCH!!!
|
-- HELL YEAH TIME TO DEPRECATE THIS BITCH!!!
|
||||||
-- syncState {{{
|
-- syncState {{{
|
||||||
@ -35,6 +45,8 @@ do
|
|||||||
|
|
||||||
---@deprecated use sharedstate instead
|
---@deprecated use sharedstate instead
|
||||||
function syncState()
|
function syncState()
|
||||||
|
logging.warn([[Call to deprecated function syncState()
|
||||||
|
]] .. util.traceback())
|
||||||
-- ping.setSnoring(skin_state.snore_enabled)
|
-- ping.setSnoring(skin_state.snore_enabled)
|
||||||
if counter < 3 then
|
if counter < 3 then
|
||||||
ping.syncState((setLocalState()))
|
ping.syncState((setLocalState()))
|
||||||
@ -67,6 +79,8 @@ end
|
|||||||
|
|
||||||
---@deprecated Use sharedstate instead
|
---@deprecated Use sharedstate instead
|
||||||
function ping.syncState(tbl)
|
function ping.syncState(tbl)
|
||||||
|
logging.warn([[Call to deprecated function pings.syncState()
|
||||||
|
]] .. util.traceback())
|
||||||
logging.debug("ping.syncState")
|
logging.debug("ping.syncState")
|
||||||
for k, v in pairs(tbl) do
|
for k, v in pairs(tbl) do
|
||||||
local_state[k]=v
|
local_state[k]=v
|
||||||
@ -78,10 +92,13 @@ end
|
|||||||
-- so is this
|
-- so is this
|
||||||
-- 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) --
|
||||||
---@deprecated use sharedstate or track internally
|
---@deprecated use sharedstate, sharedconfig, or track internally
|
||||||
local_state={}
|
local_state={}
|
||||||
---@deprecated use sharedstate with callbacks or track internally
|
---@deprecated use sharedstate with callbacks or track internally
|
||||||
old_state={}
|
old_state={}
|
||||||
|
|
||||||
|
---@deprecated use sharedstate, sharedconfig, or track internally
|
||||||
|
skin_state={}
|
||||||
-- master state variables and configuration (do not access within pings) --
|
-- master state variables and configuration (do not access within pings) --
|
||||||
do
|
do
|
||||||
local is_host=host:isHost()
|
local is_host=host:isHost()
|
||||||
@ -99,6 +116,8 @@ do
|
|||||||
|
|
||||||
---@deprecated use config api (TODO) instead
|
---@deprecated use config api (TODO) instead
|
||||||
function setLocalState()
|
function setLocalState()
|
||||||
|
logging.warn([[Call to deprecated function setLocalState()
|
||||||
|
]] .. util.traceback())
|
||||||
if host:isHost() then
|
if host:isHost() then
|
||||||
for k, v in pairs(skin_state) do
|
for k, v in pairs(skin_state) do
|
||||||
local_state[k]=v
|
local_state[k]=v
|
||||||
@ -130,14 +149,13 @@ 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
|
||||||
|
|
||||||
|
---@deprecated use sharedconfig
|
||||||
function setState(name, state)
|
function setState(name, state)
|
||||||
if state == nil then
|
if state == nil then
|
||||||
skin_state[name]=not skin_state[name]
|
skin_state[name]=not skin_state[name]
|
||||||
@ -248,15 +266,15 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function vanillaPartial()
|
local function vanillaPartial()
|
||||||
if local_state.vanilla_enabled then
|
if sharedconfig.load("vanilla_enabled") then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return local_state.vanilla_partial
|
return sharedconfig.load("vanilla_partial")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function forceVanilla()
|
local function forceVanilla()
|
||||||
print(vanilla_model.PLAYER:getVisible())
|
print(vanilla_model.PLAYER:getVisible())
|
||||||
return not avatar:canEditVanillaModel() or local_state.vanilla_enabled or vanilla_model.PLAYER:getVisible()
|
return not avatar:canEditVanillaModel() or sharedconfig.load("vanilla_enabled") or vanilla_model.PLAYER:getVisible()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- eventually replace this with an instance once PartsManager becomes a class
|
-- eventually replace this with an instance once PartsManager becomes a class
|
||||||
@ -265,7 +283,7 @@ do
|
|||||||
|
|
||||||
--- Vanilla state
|
--- Vanilla state
|
||||||
-- no cape if tail enabled (it clips)
|
-- no cape if tail enabled (it clips)
|
||||||
PM.addPartFunction(vanilla_model.CAPE, function(last) return last and not local_state.tail_enabled end)
|
PM.addPartFunction(vanilla_model.CAPE, function(last) logging.trace("pm tail enabled func", sharedconfig.load("tail_enabled")) return last and not sharedconfig.load("tail_enabled") end)
|
||||||
|
|
||||||
--- Custom state
|
--- Custom state
|
||||||
-- local tail_parts=util.mergeTable({model.Body.TailBase}, TAIL_BONES)
|
-- local tail_parts=util.mergeTable({model.Body.TailBase}, TAIL_BONES)
|
||||||
@ -276,10 +294,10 @@ do
|
|||||||
-- local vanilla_partial_enabled={model.Head, model.Body}
|
-- local vanilla_partial_enabled={model.Head, model.Body}
|
||||||
|
|
||||||
-- Show shattered only at low health
|
-- Show shattered only at low health
|
||||||
PM.addPartFunction(SHATTER, function(last) return last and local_state.health <= 5 end)
|
PM.addPartFunction(SHATTER, function(last) return last and sharedstate.get("health") <= 5 end)
|
||||||
|
|
||||||
-- Enable tail setting
|
-- Enable tail setting
|
||||||
PM.addPartFunction(model.Body_Tail, function(last) return last and local_state.tail_enabled end)
|
PM.addPartFunction(model.Body_Tail, function(last) return last and sharedconfig.load("tail_enabled") end)
|
||||||
-- no legs, regular tail in water if tail enabled
|
-- no legs, regular tail in water if tail enabled
|
||||||
local mtail_mutually_exclusive={model.LeftLeg, model.RightLeg, model.Body_Tail, armor_model.LEGGINGS, armor_model.BOOTS}
|
local mtail_mutually_exclusive={model.LeftLeg, model.RightLeg, model.Body_Tail, armor_model.LEGGINGS, armor_model.BOOTS}
|
||||||
PM.addPartGroupFunction(mtail_mutually_exclusive, function(last) return last and not aquaticTailVisible() end)
|
PM.addPartGroupFunction(mtail_mutually_exclusive, function(last) return last and not aquaticTailVisible() end)
|
||||||
@ -288,7 +306,7 @@ do
|
|||||||
|
|
||||||
--- Armor state
|
--- Armor state
|
||||||
local all_armor=util.reduce(util.mergeTable, {VANILLA_GROUPS.ARMOR, TAIL_LEGGINGS, TAIL_BOOTS})
|
local all_armor=util.reduce(util.mergeTable, {VANILLA_GROUPS.ARMOR, TAIL_LEGGINGS, TAIL_BOOTS})
|
||||||
PM.addPartGroupFunction(all_armor, function(last) return last and local_state.armor_enabled end)
|
PM.addPartGroupFunction(all_armor, function(last) return last and sharedconfig.load("armor_enabled") end)
|
||||||
-- Only show armor if equipped
|
-- Only show armor if equipped
|
||||||
PM.addPartFunction(model.Body.MTail1.MTail2.MTail3.Boot, function(last) return last and armor_state.boots end)
|
PM.addPartFunction(model.Body.MTail1.MTail2.MTail3.Boot, function(last) return last and armor_state.boots end)
|
||||||
PM.addPartFunction(model.Body.MTail1.MTail2.MTail3.LeatherBoot, function(last) return last and armor_state.leather_boots end)
|
PM.addPartFunction(model.Body.MTail1.MTail2.MTail3.LeatherBoot, function(last) return last and armor_state.leather_boots end)
|
||||||
@ -413,8 +431,7 @@ end
|
|||||||
|
|
||||||
--- Toggle Armor ---
|
--- Toggle Armor ---
|
||||||
function setArmor(state)
|
function setArmor(state)
|
||||||
setState("armor_enabled", state)
|
sharedconfig.save("armor_enabled", state)
|
||||||
syncState()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function snore() end
|
local function snore() end
|
||||||
@ -443,15 +460,14 @@ local function snore() end
|
|||||||
|
|
||||||
--- Toggle Vanilla ---
|
--- Toggle Vanilla ---
|
||||||
function setVanilla(state)
|
function setVanilla(state)
|
||||||
setState("vanilla_enabled", state)
|
sharedconfig.save("vanilla_enabled", state)
|
||||||
syncState()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function ping.tPose()
|
function ping.tPose()
|
||||||
logging.debug("ping.tPose")
|
logging.debug("ping.tPose")
|
||||||
local_state.emote_vector=player:getPos()
|
|
||||||
-- TODO
|
-- TODO
|
||||||
|
-- local_state.emote_vector=player:getPos()
|
||||||
-- animation.tpose.start()
|
-- animation.tpose.start()
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
@ -460,10 +476,11 @@ end
|
|||||||
local tail_cooldown
|
local tail_cooldown
|
||||||
function aquaticTailVisible()
|
function aquaticTailVisible()
|
||||||
tail_cooldown=tail_cooldown or 0
|
tail_cooldown=tail_cooldown or 0
|
||||||
return (local_state.aquatic_enabled and (player:isInWater() or player:isInLava()) or local_state.aquatic_override or tail_cooldown>0) and not getVanillaVisible()
|
return (sharedconfig.load("aquatic_enabled") and (player:isInWater() or player:isInLava()) or sharedconfig.load("aquatic_override") or tail_cooldown>0) and not getVanillaVisible()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateTailVisibility()
|
local function updateTailVisibility()
|
||||||
|
local old_state_aquatic_tail_visible
|
||||||
local anim=player:getPose()
|
local anim=player:getPose()
|
||||||
local water=player:isInWater()
|
local water=player:isInWater()
|
||||||
local lava=player:isInLava()
|
local lava=player:isInLava()
|
||||||
@ -471,8 +488,8 @@ local function updateTailVisibility()
|
|||||||
if aquaticTailVisible() and (anim=="SLEEPING" or anim=="SPIN_ATTACK" or anim=="FALL_FLYING" or water or lava) then
|
if aquaticTailVisible() and (anim=="SLEEPING" or anim=="SPIN_ATTACK" or anim=="FALL_FLYING" or water or lava) then
|
||||||
tail_cooldown=anim=="SPIN_ATTACK" and 60 or (tail_cooldown >= 10 and tail_cooldown or 10)
|
tail_cooldown=anim=="SPIN_ATTACK" and 60 or (tail_cooldown >= 10 and tail_cooldown or 10)
|
||||||
end
|
end
|
||||||
if old_state.aquaticTailVisible ~= aquaticTailVisible() then pmRefresh() end
|
if old_state_aquatic_tail_visible ~= aquaticTailVisible() then pmRefresh() end
|
||||||
old_state.aquaticTailVisible=aquaticTailVisible()
|
old_state_aquatic_tail_visible=aquaticTailVisible()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- armor {{{
|
-- armor {{{
|
||||||
@ -625,27 +642,27 @@ function animateTail(val)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
anim_tick=0
|
STATE.current.anim_tick=0
|
||||||
anim_cycle=0
|
STATE.current.anim_cycle=0
|
||||||
old_state.anim_cycle=0
|
STATE.old.anim_cycle=0
|
||||||
|
|
||||||
function animateTick()
|
local function animateTick()
|
||||||
anim_tick = anim_tick + 1
|
STATE.current.anim_tick = STATE.current.anim_tick + 1
|
||||||
if aquaticTailVisible() then
|
if aquaticTailVisible() then
|
||||||
local velocity = player:getVelocity()
|
local velocity = player:getVelocity()
|
||||||
|
|
||||||
if aquaticTailVisible() then
|
if aquaticTailVisible() then
|
||||||
old_state.anim_cycle=anim_cycle
|
STATE.old.anim_cycle=STATE.current.anim_cycle
|
||||||
local player_speed = math.sqrt(velocity.x^2 + velocity.y^2 + velocity.z^2)
|
local player_speed = math.sqrt(velocity.x^2 + velocity.y^2 + velocity.z^2)
|
||||||
local animation=player:getPose()
|
local animation=player:getPose()
|
||||||
local factor=(not player:isInWater() and (animation=="FALL_FLYING" or animation=="SPIN_ATTACK")) and 0.5 or 5
|
local factor=(not player:isInWater() and (animation=="FALL_FLYING" or animation=="SPIN_ATTACK")) and 0.5 or 5
|
||||||
anim_cycle=anim_cycle + (player_speed*factor+0.75)
|
STATE.current.anim_cycle=STATE.current.anim_cycle + (player_speed*factor+0.75)
|
||||||
-- bubble animation would go here but i don't have that (yet)
|
-- bubble animation would go here but i don't have that (yet)
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
old_state.anim_cycle=anim_cycle
|
STATE.old.anim_cycle=STATE.current.anim_cycle
|
||||||
anim_cycle=anim_cycle+1
|
STATE.current.anim_cycle=STATE.current.anim_cycle+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -655,8 +672,14 @@ end
|
|||||||
|
|
||||||
-- initialize values -- {{{
|
-- initialize values -- {{{
|
||||||
function player_init()
|
function player_init()
|
||||||
local_state.health=player:getHealth()
|
local function health_callback(new, old)
|
||||||
old_state.health=local_state.health
|
if old > new then
|
||||||
|
hurt()
|
||||||
|
end
|
||||||
|
PartsManager.refreshPart(SHATTER)
|
||||||
|
end
|
||||||
|
|
||||||
|
sharedstate.init("health", player:getHealth(), health_callback)
|
||||||
-- TODO possibly reconsider if this should be redone
|
-- TODO possibly reconsider if this should be redone
|
||||||
-- actually it's probably fine, it's jsut here because i forget visibility settings
|
-- actually it's probably fine, it's jsut here because i forget visibility settings
|
||||||
-- local all_parts=util.recurseModelGroup(model)
|
-- local all_parts=util.recurseModelGroup(model)
|
||||||
@ -664,9 +687,7 @@ function player_init()
|
|||||||
-- for k, v in pairs(all_parts) do
|
-- for k, v in pairs(all_parts) do
|
||||||
-- v:setVisible(nil)
|
-- v:setVisible(nil)
|
||||||
-- end
|
-- end
|
||||||
setLocalState()
|
|
||||||
pmRefresh()
|
pmRefresh()
|
||||||
syncState()
|
|
||||||
events.ENTITY_INIT:remove("player_init")
|
events.ENTITY_INIT:remove("player_init")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -679,23 +700,17 @@ if avatar:canEditVanillaModel() then
|
|||||||
else
|
else
|
||||||
model:setVisible(false)
|
model:setVisible(false)
|
||||||
end
|
end
|
||||||
anim_tick=0
|
STATE.current.anim_tick=0
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- Tick function -- {{{
|
-- Tick function -- {{{
|
||||||
function hostTick()
|
function hostTick()
|
||||||
local_state.health=player:getHealth()
|
sharedstate.set("health", player:getHealth())
|
||||||
if local_state.health ~= old_state.health then
|
|
||||||
if local_state.health < old_state.health then
|
|
||||||
ping.oof(local_state.health)
|
|
||||||
end
|
|
||||||
syncState()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function tick()
|
function tick()
|
||||||
color_check=player:isInLava() ~= (player:getDimensionName()=="minecraft:the_nether")
|
STATE.current.color_check=player:isInLava() ~= (player:getDimensionName()=="minecraft:the_nether")
|
||||||
if old_state.color_check~=color_check then
|
if STATE.old.color_check~=STATE.current.color_check then
|
||||||
setColor()
|
setColor()
|
||||||
end
|
end
|
||||||
-- optimization, only execute these once a second --
|
-- optimization, only execute these once a second --
|
||||||
@ -709,7 +724,7 @@ function tick()
|
|||||||
|
|
||||||
-- Sync state every 10 seconds
|
-- Sync state every 10 seconds
|
||||||
if world.getTimeOfDay() % (20*10) == 0 then
|
if world.getTimeOfDay() % (20*10) == 0 then
|
||||||
syncState()
|
sharedstate.sync()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -733,9 +748,7 @@ function tick()
|
|||||||
-- Check for queued PartsManager refresh
|
-- Check for queued PartsManager refresh
|
||||||
doPmRefresh()
|
doPmRefresh()
|
||||||
-- End of tick --
|
-- End of tick --
|
||||||
old_state.health=player:getHealth()
|
STATE.old.color_check=STATE.current.color_check
|
||||||
old_state.color_check=color_check
|
|
||||||
local_state.anim=player:getPose()
|
|
||||||
end
|
end
|
||||||
events.TICK:register(function() if player then tick() end end, "main_tick")
|
events.TICK:register(function() if player then tick() end end, "main_tick")
|
||||||
-- }}}
|
-- }}}
|
||||||
@ -743,13 +756,13 @@ events.TICK:register(function() if player then tick() end end, "main_tick")
|
|||||||
-- Render function {{{
|
-- Render function {{{
|
||||||
local function render(delta)
|
local function render(delta)
|
||||||
if aquaticTailVisible() then
|
if aquaticTailVisible() then
|
||||||
animateMTail((lerp(old_state.anim_cycle, anim_cycle, delta) * 0.2))
|
animateMTail((lerp(STATE.old.anim_cycle, STATE.current.anim_cycle, delta) * 0.2))
|
||||||
else
|
else
|
||||||
resetAngles(model.Body)
|
resetAngles(model.Body)
|
||||||
-- resetAngles(vanilla_model.BODY)
|
-- resetAngles(vanilla_model.BODY)
|
||||||
-- resetAngles(vanilla_model.JACKET)
|
-- resetAngles(vanilla_model.JACKET)
|
||||||
-- resetAngles(armor_model.CHESTPLATE)
|
-- resetAngles(armor_model.CHESTPLATE)
|
||||||
animateTail((lerp(old_state.anim_cycle, anim_cycle, delta)))
|
animateTail((lerp(STATE.old.anim_cycle, STATE.current.anim_cycle, delta)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- TODO this may break animation during death
|
-- TODO this may break animation during death
|
||||||
|
Loading…
x
Reference in New Issue
Block a user