| 1 |
--[[ Copyright (c) 2014 Joseph Sheppard |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
class "IdleSpawnAction" (HumanoidAction) |
| 22 |
|
| 23 |
---@type IdleSpawnAction |
| 24 |
local IdleSpawnAction = _G["IdleSpawnAction"] |
| 25 |
|
| 26 |
function IdleSpawnAction:IdleSpawnAction(anim, point_dir) |
| 27 |
assert(type(anim) == "number", "Invalid value for parameter 'anim'") |
| 28 |
assert(type(point_dir) == "table" and |
| 29 |
type(point_dir.x) == "number" and type(point_dir.y) == "number" and |
| 30 |
point_dir.direction == "north" or point_dir.direction == "south" or |
| 31 |
point_dir.direction == "east" or point_dir.direction == "west", |
| 32 |
"Invalid value for parameter 'point_dir'") |
| 33 |
|
| 34 |
self:HumanoidAction("idle_spawn") |
| 35 |
self.spawn_animation = anim |
| 36 |
self.point = point_dir -- x, y, direction of the spawn animation |
| 37 |
end |
| 38 |
|
| 39 |
local function action_idle_spawn_start(action, humanoid) |
| 40 |
action.must_happen = true |
| 41 |
|
| 42 |
humanoid.last_move_direction = action.point.direction |
| 43 |
humanoid:setTilePositionSpeed(action.point.x,action.point.y) |
| 44 |
|
| 45 |
if action.spawn_animation then |
| 46 |
local loop_callback_spawn =--[[persistable:idle_spawn_animation]] function() |
| 47 |
if action.spawn_sound then humanoid:playSound(action.spawn_sound) end |
| 48 |
humanoid:setAnimation(action.spawn_animation) |
| 49 |
end |
| 50 |
|
| 51 |
humanoid:queueAction(IdleAction() |
| 52 |
:setCount(TheApp.animation_manager:getAnimLength(action.spawn_animation)) |
| 53 |
:setLoopCallback(loop_callback_spawn)) |
| 54 |
|
| 55 |
elseif action.spawn_sound then |
| 56 |
humanoid:playSound(action.spawn_sound) |
| 57 |
end |
| 58 |
|
| 59 |
humanoid:queueAction(IdleAction():setCount(action.count):setLoopCallback(action.loop_callback)) |
| 60 |
humanoid:finishAction() |
| 61 |
end |
| 62 |
|
| 63 |
return action_idle_spawn_start |