Skip to content

Commit

Permalink
New Command: 2099 - StoreCommands
Browse files Browse the repository at this point in the history
Store commands inside a Stringvariable.

//$storeCommands "preffix",[evtType_isVar, evtType, evtId_isVar, evtId, evtPage_isVar, evtPage, targetStrVar_isVar, targetStrVar]

// 2099, "@easyrpg_raw", [1,4, 1,5, 1,6, 1,7], 0;
  • Loading branch information
jetrotal committed Dec 22, 2023
1 parent 84db179 commit d5f00c3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/dynrpg_easyrpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "game_dynrpg.h"
#include "game_battle.h"
#include "game_map.h"
#include "constants.h"

namespace DynRpg {
/**
Expand Down
72 changes: 72 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandManiacControlStrings(com);
case Cmd::Maniac_CallCommand:
return CommandManiacCallCommand(com);
case static_cast <Game_Interpreter::Cmd>(2099): //easyrpg_storeCommands
return CommandStoreCommands(com);
default:
return true;
}
Expand Down Expand Up @@ -5061,6 +5063,76 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co
return true;
}

bool Game_Interpreter::CommandStoreCommands(lcf::rpg::EventCommand const& com) {
//$storeCommands "preffix",[evtType_isVar, evtType, evtId_isVar, evtId, evtPage_isVar, evtPage, targetStrVar_isVar, targetStrVar]
// 2099, "@easyrpg_raw", [1,4, 1,5, 1,6, 1,7], 0;

int evtType = ValueOrVariable(com.parameters[0], com.parameters[1]);
int evtId = ValueOrVariable(com.parameters[2], com.parameters[3]);
int evtPage = ValueOrVariable(com.parameters[4], com.parameters[5]);
int targetStrVar = ValueOrVariable(com.parameters[6], com.parameters[7]); // target string variable

std::string textPreffix = com.string.empty() ? "" : ToString(com.string) + " ";

Game_Event* event;
const lcf::rpg::EventPage* page;
Game_CommonEvent* common_event;

if (evtType == 0) { // Map Event
event = static_cast<Game_Event*>(GetCharacter(evtId));
if (!event || evtId == 10001) {
Output::Warning("StoreCommands: Can't read non-existent event {}", evtId);
return true;
}
page = event->GetPage(evtPage);
if (!page) {
Output::Warning("StoreCommands: Can't read non-existent page {} of event {}", evtPage, evtId);
return true;
}
}
else if (evtType == 1) { // Common Event
common_event = lcf::ReaderUtil::GetElement(Game_Map::GetCommonEvents(), evtId);
if (!common_event) {
Output::Warning("StoreCommands: Can't read invalid common event {}", evtId);
return true;
}
}

std::string rawCommand = " ";
Constants constList;

const auto& list = evtType == 1 ? common_event->GetList() : page->event_commands;
int index = 0;

for (size_t i = index; i < list.size(); ++i) {
std::stringstream ss;

for (size_t j = 0; j < list[i].parameters.size(); ++j) {
ss << std::to_string(list[i].parameters[j]);
if (j < list[i].parameters.size() - 1) ss << ", ";
}

std::string inputString = ToString(list[i].string);
for (size_t j = 0; j < inputString.length(); ++j)
if (inputString[j] == '"') {
inputString.insert(j, 1, '"');
++j;
}

std::string preffix(list[i].indent, ' ');
std::string suffix = i < list.size() - 1 ? "\n" : "";

rawCommand += fmt::format("{}${}, \"{}\", [{}], {};{}",
preffix, constList.get("EventCode", std::to_string(list[i].code), 1), inputString, ss.str(), list[i].indent, suffix);
}

Game_Strings::Str_Params str_params = { targetStrVar,0, 0 };
Main_Data::game_strings->Asg(str_params, textPreffix + rawCommand);
//fmt::print(rawCommand);

return true;
}

Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
return Game_Battle::IsBattleRunning()
? Game_Battle::GetInterpreter()
Expand Down
3 changes: 3 additions & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <lcf/rpg/saveeventexecstate.h>
#include <lcf/flag_set.h>
#include "async_op.h"
#include "constants.h"

class Game_Event;
class Game_CommonEvent;
Expand Down Expand Up @@ -289,6 +290,8 @@ class Game_Interpreter
bool CommandManiacControlStrings(lcf::rpg::EventCommand const& com);
bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com);

bool CommandStoreCommands(lcf::rpg::EventCommand const& com);

int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);
lcf::rpg::MoveCommand DecodeMove(lcf::DBArray<int32_t>::const_iterator& it);
Expand Down

0 comments on commit d5f00c3

Please sign in to comment.