Skip to content

Commit

Permalink
Clone/DestroyMapEvent: Silence warning when deletion fails while cloning
Browse files Browse the repository at this point in the history
Add documentation
  • Loading branch information
Ghabry committed Sep 5, 2024
1 parent 004fdd1 commit 4843ce2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ bool Game_Map::CloneMapEvent(int src_map_id, int src_event_id, int target_x, int

lcf::rpg::Event new_event = *source_event;
if (target_event_id > 0) {
DestroyMapEvent(target_event_id, false);
DestroyMapEvent(target_event_id, true);
new_event.ID = target_event_id;
} else {
new_event.ID = GetNextAvailableEventId();
Expand Down Expand Up @@ -465,11 +465,13 @@ bool Game_Map::CloneMapEvent(int src_map_id, int src_event_id, int target_x, int
return true;
}

bool Game_Map::DestroyMapEvent(const int event_id, bool update_references) {
bool Game_Map::DestroyMapEvent(const int event_id, bool from_clone) {
const lcf::rpg::Event* event = FindEventById(map->events, event_id);

if (event == nullptr) {
Output::Warning("DestroyMapEvent: Event ID {} not found on current map", event_id);
if (!from_clone) {
Output::Warning("DestroyMapEvent: Event ID {} not found on current map", event_id);
}
return true;
}

Expand All @@ -492,7 +494,7 @@ bool Game_Map::DestroyMapEvent(const int event_id, bool update_references) {
}
}

if (update_references) {
if (!from_clone) {
UpdateUnderlyingEventReferences();

Scene_Map* scene = (Scene_Map*)Scene::Find(Scene::Map).get();
Expand Down
21 changes: 20 additions & 1 deletion src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,27 @@ namespace Game_Map {
/** Disposes Game_Map. */
void Dispose();

/**
* Clones a map event.
*
* @param src_map_id Source map where to clone the event from
* @param src_event_id Source event ID to clone
* @param target_x Where to place the new event (X coordinate)
* @param target_y Where to place the new event (Y coordinate)
* @param target_event_id New event ID. When <= 0 a free ID is selected. When the ID exists the event is overwritten.
* @param target_name New name of the event. When empty the original name is used.
* @return Whether the cloning was successful. It will fail when source map or the src/target event do not exist.
*/
bool CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y, int target_event_id, StringView target_name);
bool DestroyMapEvent(const int event_id, bool update_references = true);

/**
* Deletes a map event.
*
* @param event_id Event ID to delete
* @param from_clone When true this function was invoked by CloneMapEvent. This silences warnings and skips refreshes.
* @return Whether the event was deleted. This will fail when the event does not exist.
*/
bool DestroyMapEvent(const int event_id, bool from_clone = false);

void TranslateMapMessages(int mapId, lcf::rpg::Map& map);
void CreateMapEvents();
Expand Down

0 comments on commit 4843ce2

Please sign in to comment.