Skip to content

Instantly share code, notes, and snippets.

@zulman
Created May 31, 2024 14:20
Show Gist options
  • Save zulman/5c8f0d4ffd88786239bed4bf6f106d77 to your computer and use it in GitHub Desktop.
Save zulman/5c8f0d4ffd88786239bed4bf6f106d77 to your computer and use it in GitHub Desktop.
-- EXAMPLE NOTE: fantasies about how this might look without currying
-- EXAMPLE NOTE: (probably this can be written more beautifully but at least the context in the form of the robot argument in each call needs to be carried, and you will need to subscribe to something in it too)
-- EXAMPLE NOTE: this would be called before the start of the animation
function M.create_dropping_callback_1(mob)
mob.mob_tile_x, mob.mob_tile_y = collision_utils.posToTiles(mob.pos)
end
-- EXAMPLE NOTE: this during the transition to the "dropping" animation
function M.create_dropping_callback_2(mob, targetX, targetY)
local animation_suffix = distingushSide(mob.mob_tile_x, mob.mob_tile_y, targetX, targetY)
mob.is_left = animation_suffix == "left"
mob.animation_name = "grab_" .. animation_suffix
mob.is_failed = false
end
-- EXAMPLE NOTE: at the moment of the keyframe
function create_dropping_callback_3(mob)
mob.processing = true
spine.play_anim(mob.spine_model_url, randomizeMobsAniamtion(animation_name, mob.animationSuffix, mob.isCargomate), go.PLAYBACK_ONCE_FORWARD, {playback_rate = M.get_speed_multiplier(mob) or 1},
function(self, message_id, message, sender)
local colObj = collision_utils.checkCollision(mob, collision_utils.tilesToPos(targetX, targetY), 32, {M.mobs}, SINGLE)
if message_id == hash("spine_animation_done") then
-- if the animation ends, proceed to the next step
mob.processing = false
elseif colObj then
-- at the keyframe, feed the element to the robot if it is not busy
local element
if is_left then
element = mob.elementsStack.left
mob.elementsStack.left = nil
else
element = mob.elementsStack.right
mob.elementsStack.right = nil
end
M.eatElement(colObj.obj, element, nil, true)
goToNextStep(getCurrentCommand(mob), mob)
else
is_failed = true
mob.processing = false
if not tryToGoOnError(getCurrentCommand```lua
(mob), mob) then
mob.afkTimer = 1
showError(mob)
mob.execResult = false
end
end
end)
-- EXAMPLE NOTE: and here you would somehow wisely clean up the fields
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment