-
-
Save zulman/94590fcd4269dd0619d6b29ab50fb230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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