Compare commits

...

4 Commits

Author SHA1 Message Date
408f83242b
Add convenience functions for /figura run 2023-06-25 02:00:48 -04:00
db47bec57e
Remove deprecated functions
thank fuck it is over
2023-06-25 01:59:55 -04:00
8abdc839be
Stop using deprecated code 2023-06-25 01:49:29 -04:00
02cd7e6ea1
Update nulllib 2023-06-25 01:49:21 -04:00
2 changed files with 67 additions and 125 deletions

@ -1 +1 @@
Subproject commit ebd217dcc201b7adf07a0604a2704ef834009161 Subproject commit 8a1d772bb48d6c2b0fdecea59ae102615b489992

View File

@ -23,34 +23,24 @@ UVManager=require("nulllib.UVManager")
sharedstate=require("nulllib.sharedstate") sharedstate=require("nulllib.sharedstate")
sharedconfig=require("nulllib.sharedconfig") sharedconfig=require("nulllib.sharedconfig")
-- shortcuts for /figura run so i don't have to type so much
C={}
-- math functions -- math functions
lerp=math.lerp -- this is implemented in figura now lerp=math.lerp -- this is implemented in figura now
wave=nmath.wave wave=nmath.wave
-- this is too horrifying to put into nulllib for now -- for global state tracking, post syncState era
-- HELL YEAH TIME TO DEPRECATE THIS BITCH!!! -- this isn't entirely necessary but it's good to know what has and hasn't been
-- syncState {{{ -- migrated yet. I should probably rewrite stuff that uses it, but most of it
do -- isn't nearly as bad as the old syncState/setLocalState/etc. It's currently
local counter=0 -- only used for a somewhat scattered color check funciton.
STATE={
---@deprecated use sharedstate instead ["current"]={},
function syncState() ["old"]={}
-- ping.setSnoring(skin_state.snore_enabled) }
if counter < 3 then
ping.syncState((setLocalState()))
counter=counter+1
end
end
local function cooldownDecay()
if counter>0 and world.getTime() % 4 == 0 then
counter = counter - 1
end
end
events.TICK:register(cooldownDecay,"syncStateCooldown")
end
-- (the last remnants of) syncState {{{
do do
local pm_refresh=false local pm_refresh=false
function pmRefresh() function pmRefresh()
@ -64,24 +54,11 @@ do
end end
end end
end end
---@deprecated Use sharedstate instead
function ping.syncState(tbl)
logging.debug("ping.syncState")
for k, v in pairs(tbl) do
local_state[k]=v
end
pmRefresh()
end
-- }}} -- }}}
-- so is this -- so is this
-- Master and local state variables -- {{{ -- Master configuration -- {{{
-- Local State (these are copied by pings at runtime) --
---@deprecated use sharedstate or track internally
local_state={}
---@deprecated use sharedstate with callbacks or track internally
old_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()
@ -96,58 +73,28 @@ do
["aquatic_override"]=false ["aquatic_override"]=false
} }
sharedconfig.load_defaults(defaults) sharedconfig.load_defaults(defaults)
---@deprecated use config api (TODO) instead
function setLocalState()
if host:isHost() 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 host:isHost() then
local savedData=config:load()
if savedData == nil then
for k, v in pairs(defaults) do
config:save(k, v)
end
savedData=config:load()
end
skin_state=util.mergeTable(
util.map(util.parse,config:load()),
defaults)
else
skin_state=defaults
end
setLocalState()
end end
function printSettings() local 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) --- Convenience, manipulate settings
if state == nil then ---@param key? string Key to access
skin_state[name]=not skin_state[name] ---@param value? any Value to set
function C.set(key, value)
if value ~= nil and key ~= nil then
sharedconfig.save(key, value)
elseif key ~= nil then
print(sharedconfig.load(key))
else else
skin_state[name]=state printSettings()
end end
-- TODO
-- data.save(name, skin_state[name])
end end
-- }}} -- }}}
-- Parts, groups, other constants -- {{{ -- Parts, groups, other constants -- {{{
@ -248,15 +195,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 +212,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 +223,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 +235,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 +360,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 +389,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 +405,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 +417,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 +571,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 +601,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 +616,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 +629,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 +653,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 +677,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 +685,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