From 6691ee3b963ee3282490360bb3cc1ea09d0c58ea Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Mon, 1 Nov 2021 21:30:34 +0100 Subject: Codechange: Template script command calls. --- src/script/api/script_story_page.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/script/api/script_story_page.cpp') diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 4ee90e218..afa259041 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -19,6 +19,7 @@ #include "../../goal_base.h" #include "../../string_func.h" #include "../../tile_map.h" +#include "../../story_cmd.h" #include "../../safeguards.h" @@ -47,12 +48,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) uint8 c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - if (!ScriptObject::DoCommand(0, + if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnStoryPageID, + 0, c, 0, - CMD_CREATE_STORY_PAGE, - title != nullptr? title->GetEncodedText() : nullptr, - &ScriptInstance::DoCommandReturnStoryPageID)) return STORY_PAGE_INVALID; + title != nullptr ? std::string{ title->GetEncodedText() } : std::string{})) return STORY_PAGE_INVALID; /* In case of test-mode, we return StoryPageID 0 */ return (ScriptStoryPage::StoryPageID)0; @@ -89,12 +89,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) NOT_REACHED(); } - if (!ScriptObject::DoCommand(reftile, + if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnStoryPageElementID, + reftile, story_page_id + (type << 16), refid, - CMD_CREATE_STORY_PAGE_ELEMENT, - StoryPageElementTypeRequiresText(btype) ? text->GetEncodedText() : nullptr, - &ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID; + StoryPageElementTypeRequiresText(btype) ? std::string{ text->GetEncodedText() } : std::string{})) return STORY_PAGE_ELEMENT_INVALID; /* In case of test-mode, we return StoryPageElementID 0 */ return (ScriptStoryPage::StoryPageElementID)0; @@ -134,11 +133,10 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) NOT_REACHED(); } - return ScriptObject::DoCommand(reftile, + return ScriptObject::Command::Do(reftile, story_page_element_id, refid, - CMD_UPDATE_STORY_PAGE_ELEMENT, - StoryPageElementTypeRequiresText(type) ? text->GetEncodedText() : nullptr); + StoryPageElementTypeRequiresText(type) ? std::string{ text->GetEncodedText() } : std::string{}); } /* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id) @@ -162,7 +160,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr? title->GetEncodedText() : nullptr); + return ScriptObject::Command::Do(0, story_page_id, 0, title != nullptr ? std::string{ title->GetEncodedText() } : std::string{}); } /* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id) @@ -188,7 +186,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, nullptr); + return ScriptObject::Command::Do(0, story_page_id, date, {}); } @@ -197,7 +195,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SHOW_STORY_PAGE); + return ScriptObject::Command::Do(0, story_page_id, 0, {}); } /* static */ bool ScriptStoryPage::Remove(StoryPageID story_page_id) @@ -205,7 +203,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); EnforcePrecondition(false, IsValidStoryPage(story_page_id)); - return ScriptObject::DoCommand(0, story_page_id, 0, CMD_REMOVE_STORY_PAGE); + return ScriptObject::Command::Do(0, story_page_id, 0, {}); } /* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id) @@ -213,7 +211,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id)); - return ScriptObject::DoCommand(0, story_page_element_id, 0, CMD_REMOVE_STORY_PAGE_ELEMENT); + return ScriptObject::Command::Do(0, story_page_element_id, 0, {}); } /* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakePushButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags) -- cgit v1.2.3-54-g00ecf