Skip to content

Commit

Permalink
Fix enemy:on_restarted() called twice
Browse files Browse the repository at this point in the history
Closes solarus-games#1179.
It was called both when the map started and when the map opening
transition finished.
  • Loading branch information
christopho committed Jul 28, 2018
1 parent 50d7194 commit 3cf7e8c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Engine changes
* Fix hero shield sprite directions in animation sword (#1185).
* Fix facing entity randomly chosen when the hero faces multiple ones (#1042).
* Fix blocks not falling into water or lava (#1214).
* Fix enemy:on_restarted() called twice (#1179).
* Fix removed entity still drawn during scrolling transition (#1193).
* Fix sprite parameters order in custom entity collision callback (#1162).
* Fix sol.file.exists() returning false for directories.
Expand Down
4 changes: 0 additions & 4 deletions src/entities/Enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ void Enemy::notify_created() {
for (const SpritePtr& sprite: get_sprites()) {
sprite->set_current_direction(initial_direction);
}

if (is_enabled()) {
restart();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ set(lua_test_maps
"bugs/1162_custom_entity_collision_wrong_order"
"bugs/1163_circular_movement_get_direction4"
"bugs/1171_sword_knowledge_on_ability_used"
"bugs/1179_enemy_on_restarted_called_twice"
"bugs/1181_hurt_enemy_after_custom_attack"
"bugs/1193_entity_drawn_after_removed/map_1"
"bugs/1195_enemy_dying_animation_never_finishes"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

local enemy = ...
local game = enemy:get_game()

local count = 0

function enemy:on_restarted()

count = count + 1
end

function enemy:get_on_restarted_count()
return count
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
properties{
x = 0,
y = 0,
width = 320,
height = 240,
min_layer = 0,
max_layer = 2,
tileset = "castle",
}

tile{
layer = 0,
x = 0,
y = 0,
width = 320,
height = 240,
pattern = "3",
}

enemy{
name = "enemy",
layer = 0,
x = 24,
y = 61,
direction = 0,
breed = "bugs/1179_on_restarted_called_twice",
}

destination{
name = "destination",
layer = 0,
x = 24,
y = 29,
direction = 1,
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local map = ...
local game = map:get_game()

function map:on_opening_transition_finished()

sol.timer.start(map, 100, function()
assert_equal(enemy:get_on_restarted_count(), 1)
sol.main.exit()
end)
end
2 changes: 2 additions & 0 deletions tests/testing_quest/data/project_db.dat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ map{ id = "bugs/1158_entity_timer_suspended", description = "#1158: timer:set_su
map{ id = "bugs/1162_custom_entity_collision_wrong_order", description = "#1162: Wrong sprite order in custom entity collision callback" }
map{ id = "bugs/1163_circular_movement_get_direction4", description = "#1163: circular_movement:get_direction4() not working" }
map{ id = "bugs/1171_sword_knowledge_on_ability_used", description = "#1171: Fix item:on_ability_used() not called with sword knowledge" }
map{ id = "bugs/1179_enemy_on_restarted_called_twice", description = "#1179: enemy:on_restarted() is called twice" }
map{ id = "bugs/1181_hurt_enemy_after_custom_attack", description = "#1181: enemy:hurt() does not work after a custom attack" }
map{ id = "bugs/1193_entity_drawn_after_removed/map_1", description = "#1193: Entity still drawn after removed" }
map{ id = "bugs/1193_entity_drawn_after_removed/map_2", description = "Destination map" }
Expand Down Expand Up @@ -278,6 +279,7 @@ item{ id = "item_no_dialog_sprite", description = "Item with no dialog and a spr
item{ id = "non_saved_item", description = "Non-saved item" }
item{ id = "sword", description = "Sword" }

enemy{ id = "bugs/1179_on_restarted_called_twice", description = "#1179: enemy:on_restarted() is called twice" }
enemy{ id = "slime_green", description = "Green Slime" }
enemy{ id = "test_enemy", description = "Test enemy" }
enemy{ id = "test_flying_enemy", description = "Flying enemy" }
Expand Down

0 comments on commit 3cf7e8c

Please sign in to comment.