(svn r26306) -Add: [nogo] More story APIs: RemovePageElement, GetCompany, GetDate, SetDate

This commit is contained in:
zuu
2014-02-06 19:48:19 +00:00
parent 57a88c9de2
commit 1dbd59e6ab
6 changed files with 139 additions and 6 deletions

View File

@@ -32,11 +32,15 @@ void SQGSStoryPage_Register(Squirrel *engine)
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::New, "New", 3, ".i.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::NewElement, "NewElement", 5, ".iii.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::UpdateElement, "UpdateElement", 4, ".ii.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageSort, "GetPageSort", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageElementSort, "GetPageElementSort", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageSortValue, "GetPageSortValue", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageElementSortValue, "GetPageElementSortValue", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetCompany, "GetCompany", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetDate, "GetDate", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetDate, "SetDate", 3, ".ii");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetTitle, "SetTitle", 3, ".i.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Show, "Show", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Remove, "Remove", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::RemoveElement, "RemoveElement", 2, ".i");
SQGSStoryPage.PostRegister(engine);
}

View File

@@ -98,14 +98,14 @@
type == ::SPET_TEXT || type == ::SPET_LOCATION ? text->GetEncodedText() : NULL);
}
/* static */ uint32 ScriptStoryPage::GetPageSort(StoryPageID story_page_id)
/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
return StoryPage::Get(story_page_id)->sort_value;
}
/* static */ uint32 ScriptStoryPage::GetPageElementSort(StoryPageElementID story_page_element_id)
/* static */ uint32 ScriptStoryPage::GetPageElementSortValue(StoryPageElementID story_page_element_id)
{
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
@@ -122,6 +122,32 @@
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != NULL? title->GetEncodedText() : NULL);
}
/* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id)
{
EnforcePrecondition(ScriptCompany::COMPANY_INVALID, IsValidStoryPage(story_page_id));
CompanyID c = StoryPage::Get(story_page_id)->company;
ScriptCompany::CompanyID company = c == INVALID_COMPANY ? ScriptCompany::COMPANY_INVALID : (ScriptCompany::CompanyID)c;
return company;
}
/* static */ int32 ScriptStoryPage::GetDate(StoryPageID story_page_id)
{
EnforcePrecondition(-1, IsValidStoryPage(story_page_id));
return StoryPage::Get(story_page_id)->date;
}
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, int32 date)
{
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, NULL);
}
/* static */ bool ScriptStoryPage::Show(StoryPageID story_page_id)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
@@ -138,3 +164,11 @@
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_REMOVE_STORY_PAGE);
}
/* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id)
{
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);
}

View File

@@ -126,7 +126,7 @@ public:
* @param story_page_id The story page to get the sort value of.
* @return Page sort value.
*/
static uint32 GetPageSort(StoryPageID story_page_id);
static uint32 GetPageSortValue(StoryPageID story_page_id);
/**
* Get story page element sort value. Each page element has a sort value that is internally
@@ -137,7 +137,34 @@ public:
* @param story_page_element_id The story page element to get the sort value of.
* @return Page element sort value.
*/
static uint32 GetPageElementSort(StoryPageElementID story_page_element_id);
static uint32 GetPageElementSortValue(StoryPageElementID story_page_element_id);
/**
* Get the company which the page belongs to. If the page is global,
* ScriptCompany::COMPANY_INVALID is returned.
* @param story_page_id The story page to get the company for.
* @return owner company or ScriptCompany::COMPANY_INVALID
* @pre IsValidStoryPage(story_page_id).
*/
static ScriptCompany::CompanyID GetCompany(StoryPageID story_page_id);
/**
* Get the page date which is displayed at the top of each page.
* @param story_page_id The story page to get the date of.
* @return The date
* @pre IsValidStoryPage(story_page_id).
*/
static int32 GetDate(StoryPageID story_page_id);
/**
* Update date of a story page. The date is shown in the top left of the page
* @param story_page_id The story page to set the date for.
* @param date Page date (@see ScriptDate)
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre IsValidStoryPage(story_page_id).
*/
static bool SetDate(StoryPageID story_page_id, int32 date);
/**
* Update title of a story page. The title is shown in the page selector drop down.
@@ -169,6 +196,15 @@ public:
* @pre IsValidStoryPage(story_page_id).
*/
static bool Remove(StoryPageID story_page_id);
/**
* Removes a story page element.
* @param story_page_element_id The story page element to remove.
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre IsValidStoryPageElement(story_page_element_id).
*/
static bool RemoveElement(StoryPageElementID story_page_element_id);
};
#endif /* SCRIPT_STORY_HPP */