Refactor visor expression/damage code
- Scope entire expression change code - Use tables for related values - Make certain variables and functions local
This commit is contained in:
parent
9788f8d231
commit
776de24593
38
script.lua
38
script.lua
@ -3,13 +3,6 @@
|
|||||||
-- Texture dimensions --
|
-- Texture dimensions --
|
||||||
TEXTURE_WIDTH = 128
|
TEXTURE_WIDTH = 128
|
||||||
TEXTURE_HEIGHT = 128
|
TEXTURE_HEIGHT = 128
|
||||||
-- Values for UV mappings --
|
|
||||||
face_damage=0
|
|
||||||
face_expr=0
|
|
||||||
step_u_face=32
|
|
||||||
step_v_face=16
|
|
||||||
offset_u_face=64
|
|
||||||
offset_v_face=0
|
|
||||||
armor_enabled=true
|
armor_enabled=true
|
||||||
vanilla_enabled=true
|
vanilla_enabled=true
|
||||||
|
|
||||||
@ -67,32 +60,39 @@ VANILLA_INNER={
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Expression change -- {{{
|
-- Expression change -- {{{
|
||||||
function getExprUV(damage, expression)
|
do
|
||||||
local u=offset_u_face+(damage*step_u_face)
|
-- Values for UV mappings --
|
||||||
local v=offset_v_face+(expression*step_v_face)
|
expr_current={damage=0, expression=0}
|
||||||
return {u/TEXTURE_WIDTH,v/TEXTURE_HEIGHT}
|
local expr_step={u=32, v=16}
|
||||||
|
local expr_offset={u=64, v=0}
|
||||||
|
|
||||||
|
local function getExprUV(damage, expression)
|
||||||
|
local u=expr_offset.u+(damage*expr_step.u)
|
||||||
|
local v=expr_offset.v+(expression*expr_step.v)
|
||||||
|
return UV{u, v}
|
||||||
end
|
end
|
||||||
function changeExpression(_damage, _expression, ticks)
|
function changeExpression(_damage, _expression, ticks)
|
||||||
-- u is damage, v is expression
|
-- u is damage, v is expression
|
||||||
local damage = _damage
|
local damage = _damage
|
||||||
local expression = _expression
|
local expression = _expression
|
||||||
if damage == nil then
|
if damage == nil then
|
||||||
damage = face_damage
|
damage = expr_current.damage
|
||||||
end
|
end
|
||||||
if expression == nil then
|
if expression == nil then
|
||||||
expression = face_expr
|
expression = expr_current.expression
|
||||||
end
|
end
|
||||||
|
|
||||||
HEAD.setUV(getExprUV(damage,expression))
|
HEAD.setUV(getExprUV(damage,expression))
|
||||||
namedWait(ticks, resetExpression, "resetExpression")
|
namedWait(ticks, resetExpression, "resetExpression")
|
||||||
end
|
end
|
||||||
function setExpression(damage, expression)
|
function setExpression(damage, expression)
|
||||||
face_damage=damage
|
expr_current.damage=damage
|
||||||
face_expr=expression
|
expr_current.expression=expression
|
||||||
HEAD.setUV(getExprUV(damage, expression))
|
HEAD.setUV(getExprUV(damage, expression))
|
||||||
end
|
end
|
||||||
function resetExpression()
|
function resetExpression()
|
||||||
HEAD.setUV(getExprUV(face_damage,face_expr))
|
HEAD.setUV(getExprUV(expr_current.damage,expr_current.expression))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ function tick()
|
|||||||
-- optimization, only execute these once a second --
|
-- optimization, only execute these once a second --
|
||||||
if world.getTimeOfDay() % 20 then
|
if world.getTimeOfDay() % 20 then
|
||||||
-- if face is cracked
|
-- if face is cracked
|
||||||
if face_damage==1 and player.getHealth() > 5 then
|
if expr_current.damage==1 and player.getHealth() > 5 then
|
||||||
ping.healed()
|
ping.healed()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -236,5 +236,9 @@ function onCommand(input)
|
|||||||
v.setEnabled(not v.getEnabled())
|
v.setEnabled(not v.getEnabled())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if input[1] == chat_prefix .. "test_expression" then
|
||||||
|
setExpression(input[2], input[3])
|
||||||
|
print(input[2] .. " " .. input[3])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user