Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandTeleport (10810) - Allow com.string as map filename #3208

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ bool Game_Interpreter_Map::CommandTeleport(lcf::rpg::EventCommand const& com) {
int x = com.parameters[1];
int y = com.parameters[2];

if (map_id == 0 && com.string != "") Game_Map::SetCustomMapName(com.string);

// RPG2k3 feature
int direction = -1;
if (com.parameters.size() > 3 && Player::IsRPG2k3Commands()) {
Expand Down
28 changes: 24 additions & 4 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#include "feature.h"

namespace {
std::string custom_map_name = "";

// Intended bad value, Game_Map::Init sets them correctly
int screen_width = -1;
int screen_height = -1;
Expand Down Expand Up @@ -327,6 +329,7 @@ std::unique_ptr<lcf::rpg::Map> Game_Map::loadMapFile(int map_id) {
}

Output::Debug("Loaded Map {}", map_name);
custom_map_name = "";

if (map.get() == NULL) {
Output::ErrorStr(lcf::LcfReader::GetError());
Expand Down Expand Up @@ -1278,7 +1281,18 @@ lcf::rpg::Map const& Game_Map::GetMap() {
}

int Game_Map::GetMapId() {
return Main_Data::game_player->GetMapId();
int map_id = Main_Data::game_player->GetMapId();
return map_id;
}

std::string Game_Map::GetCustomMapName() {
return custom_map_name;
}

void Game_Map::SetCustomMapName(lcf::DBString mapName) {
custom_map_name = mapName.c_str();

return;
}

void Game_Map::PrintPathToMap() {
Expand Down Expand Up @@ -1682,7 +1696,13 @@ int Game_Map::SubstituteUp(int old_id, int new_id) {

std::string Game_Map::ConstructMapName(int map_id, bool is_easyrpg) {
std::stringstream ss;
ss << "Map" << std::setfill('0') << std::setw(4) << map_id;

if (custom_map_name == "") {
ss << "Map" << std::setfill('0') << std::setw(4) << map_id;
} else {
ss << custom_map_name;
}

if (is_easyrpg) {
return Player::fileext_map.MakeFilename(ss.str(), SUFFIX_EMU);
} else {
Expand All @@ -1694,8 +1714,8 @@ FileRequestAsync* Game_Map::RequestMap(int map_id) {
#ifdef EMSCRIPTEN
Player::translation.RequestAndAddMap(map_id);
#endif

return AsyncHandler::RequestFile(Game_Map::ConstructMapName(map_id, false));
auto map_name = Game_Map::ConstructMapName(map_id, false);
return AsyncHandler::RequestFile(map_name);
}

// Parallax
Expand Down
4 changes: 4 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ namespace Game_Map {
*/
int GetMapId();

std::string GetCustomMapName();

void SetCustomMapName(lcf::DBString mapName);

/**
* Outputs the path in the map tree to reach the current map.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Game_Player::PerformTeleport() {
return;
}

if (teleport_target.GetMapId() <= 0) {
if (Game_Map::GetCustomMapName() == "" && teleport_target.GetMapId() <= 0) {
Output::Error("Invalid Teleport map id! mapid={} x={} y={} d={}", teleport_target.GetMapId(),
teleport_target.GetX(), teleport_target.GetY(), teleport_target.GetDirection());
}
Expand Down