Skip to content

Instantly share code, notes, and snippets.

@zulman
Created May 31, 2024 14:15
Show Gist options
  • Save zulman/94590fcd4269dd0619d6b29ab50fb230 to your computer and use it in GitHub Desktop.
Save zulman/94590fcd4269dd0619d6b29ab50fb230 to your computer and use it in GitHub Desktop.
function M.create_dropping_callback(mob)
local mob = mob
return function(targetX, targetY)
local mob_tile_x, mob_tile_y = collision_utils.posToTiles(mob.pos)
local animation_suffix = distingushSide(mob_tile_x, mob_tile_y, targetX, targetY)
local is_left = animation_suffix == "left"
local animation_name = "grab_" .. animation_suffix
local is_failed = false
return function ()
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(mob), mob) then
mob.afkTimer = 1
showError(mob)
mob.execResult = false
end
end
end)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment