Skip to content

Commit

Permalink
Fix for EasyRPG#1229
Browse files Browse the repository at this point in the history
  • Loading branch information
rohkea committed Oct 9, 2017
1 parent 0f33f3e commit d250f13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/window_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Headers
#include <cctype>
#include <sstream>
#include <iterator>

#include "window_message.h"
#include "game_actors.h"
Expand Down Expand Up @@ -84,6 +85,7 @@ void Window_Message::ApplyTextInsertingCommands() {

// Contains already substitued \N actors to prevent endless recursion
std::vector<int> replaced_actors;
int actor_replacement_start = std::distance(text.begin(), end);

if (!text.empty()) {
// Move on first valid char
Expand All @@ -105,13 +107,20 @@ void Window_Message::ApplyTextInsertingCommands() {
bool success;
int parsed_num;
std::u32string command_result = Utils::DecodeUTF32(ParseCommandCode(success, parsed_num));
if (start_code < text.begin() + actor_replacement_start) {
replaced_actors.clear();
}

if (!success || std::find(replaced_actors.begin(), replaced_actors.end(), parsed_num) != replaced_actors.end()) {
text_index = start_code - 2;
continue;
}

if (ch == 'n') {
replaced_actors.push_back(parsed_num);
if (text.begin() + actor_replacement_start >= text_index - 1) {
actor_replacement_start = std::distance(text.begin(), text_index - 1);
}
}

text.replace(start_code, text_index + 1, command_result);
Expand Down

0 comments on commit d250f13

Please sign in to comment.