code:
#pragma once
#include "Database/Database.hpp"
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementSwitchONCommand final : IMovementRouteStep {
  MovementSwitchONCommand() = default;
  explicit MovementSwitchONCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~MovementSwitchONCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Switch_ON; }
  int id{1};

  void serializeParameters(nlohmann::ordered_json& out) const override;

  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::Switch) {
      return targetId == id;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      id = newId;
      return true;
    }
    return false;
  }
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementSwitchONCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementThroughOFFCommand final : IMovementRouteStep {
  MovementThroughOFFCommand() = default;
  explicit MovementThroughOFFCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementThroughOFFCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Through_OFF; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementThroughOFFCommand>(*this); }
};

repo_name: Antidote/openrpgeditor

license: mit


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementThroughONCommand final : IMovementRouteStep {
  MovementThroughONCommand() = default;
  explicit MovementThroughONCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementThroughONCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Through_ON; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementThroughONCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTransparentOFFCommand final : IMovementRouteStep {
  MovementTransparentOFFCommand() = default;
  explicit MovementTransparentOFFCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTransparentOFFCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Transparent_OFF; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTransparentOFFCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTransparentONCommand final : IMovementRouteStep {
  MovementTransparentONCommand() = default;
  explicit MovementTransparentONCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTransparentONCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Transparent_ON; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTransparentONCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurn180DegCommand final : IMovementRouteStep {
  MovementTurn180DegCommand() = default;
  explicit MovementTurn180DegCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurn180DegCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_180_deg; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurn180DegCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurn90DegLeftCommand final : IMovementRouteStep {
  MovementTurn90DegLeftCommand() = default;
  explicit MovementTurn90DegLeftCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurn90DegLeftCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_90_deg_Left; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurn90DegLeftCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurn90DegLeftOrRightCommand final : IMovementRouteStep {
  MovementTurn90DegLeftOrRightCommand() = default;
  explicit MovementTurn90DegLeftOrRightCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurn90DegLeftOrRightCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_90_deg_Left_or_Right; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurn90DegLeftOrRightCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurn90DegRightCommand final : IMovementRouteStep {
  MovementTurn90DegRightCommand() = default;
  explicit MovementTurn90DegRightCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurn90DegRightCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_90_deg_Right; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurn90DegRightCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnAtRandomCommand final : IMovementRouteStep {
  MovementTurnAtRandomCommand() = default;
  explicit MovementTurnAtRandomCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnAtRandomCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_at_Random; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnAtRandomCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnAwayFromPlayerCommand final : IMovementRouteStep {
  MovementTurnAwayFromPlayerCommand() = default;
  explicit MovementTurnAwayFromPlayerCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
  : IMovementRouteStep(indent) {}
  ~MovementTurnAwayFromPlayerCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_away_from_Player; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnAwayFromPlayerCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnDownCommand final : IMovementRouteStep {
  MovementTurnDownCommand() = default;
  explicit MovementTurnDownCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnDownCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_Down; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnDownCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnLeftCommand final : IMovementRouteStep {
  MovementTurnLeftCommand() = default;
  explicit MovementTurnLeftCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnLeftCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_Left; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnLeftCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnRightCommand final : IMovementRouteStep {
  MovementTurnRightCommand() = default;
  explicit MovementTurnRightCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnRightCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_Right; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnRightCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnTowardPlayerCommand final : IMovementRouteStep {
  MovementTurnTowardPlayerCommand() = default;
  explicit MovementTurnTowardPlayerCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnTowardPlayerCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_toward_Player; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnTowardPlayerCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementTurnUpCommand final : IMovementRouteStep {
  MovementTurnUpCommand() = default;
  explicit MovementTurnUpCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementTurnUpCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Turn_Up; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementTurnUpCommand>(*this); }
};


code:
#include "Database/EventCommands/MovementRoute/Wait.hpp"

MovementWaitCommand::MovementWaitCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IMovementRouteStep(indent) {
  parameters.at(0).get_to(duration);
}

void MovementWaitCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(duration); }

std::string MovementWaitCommand::stringRep(const Database& db, const bool colored) const { return symbol(code()) + tr("Wait") + colon.data() + std::to_string(duration) + " frames"; }


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"

#include <format>

struct MovementWaitCommand final : IMovementRouteStep {
  MovementWaitCommand() = default;
  explicit MovementWaitCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~MovementWaitCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Wait_del_Movement; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementWaitCommand>(*this); }

  int duration{60};
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementWalkingAnimationOFFCommand final : IMovementRouteStep {
  MovementWalkingAnimationOFFCommand() = default;
  explicit MovementWalkingAnimationOFFCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementWalkingAnimationOFFCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Walking_Animation_OFF; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementWalkingAnimationOFFCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include <format>

struct MovementWalkingAnimationONCommand final : IMovementRouteStep {
  MovementWalkingAnimationONCommand() = default;
  explicit MovementWalkingAnimationONCommand(const std::optional<int>& indent)
  : IMovementRouteStep(indent) {}
  ~MovementWalkingAnimationONCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Walking_Animation_ON; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementWalkingAnimationONCommand>(*this); }
};


code:
#include "Database/EventCommands/NameInput.hpp"

#include "Database/Database.hpp"

NameInputCommand::NameInputCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(actorId);
  parameters.at(1).get_to(maxChar);
}

void NameInputCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(actorId);
  out.push_back(maxChar);
}

std::string NameInputCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Name Input Processing") + colon.data() + db.actorNameOrId(actorId) + ", " +
         // TL-NOTE(disambiguation): Characters here refers to letters/symbols, e.g: the letter 'A' is a character
         std::to_string(maxChar) + (maxChar > 1 ? trNOOP("characters") : trNOOP("character")) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct NameInputCommand final : IEventCommand {
  NameInputCommand() = default;
  explicit NameInputCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~NameInputCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Name_Input_Processing; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<NameInputCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::Actor) {
      return targetId == actorId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      actorId = newId;
      return true;
    }
    return false;
  }
  int actorId{1};
  int maxChar{8};
};


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct OpenMenuCommand final : IEventCommand {
  OpenMenuCommand() = default;
  explicit OpenMenuCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~OpenMenuCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Open_Menu_Screen; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<OpenMenuCommand>(*this); }
};


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct OpenSaveCommand final : IEventCommand {
  OpenSaveCommand() = default;
  explicit OpenSaveCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~OpenSaveCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Open_Save_Screen; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<OpenSaveCommand>(*this); }
};


code:
#include "Database/EventCommands/PlayBGM.hpp"

#include "Database/Database.hpp"

PlayBGMCommand::PlayBGMCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(audio);
}

void PlayBGMCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(audio); }

std::string PlayBGMCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Play BGM") + colon.data() + db.audioText(audio) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/Audio.hpp"
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct PlayBGMCommand final : IEventCommand {
  PlayBGMCommand() = default;
  explicit PlayBGMCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PlayBGMCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Play_BGM; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PlayBGMCommand>(*this); }
  bool hasStringReference(const std::string& text, SearchType type) override {
    if (type == SearchType::Audio) {
      return text.contains(audio.name());
    }
    return false;
  };
  Audio audio;
};


code:
#include "Database/EventCommands/PlayBGS.hpp"

#include "Database/Database.hpp"

PlayBGSCommand::PlayBGSCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(audio);
}

void PlayBGSCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(audio); }

std::string PlayBGSCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Play BGS") + colon.data() + db.audioText(audio) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/Audio.hpp"
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct PlayBGSCommand final : IEventCommand {
  PlayBGSCommand() = default;
  explicit PlayBGSCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PlayBGSCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Play_BGS; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PlayBGSCommand>(*this); }
  bool hasStringReference(const std::string& text, SearchType type) override {
    if (type == SearchType::Audio) {
      return text.contains(audio.name());
    }
    return false;
  };
  Audio audio;
};


code:
#include "Database/EventCommands/PlayME.hpp"

#include "Database/Database.hpp"

PlayMECommand::PlayMECommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(audio);
}

void PlayMECommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(audio); }

std::string PlayMECommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Play ME") + colon.data() + db.audioText(audio) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/Audio.hpp"
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct PlayMECommand final : IEventCommand {
  PlayMECommand() = default;
  explicit PlayMECommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PlayMECommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Play_ME; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PlayMECommand>(*this); }
  bool hasStringReference(const std::string& text, SearchType type) override {
    if (type == SearchType::Audio) {
      return text.contains(audio.name());
    }
    return false;
  };
  Audio audio;
};


code:
#include "Database/EventCommands/PlayMovie.hpp"

#include "Database/Database.hpp"

PlayMovieCommand::PlayMovieCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(name);
}

void PlayMovieCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(name); }

std::string PlayMovieCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Play Movie") + colon.data() + db.imageText(name) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct PlayMovieCommand final : IEventCommand {
  PlayMovieCommand() = default;
  explicit PlayMovieCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PlayMovieCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Play_Movie; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PlayMovieCommand>(*this); }
  std::string name;
};


code:
#include "Database/EventCommands/PlaySE.hpp"

#include "Database/Database.hpp"

PlaySECommand::PlaySECommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(audio);
}

void PlaySECommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(audio); }

std::string PlaySECommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Play SE") + colon.data() + db.audioText(audio) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/Audio.hpp"
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"

#include <format>

struct PlaySECommand final : IEventCommand {
  PlaySECommand() = default;
  explicit PlaySECommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PlaySECommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Play_SE; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PlaySECommand>(*this); }
  bool hasStringReference(const std::string& text, SearchType type) override {
    if (type == SearchType::Audio) {
      if (!text.empty()) {
        if (audio.name().contains(text)) {
          return text.contains(audio.name());
        }
      }
    }
    return false;
  };
  Audio audio;
};


code:
#include "Database/EventCommands/Plugin.hpp"

PluginCommandMV::PluginCommandMV(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(command);
}

void PluginCommandMV::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(command); }

std::string PluginCommandMV::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Plugin Command") + colon.data() + command + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct PluginCommandMV : IEventCommand {
  PluginCommandMV() = default;
  explicit PluginCommandMV(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~PluginCommandMV() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Plugin_Command_del_MV; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<PluginCommandMV>(*this); }

  std::string command;
};


code:
#include "Database/EventCommands/RecoverAll.hpp"
#include "Database/Database.hpp"

RecoverAllCommand::RecoverAllCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(comparison);
  parameters.at(1).get_to(value);
}

void RecoverAllCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(comparison);
  out.push_back(value);
}

std::string RecoverAllCommand::stringRep(const Database& db, const bool colored) const {
  const std::string source = comparison == ActorComparisonSource::Fixed ? value == 0 ? trNOOP("Entire Party") : db.actorNameOrId(value) : "{" + db.variableNameOrId(value) + "}";
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Recover All") + colon.data() + source + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct RecoverAllCommand final : IEventCommand {
  RecoverAllCommand() = default;
  explicit RecoverAllCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~RecoverAllCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Recover_All; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<RecoverAllCommand>(*this); }

  ActorComparisonSource comparison = ActorComparisonSource::Fixed;
  int value = 1;
};


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct RepeatAboveCommand final : IEventCommand {
  RepeatAboveCommand() = default;
  explicit RepeatAboveCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~RepeatAboveCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Repeat_Above; }
  [[nodiscard]] constexpr bool hasPartner() const override { return true; }
  [[nodiscard]] constexpr int partnerCount() const override { return 1; }
  [[nodiscard]] bool reverseSelection() const override { return true; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<RepeatAboveCommand>(*this); }

  bool isPartner(const EventCode code, const std::optional<int>& codeIndent) override {
    if (!codeIndent) {
      return false;
    }
    return code == EventCode::Loop && indent() == *codeIndent;
  }
};


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct ResumeBGMCommand final : IEventCommand {
  ResumeBGMCommand() = default;
  explicit ResumeBGMCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~ResumeBGMCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Resume_BGM; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ResumeBGMCommand>(*this); }
};


code:
#include "Database/EventCommands/ReturnToTitle.hpp"

std::string ReturnToTitleCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Return To Title Screen") + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ReturnToTitleCommand final : IEventCommand {
  ReturnToTitleCommand() = default;
  explicit ReturnToTitleCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~ReturnToTitleCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Return_To_Title_Screen; }
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ReturnToTitleCommand>(*this); }
};


code:
#include "Database/EventCommands/RotatePicture.hpp"

RotatePictureCommand::RotatePictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(picture);
  parameters.at(1).get_to(rotation);
}

void RotatePictureCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(picture);
  out.push_back(rotation);
}

std::string RotatePictureCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Rotate Picture") + colon.data() + "#" + std::to_string(picture) + ", " +
         std::to_string(rotation) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct RotatePictureCommand final : IEventCommand {
  RotatePictureCommand() = default;
  explicit RotatePictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~RotatePictureCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Rotate_Picture; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<RotatePictureCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::PictureId) {
      return picture == targetId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      picture = newId;
      return true;
    }
    return false;
  }
  int picture;
  int rotation;
};


code:
#pragma once
#include "IEventCommand.hpp"
#include <format>

struct SaveBGMCommand final : IEventCommand {
  SaveBGMCommand() = default;
  explicit SaveBGMCommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~SaveBGMCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Save_BGM; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SaveBGMCommand>(*this); }
};


code:
#include "Database/EventCommands/Script.hpp"

NextScriptCommand::NextScriptCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(script);
}

void NextScriptCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(script); }

ScriptCommand::ScriptCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(script);
}

void ScriptCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(script); }

std::string ScriptCommand::stringRep(const Database& db, const bool colored) const {
  const auto name = UndectorateEnumName(code());
  std::string ret = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + name + colon.data() + script + ColorFormatter::popColor(colored);
  for (const auto& t : moreScript) {
    if (!ret.empty()) {
      ret += "\n";
    }
    ret += indentText(indent()) + symbol(t->code()) + ColorFormatter::getColorCode(t->code(), colored) + std::string(name.length(), ' ') + colon.data() + t->script + ColorFormatter::popColor(colored);
  }

  return ret;
}


code:
#pragma once
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct NextScriptCommand final : IEventCommand {
  NextScriptCommand() = default;
  explicit NextScriptCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~NextScriptCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Next_Script; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<NextScriptCommand>(*this); }

  std::string script;
};

struct ScriptCommand final : IEventCommand {
  ScriptCommand() = default;
  explicit ScriptCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ScriptCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Script; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ScriptCommand>(*this); }

  void addText(NextScriptCommand* text) { moreScript.emplace_back(text); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::Variable) {
      std::string cnst = Database::instance()->gameConstants.variables[targetId];
      if (cnst.empty()) {
        return false;
      }

      if (script.contains("gameVariables") && script.contains(cnst)) {
        return true;
      }
    }
    if (type == SearchType::Switch) {
      std::string cnst = Database::instance()->gameConstants.switches[targetId];
      if (cnst.empty()) {
        return false;
      }
      if (script.contains("gameSwitches") && script.contains(cnst)) {
        return true;
      }
    }
    for (auto& nextCmd : moreScript) {
      if (type == SearchType::Variable) {
        std::string cnst = Database::instance()->gameConstants.variables[targetId];
        if (cnst.empty()) {
          return false;
        }
        if (nextCmd->script.contains("gameVariables") && script.contains(Database::instance()->gameConstants.variables[targetId])) {
          return true;
        }
      }
      if (type == SearchType::Switch) {
        std::string cnst = Database::instance()->gameConstants.switches[targetId];
        if (cnst.empty()) {
          return false;
        }
        if (nextCmd->script.contains("gameSwitches") && script.contains(Database::instance()->gameConstants.switches[targetId])) {
          return true;
        }
      }
    }
    return false;
  };

  bool hasStringReference(const std::string& text, SearchType type) override {
    if (text.empty()) {
      return true;
    }
    if (script.contains(text)) {
      return true;
    }
    for (auto& nextCmd : moreScript) {
      if (nextCmd->script.contains(text)) {
        return true;
      }
    }
    return false;
  }
  std::string script;
  std::vector<std::shared_ptr<NextScriptCommand>> moreScript;
};


code:
#include "Database/EventCommands/ScrollMap.hpp"

ScrollMapCommand::ScrollMapCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(direction);
  parameters.at(1).get_to(distance);
  parameters.at(2).get_to(speed);
}

void ScrollMapCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(direction);
  out.push_back(distance);
  out.push_back(speed);
}

std::string ScrollMapCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) +
         std::format("{}{}{}, {}, {}", trNOOP("Scroll Map"), colon.data(), DecodeEnumName(direction), distance, DecodeEnumName(speed)) + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ScrollMapCommand final : IEventCommand {
  ScrollMapCommand() = default;
  explicit ScrollMapCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ScrollMapCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Scroll_Map; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ScrollMapCommand>(*this); }

  Direction direction = Direction::Down;
  int distance{1};
  MovementSpeed speed = MovementSpeed::Normal;
};


code:
#include "Database/EventCommands/ScrollingText.hpp"

NextScrollingTextCommand::NextScrollingTextCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(text);
}

void NextScrollingTextCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(text); }

ShowScrollTextCommand::ShowScrollTextCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(speed);
  parameters.at(1).get_to(noFast);
}

void ShowScrollTextCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(speed);
  out.push_back(noFast);
}

std::string ShowScrollTextCommand::stringRep(const Database& db, const bool colored) const {
  const std::string name = trNOOP("Text(S)");
  std::string ret = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + name.data() + colon.data() + ColorFormatter::popColor(colored) +
                    ColorFormatter::getColor(FormatColor::Gray, colored) + trNOOP("Speed") + " " + std::to_string(speed) + (noFast == true ? ", " + tr("No Fast Forward") : "") +
                    ColorFormatter::popColor(colored);

  for (const auto& t : text) {
    if (!ret.empty()) {
      ret += "\n";
    }
    ret += indentText(indent()) + colon.data() + ColorFormatter::getColorCode(t->code(), colored) + std::string(name.length(), ' ') + colon.data() + t->text + ColorFormatter::popColor(colored);
  }
  return ret;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct NextScrollingTextCommand final : IEventCommand {
  NextScrollingTextCommand() = default;
  explicit NextScrollingTextCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~NextScrollingTextCommand() override = default;
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] EventCode code() const override { return EventCode::Next_Scrolling_Text; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<NextScrollingTextCommand>(*this); }

  std::string text;
};

struct ShowScrollTextCommand final : IEventCommand {
  ShowScrollTextCommand() = default;
  explicit ShowScrollTextCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShowScrollTextCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Scrolling_Text; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowScrollTextCommand>(*this); }

  void addText(NextScrollingTextCommand* n) { text.emplace_back(n); }

  int speed{2};
  bool noFast{false};
  std::vector<std::shared_ptr<NextScrollingTextCommand>> text;
};


code:
#include "Database/EventCommands/SelectItem.hpp"

#include "Database/Database.hpp"

SelectItemCommand::SelectItemCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters)
: IEventCommand(_indent) {
  parameters.at(0).get_to(item);
  parameters.at(1).get_to(type);
}

void SelectItemCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(item);
  out.push_back(type);
}

std::string SelectItemCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Select Item") + colon.data() + db.variableNameOrId(item) + ", " + DecodeEnumName(type) +
         ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct SelectItemCommand final : IEventCommand {
  SelectItemCommand() = default;
  explicit SelectItemCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters);
  ~SelectItemCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Select_Item; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SelectItemCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::Variable) {
      return item == targetId;
    }
    if (type == SearchType::Items) {
      return targetId == item;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      item = newId;
      return true;
    }
    return false;
  }
  int item = 1;
  ItemType type = ItemType::Key_Item;
};


code:
#include "Database/EventCommands/SetEventLocation.hpp"
#include "Database/Database.hpp"

SetEventLocationCommand::SetEventLocationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(event);
  parameters.at(1).get_to(mode);
  parameters.at(2).get_to(x); // Stores event designation ID
  parameters.at(3).get_to(y);
  parameters.at(4).get_to(direction);
}

void SetEventLocationCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(event);
  out.push_back(mode);
  out.push_back(x); // Stores event designation ID
  out.push_back(y);
  out.push_back(direction);
}

std::string SetEventLocationCommand::stringRep(const Database& db, const bool colored) const {
  const auto evName = db.eventNameOrId(event);
  auto dir = static_cast<Direction>(static_cast<int>(direction) * 2);
  const auto prefix = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Set Event Location") + colon.data() + evName;
  const auto suffix =
      direction == Direction::Retain ? "" : ColorFormatter::getColor(FormatColor::Gray, colored) + " (" + tr("Direction") + ": " + DecodeEnumName(dir) + ")" + ColorFormatter::popColor(colored);

  if (mode == TransferMode::Variable_Designation) {
    return prefix + std::format(", ({{{}}},{{{}}})", db.variableNameOrId(x), db.variableNameOrId(y)) + ColorFormatter::popColor() + suffix;
  }

  if (mode == TransferMode::Exchange_With_Another_Event) {
    return prefix + ", " + trNOOP("Exchange with") + " " + Database::instance()->eventNameOrId(x) + ColorFormatter::popColor() + suffix;
  }

  return prefix + std::format(", ({}, {})", x, y) + ColorFormatter::popColor() + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct SetEventLocationCommand final : IEventCommand {
  SetEventLocationCommand() = default;
  explicit SetEventLocationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~SetEventLocationCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Set_Event_Location; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SetEventLocationCommand>(*this); }

  TransferMode mode = TransferMode::Direct;
  int event{0};
  int x{0};
  int y{0};
  Direction direction = Direction::Retain;
};


code:
#include "Database/EventCommands/SetMovementRoute.hpp"
#include "Database/CommandParser.hpp"
#include "Database/Database.hpp"

MovementRouteStepCommand::MovementRouteStepCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  CommandParser p;
  step = p.parse(parameters)[0];
}

void MovementRouteStepCommand::serializeParameters(nlohmann::ordered_json& out) const {
  const auto code = step->code();
  const bool doParameters = code == EventCode::Jump || code == EventCode::Change_Blend_Mode || code == EventCode::Change_Image || code == EventCode::Change_Opacity || code == EventCode::Frequency ||
                            code == EventCode::Speed || code == EventCode::Play_SE_del_Movement || code == EventCode::Wait_del_Movement || code == EventCode::Script_del_Movement ||
                            code == EventCode::Switch_ON || code == EventCode::Switch_OFF;
  step->serialize(out.emplace_back(), step->code() != EventCode::Event_Dummy, doParameters);
}

SetMovementRouteCommand::SetMovementRouteCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(character);
  parameters.at(1).get_to(route);
}

void SetMovementRouteCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(character);
  out.push_back(route);
}

std::string SetMovementRouteCommand::stringRep(const Database& db, const bool colored) const {
  const auto name = DecodeEnumName(code());

  std::string stringSuffix;

  if (route.skippable() == true || route.wait() == true || route.repeat() == true) {
    stringSuffix += "(";
    if (route.repeat() == true) {
      stringSuffix += trNOOP("Repeat");
    }
    if (route.skippable() == true) {
      if (route.repeat() == true) {
        stringSuffix += ", ";
      }
      stringSuffix += trNOOP("Skip");
    }
    if (route.wait() == true) {
      if (route.repeat() == true || route.skippable() == true) {
        stringSuffix += ", ";
      }
      stringSuffix += trNOOP("Wait");
    }
    stringSuffix += ")";
  }

  std::string moveRoute = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + name + colon.data() + db.eventNameOrId(character) +
                          ColorFormatter::popColor(colored) + ColorFormatter::getColor(FormatColor::Gray, colored) + stringSuffix + ColorFormatter::popColor(colored);

  const std::string stepColor = ColorFormatter::getColorCode(EventCode::Movement_Route_Step, colored);
  const std::string stepSymbol = symbol(EventCode::Movement_Route_Step);
  const auto stepSpacing = std::string(name.length(), ' ');
  const std::string popColor = ColorFormatter::popColor(colored);
  for (const auto& t : editNodes) {
    if (t->code() != EventCode::Event_Dummy) {
      moveRoute += "\n" + indentText(t->indent()) + stepSymbol + stepColor + stepSpacing + colon.data() + t->stringRep(db) + popColor;
    }
  }
  return moveRoute;
}


code:
#pragma once
#include "Database/EventCommands/MovementRoute/IMovementRouteStep.hpp"
#include "Database/MovementRoute.hpp"
#include <format>

struct MovementRouteStepCommand final : IEventCommand {
  MovementRouteStepCommand() = default;
  explicit MovementRouteStepCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  explicit MovementRouteStepCommand(const std::optional<int>& indent) { setIndent(indent.value()); }
  ~MovementRouteStepCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Movement_Route_Step; }
  std::shared_ptr<IEventCommand> step;

  void serializeParameters(nlohmann::ordered_json& out) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<MovementRouteStepCommand>(*this); }

  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override { return step->stringRep(db); }
};

struct SetMovementRouteCommand final : IEventCommand {
  SetMovementRouteCommand() = default;
  explicit SetMovementRouteCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~SetMovementRouteCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Set_Movement_Route; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SetMovementRouteCommand>(*this); }

  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  void addStep(MovementRouteStepCommand* step) { editNodes.emplace_back(step); }
  bool hasReference(int targetId, SearchType type) override {
    for (auto& nextCmd : editNodes) {
      if (nextCmd->hasReference(targetId, type)) {
        return true;
      }
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    for (auto& nextCmd : editNodes) {
      nextCmd->hasReference(targetId, type);
    }
    return false;
  }
  int character{-1};
  MovementRoute route;
  std::vector<std::shared_ptr<MovementRouteStepCommand>> editNodes;
};


code:
#include "Database/EventCommands/SetVehicleLocation.hpp"
#include "Database/Database.hpp"

SetVehicleLocationCommand::SetVehicleLocationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(vehicle);
  parameters.at(1).get_to(mode);
  parameters.at(2).get_to(mapId);
  parameters.at(3).get_to(x);
  parameters.at(4).get_to(y);
}

void SetVehicleLocationCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(vehicle);
  out.push_back(mode);
  out.push_back(mapId);
  out.push_back(x);
  out.push_back(y);
}

std::string SetVehicleLocationCommand::stringRep(const Database& db, const bool colored) const {
  const auto prefix = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Set Vehicle Location") + colon.data() + DecodeEnumName(vehicle) + ",";
  const auto suffix = ColorFormatter::popColor(colored);

  if (mode == TransferMode::Variable_Designation) {
    auto varMap = db.system.variable(mapId);
    auto varX = db.system.variable(x);
    auto varY = db.system.variable(y);
    varMap = varMap.empty() ? std::format("#{:04}", mapId) : varMap;
    varX = varX.empty() ? std::format("#{:04}", x) : varX;
    varY = varY.empty() ? std::format("#{:04}", y) : varY;
    return prefix + std::format(" {{{}}} ({{{}}},{{{}}}) ", varMap, varX, varY) + suffix;
  }
  const auto map = db.mapInfos.map(mapId);
  return prefix + std::format(" {} ({}, {})", map->name(), x, y) + suffix;
}


code:
#pragma once
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct SetVehicleLocationCommand final : IEventCommand {
  SetVehicleLocationCommand() = default;
  explicit SetVehicleLocationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~SetVehicleLocationCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Set_Vehicle_Location; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SetVehicleLocationCommand>(*this); }

  VehicleType vehicle = VehicleType::Boat;
  TransferMode mode = TransferMode::Direct;
  int mapId = Database::instance()->mapInfos.currentMap() != nullptr ? Database::instance()->mapInfos.currentMap()->id() : 1;
  int x{0};
  int y{0};
};


code:
#include "Database/EventCommands/SetWeatherEffect.hpp"

#include "Database/Database.hpp"

SetWeatherEffectCommand::SetWeatherEffectCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  std::string eff;
  parameters.at(0).get_to(eff);
  effect = magic_enum::enum_cast<WeatherEffect>(eff, magic_enum::case_insensitive).value();
  parameters.at(1).get_to(power);
  parameters.at(2).get_to(duration);
  parameters.at(3).get_to(waitForCompletion);
}

void SetWeatherEffectCommand::serializeParameters(nlohmann::ordered_json& out) const {
  std::string eff = magic_enum::enum_name(effect).data();
  std::ranges::transform(eff, eff.begin(), [](const char c) { return std::tolower(c); });
  out.push_back(eff);
  out.push_back(power);
  out.push_back(duration);
  out.push_back(waitForCompletion);
}

std::string SetWeatherEffectCommand::stringRep(const Database& db, const bool colored) const {

  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Set Weather Effect") + colon.data() + DecodeEnumName(effect) + ", " + std::to_string(power) +
         ", " + db.framesText(duration) + ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct SetWeatherEffectCommand final : IEventCommand {
  SetWeatherEffectCommand() = default;
  explicit SetWeatherEffectCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~SetWeatherEffectCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Set_Weather_Effect; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<SetWeatherEffectCommand>(*this); }

  WeatherEffect effect;
  int power;
  int duration;
  bool waitForCompletion;
};


code:
#include "Database/EventCommands/ShakeScreen.hpp"

#include "Database/Database.hpp"

ShakeScreenCommand::ShakeScreenCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(power);
  parameters.at(1).get_to(speed);
  parameters.at(2).get_to(duration);
  parameters.at(3).get_to(waitForCompletion);
}

void ShakeScreenCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(power);
  out.push_back(speed);
  out.push_back(duration);
  out.push_back(waitForCompletion);
}

std::string ShakeScreenCommand::stringRep(const Database& db, const bool colored) const {
  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Shake Screen") + colon.data() +
         std::format("{}, {}, {}", power, speed, db.framesText(duration)) + ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShakeScreenCommand final : IEventCommand {
  ShakeScreenCommand() = default;
  explicit ShakeScreenCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShakeScreenCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Shake_Screen; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShakeScreenCommand>(*this); }

  int power;
  int speed;
  int duration;
  bool waitForCompletion;
};


code:
#include "Database/EventCommands/ShopProcessing.hpp"
#include "Database/Database.hpp"

ShopProcessingGoodCommand::ShopProcessingGoodCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(type);
  parameters.at(1).get_to(id);
  parameters.at(2).get_to(priceType);
  parameters.at(3).get_to(price);
}

void ShopProcessingGoodCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(type);
  out.push_back(id);
  out.push_back(priceType);
  out.push_back(price);
}

std::string ShopProcessingGoodCommand::stringRep(const Database& db, const bool colored) const {
  std::string good;
  switch (type) {
  case ShopType::Item:
    good = db.itemName(id);
    break;
  case ShopType::Armor:
    good = db.armorNameOrId(id);
    break;
  case ShopType::Weapon:
    good = db.weaponNameOrId(id);
    break;
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + std::string(tr("Shop Processing").length(), ' ') + colon.data() + good +
         ColorFormatter::popColor(colored);
}

ShopProcessingCommand::ShopProcessingCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(type);
  parameters.at(1).get_to(id);
  parameters.at(2).get_to(priceType);
  parameters.at(3).get_to(price);
  parameters.at(4).get_to(purchaseOnly);
}

void ShopProcessingCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(type);
  out.push_back(id);
  out.push_back(priceType);
  out.push_back(price);
  out.push_back(purchaseOnly);
}

std::string ShopProcessingCommand::stringRep(const Database& db, const bool colored) const {
  std::string good;
  switch (type) {
  case ShopType::Item:
    good = db.itemName(id);
    break;
  case ShopType::Armor:
    good = db.armorNameOrId(id);
    break;
  case ShopType::Weapon:
    good = db.weaponNameOrId(id);
    break;
  }
  std::string ret = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Shop Processing") + colon.data() + good + ColorFormatter::popColor(colored);

  for (const auto& g : goods) {
    ret += "\n" + g->stringRep(db);
  }
  return ret;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShopProcessingGoodCommand final : IEventCommand {
  explicit ShopProcessingGoodCommand(const std::optional<int>& indent = std::nullopt)
  : IEventCommand(indent) {}
  ShopProcessingGoodCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);

  ~ShopProcessingGoodCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Shop_Processing_Good; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShopProcessingGoodCommand>(*this); }
  bool hasReference(int targetId, SearchType searchType) override {
    if (searchType == SearchType::Items && type == ShopType::Item) {
      return id == targetId;
    }
    if (searchType == SearchType::Armors && type == ShopType::Armor) {
      return id == targetId;
    }
    if (searchType == SearchType::Weapons && type == ShopType::Weapon) {
      return id == targetId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      id = newId;
      return true;
    }
    return false;
  }
  ShopType type = ShopType::Item;
  int id{1};
  PriceType priceType = PriceType::Standard;
  int price{0};
};

struct ShopProcessingCommand final : IEventCommand {
  ShopProcessingCommand() = default;
  explicit ShopProcessingCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);

  ~ShopProcessingCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Shop_Processing; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShopProcessingCommand>(*this); }

  void setIndent(const int indent) override {
    IEventCommand::setIndent(indent);
    for (const auto& good : goods) {
      good->setIndent(indent);
    }
  }

  void addGood(const std::shared_ptr<ShopProcessingGoodCommand>& good) { goods.emplace_back(good); }

  ShopType type{};
  int id{0};
  PriceType priceType{};
  int price{};
  bool purchaseOnly{false};
  std::vector<std::shared_ptr<ShopProcessingGoodCommand>> goods;
};


code:
#include "Database/EventCommands/ShowAnimation.hpp"

#include "Database/Database.hpp"

ShowAnimationCommand::ShowAnimationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(character);
  parameters.at(1).get_to(animation);
  parameters.at(2).get_to(waitForCompletion);
}

void ShowAnimationCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(character);
  out.push_back(animation);
  out.push_back(waitForCompletion);
}

std::string ShowAnimationCommand::stringRep(const Database& db, const bool colored) const {
  const auto evName = db.eventNameOrId(character);
  const auto animName = db.animationNameOrId(animation);

  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }

  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Show Animation") + colon.data() + evName + ", " + animName +
         ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShowAnimationCommand final : IEventCommand {
  ShowAnimationCommand() = default;
  explicit ShowAnimationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShowAnimationCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Animation; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowAnimationCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::Animation) {
      return animation == targetId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      animation = newId;
      return true;
    }
    return false;
  }
  int character = -1;
  int animation = 1;
  bool waitForCompletion = false;
};


code:
#include "Database/EventCommands/ShowBalloonIcon.hpp"

#include "Database/Database.hpp"

ShowBalloonIconCommand::ShowBalloonIconCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(id);
  parameters.at(1).get_to(index);
  parameters.at(2).get_to(waitForCompletion);
}

void ShowBalloonIconCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(id);
  out.push_back(index);
  out.push_back(waitForCompletion);
}

std::string ShowBalloonIconCommand::stringRep(const Database& db, const bool colored) const {
  const auto evName = db.eventNameOrId(id);
  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Show Balloon Icon") + colon.data() + evName + DecodeEnumName(index) +
         ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShowBalloonIconCommand final : IEventCommand {
  ShowBalloonIconCommand() = default;
  explicit ShowBalloonIconCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShowBalloonIconCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Balloon_Icon; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowBalloonIconCommand>(*this); }

  int id = -1;
  BalloonIcon index = BalloonIcon::Exclamation;
  bool waitForCompletion = false;
};


code:
#include "Database/EventCommands/ShowBattleAnimation.hpp"
#include "Database/Database.hpp"

ShowBattleAnimationCommand::ShowBattleAnimationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(enemy);
  parameters.at(1).get_to(animation);
  parameters.at(2).get_to(targetAllEnemies);
}

void ShowBattleAnimationCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(enemy);
  out.push_back(animation);
  out.push_back(targetAllEnemies);
}

std::string ShowBattleAnimationCommand::stringRep(const Database& db, const bool colored) const {
  const auto animName = db.animationNameOrId(animation);
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Show Battle Animation") + colon.data() +
         (targetAllEnemies == true ? tr("Entire Troop") + ", " : std::format("#{}{}, ", enemy + 1, m_troopId <= 0 ? "" : Database::instance()->troopMemberName(m_troopId, enemy))) + animName +
         ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShowBattleAnimationCommand final : IEventCommand {
  ShowBattleAnimationCommand() = default;
  explicit ShowBattleAnimationCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShowBattleAnimationCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Battle_Animation; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowBattleAnimationCommand>(*this); }
  bool hasReference(const int targetId, const SearchType type) override {
    if (type == SearchType::Animation) {
      return animation == targetId;
    }
    return false;
  };
  bool setReference(const int targetId, const int newId, const SearchType type) override {
    if (hasReference(targetId, type)) {
      animation = newId;
      return true;
    }
    return false;
  }
  int enemy = 0;
  int animation = 1;
  bool targetAllEnemies = false;

  int m_troopId = 0;
};


code:
#include "ShowChoice.hpp"

ShowChoiceCommand::ShowChoiceCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters)
: IEventCommand(_indent) {
  parameters.at(0).get_to(choices);
  parameters.at(1).get_to(cancelType);
  if (parameters.size() > 2) {
    parameters.at(2).get_to(defaultType);
  } else {
    defaultType = 0;
  }
  if (parameters.size() > 3) {
    parameters.at(3).get_to(positionType);
  } else {
    positionType = ChoiceWindowPosition::Right;
  }

  if (parameters.size() > 4) {
    parameters.at(4).get_to(background);
  } else {
    background = TextBackground::Window;
  }

  if (cancelType >= choices.size()) {
    cancelType = -2;
  }
}

void ShowChoiceCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(choices);
  out.push_back(cancelType);
  if (defaultType != 0 || positionType != ChoiceWindowPosition::Right || background != TextBackground::Window) {
    out.push_back(defaultType);
  }
  if (positionType != ChoiceWindowPosition::Right || background != TextBackground::Window) {
    out.push_back(positionType);
  }

  if (background != TextBackground::Window) {
    out.push_back(background);
  }
}

std::string ShowChoiceCommand::stringRep(const Database& db, const bool colored) const {
  std::string suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " (" + DecodeEnumName(background) + ", " + DecodeEnumName(positionType);
  suffix += (defaultType < 0 ? ", -" : ", #" + std::to_string(defaultType + 1));
  suffix += (cancelType < 0 ? ", -" : ", #" + std::to_string(cancelType + 1)) + ")" + ColorFormatter::popColor(colored);

  std::string choiceList = std::accumulate(std::next(choices.begin()), choices.end(), *choices.begin(), [](const std::string& a, const std::string& b) { return a + ", " + b; });

  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Show Choices") + colon.data() + choiceList + ColorFormatter::popColor(colored) + suffix;
}

WhenSelectedCommand::WhenSelectedCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters)
: IEventCommand(_indent) {
  parameters.at(0).get_to(param1);
  parameters.at(1).get_to(choice);
}

void WhenSelectedCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(param1);
  out.push_back(choice);
}

std::string WhenSelectedCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("When") + " " + choice + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct ShowChoiceCommand final : IEventCommand {
  ShowChoiceCommand() = default;
  explicit ShowChoiceCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters);
  ~ShowChoiceCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Choices; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowChoiceCommand>(*this); }

  [[nodiscard]] constexpr bool collapsable() const override { return true; }
  [[nodiscard]] bool isCollapsed() const override { return m_collapsed; }
  void setCollapsed(const bool collapsed) override { m_collapsed = collapsed; }
  bool isPartner(const EventCode code, const std::optional<int>& codeIndent) override {
    if (!codeIndent) {
      return false;
    }

    return (code == EventCode::End_del_ShowChoices) && *codeIndent == indent();
  }

  [[nodiscard]] constexpr int partnerCount() const override { return 1; }

  [[nodiscard]] constexpr bool hasPartner() const override { return true; }
  [[nodiscard]] constexpr bool isParent() const override { return true; }

  bool m_collapsed{false};

  TextBackground background = TextBackground::Window;
  ChoiceWindowPosition positionType = ChoiceWindowPosition::Right;
  std::vector<std::string> choices{"Yes", "No"};
  int cancelType{1};  // < 0 == disallow/branch
  int defaultType{0}; // -1 is none

  bool hasStringReference(const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      for (auto& cmd : choices) {
        if (cmd.contains(str)) {
          return true;
        }
      }
    }
    return false;
  }
  bool setStringReference(const std::string& replaceStr, const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      for (auto& cmd : choices) {
        if (cmd.contains(str)) {
          size_t pos = str.find(replaceStr);
          if (pos != std::string::npos) {
            cmd.replace(pos, replaceStr.size(), str);
          }
        }
      }
    }
    return true;
  }
};

struct WhenSelectedCommand final : IEventCommand {
  WhenSelectedCommand() = default;
  explicit WhenSelectedCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters);
  ~WhenSelectedCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::When_Selected; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<WhenSelectedCommand>(*this); }

  [[nodiscard]] constexpr bool collapsable() const override { return true; }
  [[nodiscard]] bool isCollapsed() const override { return m_collapsed; }
  [[nodiscard]] bool isCollapseEnd() const override { return false; }
  void setCollapsed(const bool collapsed) override { m_collapsed = collapsed; }
  bool isPartner(const EventCode code, const std::optional<int>& codeIndent) override {
    if (!codeIndent) {
      return false;
    }

    return (code == EventCode::When_Selected || code == EventCode::When_Cancel || code == EventCode::End_del_ShowChoices) && *codeIndent == indent();
  }
  [[nodiscard]] constexpr bool hasPartner() const override { return true; }
  [[nodiscard]] constexpr int partnerCount() const override { return 3; }
  [[nodiscard]] bool reverseSelection() const override { return m_reverseSelection; }
  void setReverseSelection(const bool reverseSelection) override { m_reverseSelection = reverseSelection; }
  bool m_reverseSelection = false;
  bool m_collapsed{false};

  int param1;
  std::string choice;

  bool hasStringReference(const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      return true;
    }
    return false;
  }
  bool setStringReference(const std::string& replaceStr, const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      choice = str;
    }
    return true;
  }
};

struct WhenCancelCommand final : IEventCommand {
  WhenCancelCommand() = default;
  explicit WhenCancelCommand(const std::optional<int>& _indent)
  : IEventCommand(_indent) {}
  ~WhenCancelCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::When_Cancel; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<WhenCancelCommand>(*this); }

  [[nodiscard]] constexpr bool collapsable() const override { return true; }
  [[nodiscard]] bool isCollapsed() const override { return m_collapsed; }
  [[nodiscard]] bool isCollapseEnd() const override { return false; }
  void setCollapsed(const bool collapsed) override { m_collapsed = collapsed; }
  bool isPartner(const EventCode code, const std::optional<int>& codeIndent) override {
    if (!codeIndent) {
      return false;
    }

    return (code == EventCode::End_del_ShowChoices) && *codeIndent == indent();
  }
  [[nodiscard]] constexpr bool hasPartner() const override { return true; }
  [[nodiscard]] constexpr int partnerCount() const override { return 1; }
  [[nodiscard]] bool reverseSelection() const override { return m_reverseSelection; }
  void setReverseSelection(const bool reverseSelection) override { m_reverseSelection = reverseSelection; }
  bool m_reverseSelection = false;
  bool m_collapsed{false};
};

struct ShowChoicesEndCommand final : IEventCommand {
  ShowChoicesEndCommand() = default;
  explicit ShowChoicesEndCommand(const std::optional<int>& _indent)
  : IEventCommand(_indent) {}
  ~ShowChoicesEndCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::End_del_ShowChoices; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowChoicesEndCommand>(*this); }

  bool hasStringReference(const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      return true;
    }
    return false;
  }
};


code:
#include "Database/EventCommands/ShowPicture.hpp"

#include "Database/Database.hpp"

ShowPictureCommand::ShowPictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(number);
  parameters.at(1).get_to(imageName);
  parameters.at(2).get_to(origin);
  parameters.at(3).get_to(type);
  parameters.at(4).get_to(value1);
  parameters.at(5).get_to(value2);
  parameters.at(6).get_to(zoomX);
  parameters.at(7).get_to(zoomY);
  parameters.at(8).get_to(opacityValue);
  parameters.at(9).get_to(blendMode);
}

void ShowPictureCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(number);
  out.push_back(imageName);
  out.push_back(origin);
  out.push_back(type);
  out.push_back(value1);
  out.push_back(value2);
  out.push_back(zoomX);
  out.push_back(zoomY);
  out.push_back(opacityValue);
  out.push_back(blendMode);
}

std::string ShowPictureCommand::stringRep(const Database& db, const bool colored) const {
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Show Picture") + colon.data() +
         std::format("#{}, {}, {} ({},{}), ({}%, {}%), {}, {}", number, db.imageText(imageName), DecodeEnumName(origin), value1, value2, zoomX, zoomY, opacityValue, DecodeEnumName(blendMode)) +
         ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct ShowPictureCommand final : IEventCommand {
  ShowPictureCommand() = default;
  explicit ShowPictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~ShowPictureCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Picture; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowPictureCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::PictureId) {
      return number == targetId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      number = newId;
      return true;
    }
    return false;
  }
  int number{1};
  std::string imageName;
  PictureOrigin origin = PictureOrigin::Upper_Left;
  PictureDesignationSource type = PictureDesignationSource::Direct_designation;
  int value1{1}; // direct X value or indirect from global variables
  int value2{1}; // direct Y value or indirect from global variables
  int zoomX{100};
  int zoomY{100};
  int opacityValue{255};
  Blend blendMode = Blend::Normal;
};


code:
#include "ShowText.hpp"

#include "Database/Database.hpp"

NextTextCommand::NextTextCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters)
: IEventCommand(_indent) {
  parameters.at(0).get_to(text);
}

void NextTextCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(text); }

ShowTextCommand::ShowTextCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters)
: IEventCommand(_indent) {
  parameters.at(0).get_to(faceImage);
  parameters.at(1).get_to(faceIndex);
  parameters.at(2).get_to(background);
  parameters.at(3).get_to(position);
}

void ShowTextCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(faceImage);
  out.push_back(faceIndex);
  out.push_back(background);
  out.push_back(position);
}

std::string ShowTextCommand::stringRep(const Database& db, const bool colored) const {
  const auto name = UndectorateEnumName(code());
  std::string ret = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + name + colon.data() + ColorFormatter::popColor(colored) +
                    ColorFormatter::getColor(FormatColor::Gray, colored) + db.imageText(faceImage, faceIndex) + ", " + DecodeEnumName(background) + ", " + DecodeEnumName(position) +
                    ColorFormatter::popColor(colored);

  for (const auto& t : text) {
    if (!ret.empty()) {
      ret += "\n";
    }
    ret += indentText(indent()) + symbol(t->code()) + ColorFormatter::getColorCode(t->code(), colored) + std::string(name.length(), ' ') + colon.data() + t->text + ColorFormatter::popColor(colored);
  }
  return ret;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct NextTextCommand final : IEventCommand {
  NextTextCommand() = default;
  NextTextCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters);
  explicit NextTextCommand(const std::optional<int>& indent) { setIndent(indent.value()); }
  ~NextTextCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Next_Text; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<NextTextCommand>(*this); }

  std::string text;
};

struct ShowTextCommand final : IEventCommand {
  ShowTextCommand() = default;
  ShowTextCommand(const std::optional<int>& _indent, const nlohmann::ordered_json& parameters);
  ~ShowTextCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Show_Text; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<ShowTextCommand>(*this); }

  void addText(NextTextCommand* nextText) { text.emplace_back(nextText); }

  void adjustIndent(const int offset) override {
    int originalIndent = this->indent().value();

    this->setIndent(originalIndent + offset);

    if (!text.empty()) {
      for (const auto& nextText : text) {
        nextText->setIndent(originalIndent + offset);
      }
    }
    // if (this->indent()) {
    //   this->setIndent(originalIndent + offset);
    // } else {
    //  m_indent.emplace(0);
    //}
    setModified();
  }

  std::string faceImage;
  int faceIndex{0};
  TextBackground background = TextBackground::Window;
  TextWindowPosition position = TextWindowPosition::Bottom;
  std::string textLine;
  std::vector<std::shared_ptr<NextTextCommand>> text;

  bool hasStringReference(const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      for (auto& cmd : text) {
        if (cmd->text.contains(str)) {
          return true;
        }
      }
    }
    return false;
  }
  bool setStringReference(const std::string& replaceStr, const std::string& str, SearchType type) override {
    if (type == SearchType::Text) {
      for (auto& cmd : text) {
        if (cmd->text.contains(replaceStr)) {
          size_t pos = cmd->text.find(replaceStr);
          if (pos != std::string::npos) {
            cmd->text.replace(pos, replaceStr.size(), str);
          }
        }
      }
    }
    return true;
  }
};


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct StopSECommand final : IEventCommand {
  StopSECommand() = default;
  explicit StopSECommand(const std::optional<int>& indent)
  : IEventCommand(indent) {}
  ~StopSECommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Stop_SE; }
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<StopSECommand>(*this); }
};


code:
#include "Database/EventCommands/TintPicture.hpp"
#include "Database/Database.hpp"

TintPictureCommand::TintPictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(picture);
  auto colorValues = parameters.at(1);
  colorValues[0].get_to(color.r);
  colorValues[1].get_to(color.g);
  colorValues[2].get_to(color.b);
  colorValues[3].get_to(color.gray);
  parameters.at(2).get_to(duration);
  parameters.at(3).get_to(waitForCompletion);
}

void TintPictureCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(picture);
  auto colorValues = nlohmann::json();
  colorValues.push_back(color.r);
  colorValues.push_back(color.g);
  colorValues.push_back(color.b);
  colorValues.push_back(color.gray);
  out.push_back(colorValues);
  out.push_back(duration);
  out.push_back(waitForCompletion);
}

std::string TintPictureCommand::stringRep(const Database& db, const bool colored) const {
  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Tint Picture") + colon.data() +
         std::format("#{}, ({},{},{},{}), {}", picture, color.r, color.g, color.b, color.gray, db.framesText(duration)) + ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct TintPictureCommand final : IEventCommand {
  TintPictureCommand() = default;
  explicit TintPictureCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~TintPictureCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Tint_Picture; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<TintPictureCommand>(*this); }
  bool hasReference(int targetId, SearchType type) override {
    if (type == SearchType::PictureId) {
      return picture == targetId;
    }
    return false;
  };
  bool setReference(int targetId, int newId, SearchType type) override {
    if (hasReference(targetId, type)) {
      picture = newId;
      return true;
    }
    return false;
  }
  int picture{1};

  struct {
    int r{0};
    int g{0};
    int b{0};
    int gray{0};
  } color;

  int duration{60};
  bool waitForCompletion{true};
};


code:
#include "Database/EventCommands/TintScreen.hpp"

#include "Database/Database.hpp"

TintScreenCommand::TintScreenCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  auto colorValues = parameters.at(0);
  colorValues[0].get_to(color.r);
  colorValues[1].get_to(color.g);
  colorValues[2].get_to(color.b);
  colorValues[3].get_to(color.gray);
  parameters.at(1).get_to(duration);
  parameters.at(2).get_to(waitForCompletion);
}

void TintScreenCommand::serializeParameters(nlohmann::ordered_json& out) const {
  auto colorValues = nlohmann::json();
  colorValues.push_back(color.r);
  colorValues.push_back(color.g);
  colorValues.push_back(color.b);
  colorValues.push_back(color.gray);
  out.push_back(colorValues);
  out.push_back(duration);
  out.push_back(waitForCompletion);
}

std::string TintScreenCommand::stringRep(const Database& db, const bool colored) const {
  std::string suffix;
  if (waitForCompletion) {
    suffix = ColorFormatter::getColor(FormatColor::Gray, colored) + " " + db.parentheses(trNOOP("Wait")) + ColorFormatter::popColor(colored);
  }
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Tint Screen") + colon.data() +
         std::format("({},{},{},{}), {}", color.r, color.g, color.b, color.gray, db.framesText(duration)) + ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct TintScreenCommand final : IEventCommand {
  TintScreenCommand() = default;
  explicit TintScreenCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~TintScreenCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Tint_Screen; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<TintScreenCommand>(*this); }

  struct {
    int r;
    int g;
    int b;
    int gray;
  } color;
  int duration;
  bool waitForCompletion;
};


code:
#include "Database/EventCommands/TransferPlayer.hpp"

#include "Database/Database.hpp"

TransferPlayerCommand::TransferPlayerCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(mode);
  parameters.at(1).get_to(mapId);
  parameters.at(2).get_to(x);
  parameters.at(3).get_to(y);
  parameters.at(4).get_to(direction);
  parameters.at(5).get_to(fade);
}

void TransferPlayerCommand::serializeParameters(nlohmann::ordered_json& out) const {
  out.push_back(mode);
  out.push_back(mapId);
  out.push_back(x);
  out.push_back(y);
  out.push_back(direction);
  out.push_back(fade);
}

std::string TransferPlayerCommand::stringRep(const Database& db, const bool colored) const {
  std::string suffix;

  if (direction != Direction::Retain || fade != Fade::Black) {
    suffix += ColorFormatter::getColor(FormatColor::Gray, colored) + " (";
  }
  if (direction != Direction::Retain) {
    suffix += tr("Direction") + ": " + DecodeEnumName(direction);
  }

  if (fade != Fade::Black) {
    if (direction != Direction::Retain) {
      suffix += ", ";
    }
    suffix += tr("Fade") + ": " + DecodeEnumName(fade);
  }
  if (direction != Direction::Retain || fade != Fade::Black) {
    suffix += ")" + ColorFormatter::popColor(colored);
  }

  if (mode == TransferMode::Variable_Designation) {
    auto varMap = db.variableNameOrId(mapId);
    auto varX = db.variableNameOrId(x);
    auto varY = db.variableNameOrId(y);
    return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Transfer Player") + colon.data() +
           std::format("{{{}}} ({{{}}},{{{}}})", varMap, varX, varY) + ColorFormatter::popColor(colored) + suffix;
  }
  const auto mapName = db.mapNameOrId(mapId);
  return indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Transfer Player") + colon.data() + mapName + std::format(" ({},{})", x, y) +
         ColorFormatter::popColor(colored) + suffix;
}


code:
#pragma once
#include "Database/Database.hpp"
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct TransferPlayerCommand final : IEventCommand {
  TransferPlayerCommand() = default;
  explicit TransferPlayerCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~TransferPlayerCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Transfer_Player; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<TransferPlayerCommand>(*this); }

  TransferMode mode = TransferMode::Direct;
  int mapId = Database::instance() != nullptr && Database::instance()->mapInfos.currentMap() != nullptr ? Database::instance()->mapInfos.currentMap()->id() : 1;
  int x{0};
  int y{0};
  Direction direction = Direction::Retain;
  Fade fade = Fade::Black;
};


code:
#include "Database/EventCommands/UnhandledEvent.hpp"

void UnhandledEventCommand::serialize(nlohmann::ordered_json& out, [[maybe_unused]] const bool doIndent, [[maybe_unused]] const bool doParameters, [[maybe_unused]] const bool oldValues) const {
  out.push_back(data);
}

std::string UnhandledEventCommand::stringRep(const Database& db, const bool colored) const {
  return IEventCommand::stringRep(db) + ColorFormatter::getColor(FormatColor::Red, colored) + " UNHANDLED" + ColorFormatter::popColor(colored);
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"

struct UnhandledEventCommand final : IEventCommand {
  ~UnhandledEventCommand() override = default;
  [[nodiscard]] EventCode code() const override { return m_code; }
  void serialize(nlohmann::ordered_json& out, const bool doIndent = true, const bool doParameters = true, bool oldValues = false) const override;
  std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<UnhandledEventCommand>(*this); }

  EventCode m_code{};
  nlohmann::ordered_json data;
};


code:
#include "Database/EventCommands/Wait.hpp"

#include "Database/Database.hpp"

WaitCommand::WaitCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters)
: IEventCommand(indent) {
  parameters.at(0).get_to(duration);
}

void WaitCommand::serializeParameters(nlohmann::ordered_json& out) const { out.push_back(duration); }

std::string WaitCommand::stringRep(const Database& db, const bool colored) const {
  auto ret = indentText(indent()) + symbol(code()) + ColorFormatter::getColorCode(code(), colored) + trNOOP("Wait") + colon.data() + db.framesText(duration) + ColorFormatter::popColor(colored);
  return ret;
}


code:
#pragma once
#include "Database/EventCommands/IEventCommand.hpp"
#include <format>

struct WaitCommand final : IEventCommand {
  WaitCommand() = default;
  explicit WaitCommand(const std::optional<int>& indent, const nlohmann::ordered_json& parameters);
  ~WaitCommand() override = default;
  [[nodiscard]] EventCode code() const override { return EventCode::Wait; }
  void serializeParameters(nlohmann::ordered_json& out) const override;
  [[nodiscard]] std::string stringRep(const Database& db, bool colored = true) const override;
  std::shared_ptr<IEventCommand> clone() const override { return std::make_shared<WaitCommand>(*this); }

  int duration = 1;
};