Compare commits

..

No commits in common. "408f83242b94189c27edd9daef47fd22c0dcd772" and "09adab0b359c4e5c30b97ad27a157062811067a4" have entirely different histories.

2 changed files with 125 additions and 67 deletions

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

View File

@ -23,24 +23,34 @@ UVManager=require("nulllib.UVManager")
sharedstate=require("nulllib.sharedstate")
sharedconfig=require("nulllib.sharedconfig")
-- shortcuts for /figura run so i don't have to type so much
C={}
-- math functions
lerp=math.lerp -- this is implemented in figura now
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
-- HELL YEAH TIME TO DEPRECATE THIS BITCH!!!
-- syncState {{{
do
local counter=0
---@deprecated use sharedstate instead
function syncState()
-- 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
local pm_refresh=false
function pmRefresh()
@ -54,11 +64,24 @@ do
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
-- Master configuration -- {{{
-- Master and local state variables -- {{{
-- 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) --
do
local is_host=host:isHost()
@ -73,28 +96,58 @@ do
["aquatic_override"]=false
}
sharedconfig.load_defaults(defaults)
end
local function printSettings()
print("Settings:")
printTable(sharedconfig.load())
end
if sharedconfig.load("print_settings") then
printSettings()
end
--- Convenience, manipulate settings
---@param key? string Key to access
---@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))
---@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
printSettings()
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
function printSettings()
print("Settings:")
for k, v in pairs(skin_state) do
print(tostring(k)..": "..tostring(v))
end
end
if skin_state.print_settings==true then
printSettings()
end
function setState(name, state)
if state == nil then
skin_state[name]=not skin_state[name]
else
skin_state[name]=state
end
-- TODO
-- data.save(name, skin_state[name])
end
-- }}}
-- Parts, groups, other constants -- {{{
@ -195,15 +248,15 @@ do
end
local function vanillaPartial()
if sharedconfig.load("vanilla_enabled") then
if local_state.vanilla_enabled then
return false
end
return sharedconfig.load("vanilla_partial")
return local_state.vanilla_partial
end
local function forceVanilla()
print(vanilla_model.PLAYER:getVisible())
return not avatar:canEditVanillaModel() or sharedconfig.load("vanilla_enabled") or vanilla_model.PLAYER:getVisible()
return not avatar:canEditVanillaModel() or local_state.vanilla_enabled or vanilla_model.PLAYER:getVisible()
end
-- eventually replace this with an instance once PartsManager becomes a class
@ -212,7 +265,7 @@ do
--- Vanilla state
-- no cape if tail enabled (it clips)
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)
PM.addPartFunction(vanilla_model.CAPE, function(last) return last and not local_state.tail_enabled end)
--- Custom state
-- local tail_parts=util.mergeTable({model.Body.TailBase}, TAIL_BONES)
@ -223,10 +276,10 @@ do
-- local vanilla_partial_enabled={model.Head, model.Body}
-- Show shattered only at low health
PM.addPartFunction(SHATTER, function(last) return last and sharedstate.get("health") <= 5 end)
PM.addPartFunction(SHATTER, function(last) return last and local_state.health <= 5 end)
-- Enable tail setting
PM.addPartFunction(model.Body_Tail, function(last) return last and sharedconfig.load("tail_enabled") end)
PM.addPartFunction(model.Body_Tail, function(last) return last and local_state.tail_enabled end)
-- 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}
PM.addPartGroupFunction(mtail_mutually_exclusive, function(last) return last and not aquaticTailVisible() end)
@ -235,7 +288,7 @@ do
--- Armor state
local all_armor=util.reduce(util.mergeTable, {VANILLA_GROUPS.ARMOR, TAIL_LEGGINGS, TAIL_BOOTS})
PM.addPartGroupFunction(all_armor, function(last) return last and sharedconfig.load("armor_enabled") end)
PM.addPartGroupFunction(all_armor, function(last) return last and local_state.armor_enabled end)
-- 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.LeatherBoot, function(last) return last and armor_state.leather_boots end)
@ -360,7 +413,8 @@ end
--- Toggle Armor ---
function setArmor(state)
sharedconfig.save("armor_enabled", state)
setState("armor_enabled", state)
syncState()
end
local function snore() end
@ -389,14 +443,15 @@ local function snore() end
--- Toggle Vanilla ---
function setVanilla(state)
sharedconfig.save("vanilla_enabled", state)
setState("vanilla_enabled", state)
syncState()
end
function ping.tPose()
logging.debug("ping.tPose")
local_state.emote_vector=player:getPos()
-- TODO
-- local_state.emote_vector=player:getPos()
-- animation.tpose.start()
end
-- }}}
@ -405,11 +460,10 @@ end
local tail_cooldown
function aquaticTailVisible()
tail_cooldown=tail_cooldown or 0
return (sharedconfig.load("aquatic_enabled") and (player:isInWater() or player:isInLava()) or sharedconfig.load("aquatic_override") or tail_cooldown>0) and not getVanillaVisible()
return (local_state.aquatic_enabled and (player:isInWater() or player:isInLava()) or local_state.aquatic_override or tail_cooldown>0) and not getVanillaVisible()
end
local function updateTailVisibility()
local old_state_aquatic_tail_visible
local anim=player:getPose()
local water=player:isInWater()
local lava=player:isInLava()
@ -417,8 +471,8 @@ local function updateTailVisibility()
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)
end
if old_state_aquatic_tail_visible ~= aquaticTailVisible() then pmRefresh() end
old_state_aquatic_tail_visible=aquaticTailVisible()
if old_state.aquaticTailVisible ~= aquaticTailVisible() then pmRefresh() end
old_state.aquaticTailVisible=aquaticTailVisible()
end
-- armor {{{
@ -571,27 +625,27 @@ function animateTail(val)
end
end
STATE.current.anim_tick=0
STATE.current.anim_cycle=0
STATE.old.anim_cycle=0
anim_tick=0
anim_cycle=0
old_state.anim_cycle=0
local function animateTick()
STATE.current.anim_tick = STATE.current.anim_tick + 1
function animateTick()
anim_tick = anim_tick + 1
if aquaticTailVisible() then
local velocity = player:getVelocity()
if aquaticTailVisible() then
STATE.old.anim_cycle=STATE.current.anim_cycle
old_state.anim_cycle=anim_cycle
local player_speed = math.sqrt(velocity.x^2 + velocity.y^2 + velocity.z^2)
local animation=player:getPose()
local factor=(not player:isInWater() and (animation=="FALL_FLYING" or animation=="SPIN_ATTACK")) and 0.5 or 5
STATE.current.anim_cycle=STATE.current.anim_cycle + (player_speed*factor+0.75)
anim_cycle=anim_cycle + (player_speed*factor+0.75)
-- bubble animation would go here but i don't have that (yet)
end
else
STATE.old.anim_cycle=STATE.current.anim_cycle
STATE.current.anim_cycle=STATE.current.anim_cycle+1
old_state.anim_cycle=anim_cycle
anim_cycle=anim_cycle+1
end
end
@ -601,14 +655,8 @@ end
-- initialize values -- {{{
function player_init()
local function health_callback(new, old)
if old > new then
hurt()
end
PartsManager.refreshPart(SHATTER)
end
sharedstate.init("health", player:getHealth(), health_callback)
local_state.health=player:getHealth()
old_state.health=local_state.health
-- TODO possibly reconsider if this should be redone
-- actually it's probably fine, it's jsut here because i forget visibility settings
-- local all_parts=util.recurseModelGroup(model)
@ -616,7 +664,9 @@ function player_init()
-- for k, v in pairs(all_parts) do
-- v:setVisible(nil)
-- end
setLocalState()
pmRefresh()
syncState()
events.ENTITY_INIT:remove("player_init")
end
@ -629,17 +679,23 @@ if avatar:canEditVanillaModel() then
else
model:setVisible(false)
end
STATE.current.anim_tick=0
anim_tick=0
-- }}}
-- Tick function -- {{{
function hostTick()
sharedstate.set("health", player:getHealth())
local_state.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
function tick()
STATE.current.color_check=player:isInLava() ~= (player:getDimensionName()=="minecraft:the_nether")
if STATE.old.color_check~=STATE.current.color_check then
color_check=player:isInLava() ~= (player:getDimensionName()=="minecraft:the_nether")
if old_state.color_check~=color_check then
setColor()
end
-- optimization, only execute these once a second --
@ -653,7 +709,7 @@ function tick()
-- Sync state every 10 seconds
if world.getTimeOfDay() % (20*10) == 0 then
sharedstate.sync()
syncState()
end
end
@ -677,7 +733,9 @@ function tick()
-- Check for queued PartsManager refresh
doPmRefresh()
-- End of tick --
STATE.old.color_check=STATE.current.color_check
old_state.health=player:getHealth()
old_state.color_check=color_check
local_state.anim=player:getPose()
end
events.TICK:register(function() if player then tick() end end, "main_tick")
-- }}}
@ -685,13 +743,13 @@ events.TICK:register(function() if player then tick() end end, "main_tick")
-- Render function {{{
local function render(delta)
if aquaticTailVisible() then
animateMTail((lerp(STATE.old.anim_cycle, STATE.current.anim_cycle, delta) * 0.2))
animateMTail((lerp(old_state.anim_cycle, anim_cycle, delta) * 0.2))
else
resetAngles(model.Body)
-- resetAngles(vanilla_model.BODY)
-- resetAngles(vanilla_model.JACKET)
-- resetAngles(armor_model.CHESTPLATE)
animateTail((lerp(STATE.old.anim_cycle, STATE.current.anim_cycle, delta)))
animateTail((lerp(old_state.anim_cycle, anim_cycle, delta)))
end
end
-- TODO this may break animation during death