Skip to content

Commit

Permalink
Merge pull request #470 from Ghabry/enum-tags
Browse files Browse the repository at this point in the history
EnumTags: Support non-monotonic enums (e.g. EventCommands)
  • Loading branch information
fdelapena authored Dec 1, 2023
2 parents 28fd197 + 0a2de2f commit 272daa5
Show file tree
Hide file tree
Showing 9 changed files with 897 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ endif()
if(LIBLCF_ENABLE_TESTS)
file(GLOB TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
add_executable(test_runner_lcf EXCLUDE_FROM_ALL ${TEST_FILES})
target_compile_definitions(test_runner_lcf PRIVATE DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING=1)
set_target_properties(test_runner_lcf PROPERTIES OUTPUT_NAME "test_runner")
target_link_libraries(test_runner_lcf lcf)
add_custom_target(check_lcf COMMAND test_runner_lcf)
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ test_runner_SOURCES = \
tests/dbbitarray.cpp \
tests/dbstring.cpp \
tests/doctest.h \
tests/enum_tags.cpp \
tests/flag_set.cpp \
tests/test_main.cpp \
tests/time_stamp.cpp \
Expand All @@ -342,6 +343,7 @@ test_runner_CPPFLAGS = \
-I$(srcdir)/src/generated
test_runner_CXXFLAGS = \
-std=gnu++17 \
-DDOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING=1 \
$(EXPAT_CXXFLAGS) \
$(ICU_CXXFLAGS)
test_runner_LDADD = \
Expand Down
10 changes: 10 additions & 0 deletions generator/templates/rpg_header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ namespace rpg {
"{{ field.0 }}"{%- if not loop.last %},{% endif %}
{%- endfor %}
);
{%- else %}
static constexpr auto k{{ name }}Tags = lcf::EnumTags{
{%- for field in enum %}
{%- if name != "Code" %}
{{ name }}_{{ field.0 }}, "{{ field.0 }}"{%- if not loop.last %},{% endif %}
{%- else %}
{{ name }}::{{ field.0 }}, "{{ field.0 }}"{%- if not loop.last %},{% endif %}
{%- endif %}
{%- endfor %}
};
{%- endif %}
{%- endfor %}
{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions src/generated/lcf/rpg/battleranimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace rpg {
Speed_medium = 14,
Speed_fast = 8
};
static constexpr auto kSpeedTags = lcf::EnumTags{
Speed_slow, "slow",
Speed_medium, "medium",
Speed_fast, "fast"
};
enum Pose {
Pose_Idle = 0,
Pose_AttackRight = 1,
Expand Down
5 changes: 5 additions & 0 deletions src/generated/lcf/rpg/commonevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace rpg {
Trigger_parallel = 4,
Trigger_call = 5
};
static constexpr auto kTriggerTags = lcf::EnumTags{
Trigger_automatic, "automatic",
Trigger_parallel, "parallel",
Trigger_call, "call"
};

int ID = 0;
DBString name;
Expand Down
156 changes: 156 additions & 0 deletions src/generated/lcf/rpg/eventcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,162 @@ namespace rpg {
Maniac_EditTile = 3028,
Maniac_ControlTextProcessing = 3029
};
static constexpr auto kCodeTags = lcf::EnumTags{
Code::END, "END",
Code::CallCommonEvent, "CallCommonEvent",
Code::ForceFlee, "ForceFlee",
Code::EnableCombo, "EnableCombo",
Code::ChangeClass, "ChangeClass",
Code::ChangeBattleCommands, "ChangeBattleCommands",
Code::OpenLoadMenu, "OpenLoadMenu",
Code::ExitGame, "ExitGame",
Code::ToggleAtbMode, "ToggleAtbMode",
Code::ToggleFullscreen, "ToggleFullscreen",
Code::OpenVideoOptions, "OpenVideoOptions",
Code::ShowMessage, "ShowMessage",
Code::MessageOptions, "MessageOptions",
Code::ChangeFaceGraphic, "ChangeFaceGraphic",
Code::ShowChoice, "ShowChoice",
Code::InputNumber, "InputNumber",
Code::ControlSwitches, "ControlSwitches",
Code::ControlVars, "ControlVars",
Code::TimerOperation, "TimerOperation",
Code::ChangeGold, "ChangeGold",
Code::ChangeItems, "ChangeItems",
Code::ChangePartyMembers, "ChangePartyMembers",
Code::ChangeExp, "ChangeExp",
Code::ChangeLevel, "ChangeLevel",
Code::ChangeParameters, "ChangeParameters",
Code::ChangeSkills, "ChangeSkills",
Code::ChangeEquipment, "ChangeEquipment",
Code::ChangeHP, "ChangeHP",
Code::ChangeSP, "ChangeSP",
Code::ChangeCondition, "ChangeCondition",
Code::FullHeal, "FullHeal",
Code::SimulatedAttack, "SimulatedAttack",
Code::ChangeHeroName, "ChangeHeroName",
Code::ChangeHeroTitle, "ChangeHeroTitle",
Code::ChangeSpriteAssociation, "ChangeSpriteAssociation",
Code::ChangeActorFace, "ChangeActorFace",
Code::ChangeVehicleGraphic, "ChangeVehicleGraphic",
Code::ChangeSystemBGM, "ChangeSystemBGM",
Code::ChangeSystemSFX, "ChangeSystemSFX",
Code::ChangeSystemGraphics, "ChangeSystemGraphics",
Code::ChangeScreenTransitions, "ChangeScreenTransitions",
Code::EnemyEncounter, "EnemyEncounter",
Code::OpenShop, "OpenShop",
Code::ShowInn, "ShowInn",
Code::EnterHeroName, "EnterHeroName",
Code::Teleport, "Teleport",
Code::MemorizeLocation, "MemorizeLocation",
Code::RecallToLocation, "RecallToLocation",
Code::EnterExitVehicle, "EnterExitVehicle",
Code::SetVehicleLocation, "SetVehicleLocation",
Code::ChangeEventLocation, "ChangeEventLocation",
Code::TradeEventLocations, "TradeEventLocations",
Code::StoreTerrainID, "StoreTerrainID",
Code::StoreEventID, "StoreEventID",
Code::EraseScreen, "EraseScreen",
Code::ShowScreen, "ShowScreen",
Code::TintScreen, "TintScreen",
Code::FlashScreen, "FlashScreen",
Code::ShakeScreen, "ShakeScreen",
Code::PanScreen, "PanScreen",
Code::WeatherEffects, "WeatherEffects",
Code::ShowPicture, "ShowPicture",
Code::MovePicture, "MovePicture",
Code::ErasePicture, "ErasePicture",
Code::ShowBattleAnimation, "ShowBattleAnimation",
Code::PlayerVisibility, "PlayerVisibility",
Code::FlashSprite, "FlashSprite",
Code::MoveEvent, "MoveEvent",
Code::ProceedWithMovement, "ProceedWithMovement",
Code::HaltAllMovement, "HaltAllMovement",
Code::Wait, "Wait",
Code::PlayBGM, "PlayBGM",
Code::FadeOutBGM, "FadeOutBGM",
Code::MemorizeBGM, "MemorizeBGM",
Code::PlayMemorizedBGM, "PlayMemorizedBGM",
Code::PlaySound, "PlaySound",
Code::PlayMovie, "PlayMovie",
Code::KeyInputProc, "KeyInputProc",
Code::ChangeMapTileset, "ChangeMapTileset",
Code::ChangePBG, "ChangePBG",
Code::ChangeEncounterSteps, "ChangeEncounterSteps",
Code::TileSubstitution, "TileSubstitution",
Code::TeleportTargets, "TeleportTargets",
Code::ChangeTeleportAccess, "ChangeTeleportAccess",
Code::EscapeTarget, "EscapeTarget",
Code::ChangeEscapeAccess, "ChangeEscapeAccess",
Code::OpenSaveMenu, "OpenSaveMenu",
Code::ChangeSaveAccess, "ChangeSaveAccess",
Code::OpenMainMenu, "OpenMainMenu",
Code::ChangeMainMenuAccess, "ChangeMainMenuAccess",
Code::ConditionalBranch, "ConditionalBranch",
Code::Label, "Label",
Code::JumpToLabel, "JumpToLabel",
Code::Loop, "Loop",
Code::BreakLoop, "BreakLoop",
Code::EndEventProcessing, "EndEventProcessing",
Code::EraseEvent, "EraseEvent",
Code::CallEvent, "CallEvent",
Code::Comment, "Comment",
Code::GameOver, "GameOver",
Code::ReturntoTitleScreen, "ReturntoTitleScreen",
Code::ChangeMonsterHP, "ChangeMonsterHP",
Code::ChangeMonsterMP, "ChangeMonsterMP",
Code::ChangeMonsterCondition, "ChangeMonsterCondition",
Code::ShowHiddenMonster, "ShowHiddenMonster",
Code::ChangeBattleBG, "ChangeBattleBG",
Code::ShowBattleAnimation_B, "ShowBattleAnimation_B",
Code::ConditionalBranch_B, "ConditionalBranch_B",
Code::TerminateBattle, "TerminateBattle",
Code::ShowMessage_2, "ShowMessage_2",
Code::ShowChoiceOption, "ShowChoiceOption",
Code::ShowChoiceEnd, "ShowChoiceEnd",
Code::VictoryHandler, "VictoryHandler",
Code::EscapeHandler, "EscapeHandler",
Code::DefeatHandler, "DefeatHandler",
Code::EndBattle, "EndBattle",
Code::Transaction, "Transaction",
Code::NoTransaction, "NoTransaction",
Code::EndShop, "EndShop",
Code::Stay, "Stay",
Code::NoStay, "NoStay",
Code::EndInn, "EndInn",
Code::ElseBranch, "ElseBranch",
Code::EndBranch, "EndBranch",
Code::EndLoop, "EndLoop",
Code::Comment_2, "Comment_2",
Code::ElseBranch_B, "ElseBranch_B",
Code::EndBranch_B, "EndBranch_B",
Code::Maniac_GetSaveInfo, "Maniac_GetSaveInfo",
Code::Maniac_Save, "Maniac_Save",
Code::Maniac_Load, "Maniac_Load",
Code::Maniac_EndLoadProcess, "Maniac_EndLoadProcess",
Code::Maniac_GetMousePosition, "Maniac_GetMousePosition",
Code::Maniac_SetMousePosition, "Maniac_SetMousePosition",
Code::Maniac_ShowStringPicture, "Maniac_ShowStringPicture",
Code::Maniac_GetPictureInfo, "Maniac_GetPictureInfo",
Code::Maniac_ControlBattle, "Maniac_ControlBattle",
Code::Maniac_ControlAtbGauge, "Maniac_ControlAtbGauge",
Code::Maniac_ChangeBattleCommandEx, "Maniac_ChangeBattleCommandEx",
Code::Maniac_GetBattleInfo, "Maniac_GetBattleInfo",
Code::Maniac_ControlVarArray, "Maniac_ControlVarArray",
Code::Maniac_KeyInputProcEx, "Maniac_KeyInputProcEx",
Code::Maniac_RewriteMap, "Maniac_RewriteMap",
Code::Maniac_ControlGlobalSave, "Maniac_ControlGlobalSave",
Code::Maniac_ChangePictureId, "Maniac_ChangePictureId",
Code::Maniac_SetGameOption, "Maniac_SetGameOption",
Code::Maniac_CallCommand, "Maniac_CallCommand",
Code::Maniac_ControlStrings, "Maniac_ControlStrings",
Code::Maniac_GetGameInfo, "Maniac_GetGameInfo",
Code::Maniac_EditPicture, "Maniac_EditPicture",
Code::Maniac_WritePicture, "Maniac_WritePicture",
Code::Maniac_AddMoveRoute, "Maniac_AddMoveRoute",
Code::Maniac_EditTile, "Maniac_EditTile",
Code::Maniac_ControlTextProcessing, "Maniac_ControlTextProcessing"
};

int32_t code = 0;
int32_t indent = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/generated/lcf/rpg/eventpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ namespace rpg {
MoveSpeed_double = 5,
MoveSpeed_fourfold = 6
};
static constexpr auto kMoveSpeedTags = lcf::EnumTags{
MoveSpeed_eighth, "eighth",
MoveSpeed_quarter, "quarter",
MoveSpeed_half, "half",
MoveSpeed_normal, "normal",
MoveSpeed_double, "double",
MoveSpeed_fourfold, "fourfold"
};
enum ManiacEventInfo {
ManiacEventInfo_action = 0,
ManiacEventInfo_touched = 1,
Expand All @@ -136,6 +144,19 @@ namespace rpg {
ManiacEventInfo_common_event = 32,
ManiacEventInfo_battle_event = 64
};
static constexpr auto kManiacEventInfoTags = lcf::EnumTags{
ManiacEventInfo_action, "action",
ManiacEventInfo_touched, "touched",
ManiacEventInfo_collision, "collision",
ManiacEventInfo_auto_start, "auto_start",
ManiacEventInfo_parallel, "parallel",
ManiacEventInfo_called, "called",
ManiacEventInfo_battle_start, "battle_start",
ManiacEventInfo_battle_parallel, "battle_parallel",
ManiacEventInfo_map_event, "map_event",
ManiacEventInfo_common_event, "common_event",
ManiacEventInfo_battle_event, "battle_event"
};

int ID = 0;
EventPageCondition condition;
Expand Down
Loading

0 comments on commit 272daa5

Please sign in to comment.