Refactor API calls to use success/fail events

All async native function calls now respond on separate success & fail events.

Improve error messages and save `BugReportCopy` in one place on BRQuestScript.
This commit is contained in:
Tyler Hallada 2020-10-18 20:56:10 -04:00
parent cd9d11edfd
commit e6a4b19f5a
5 changed files with 84 additions and 70 deletions

View File

@ -9,7 +9,7 @@ event OnMenuClose(string menuName)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self) bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self)
if !result if !result
Debug.MessageBox("Failed to save shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to save shop merchandise.\n\n" + BRScript.BugReportCopy)
endif endif
UnregisterForMenu("ContainerMenu") UnregisterForMenu("ContainerMenu")
endif endif
@ -22,15 +22,19 @@ event OnActivate(ObjectReference akActionRef)
endif endif
endEvent endEvent
event OnCreateMerchandise(int result) event OnCreateMerchandiseSuccess(bool created, int id)
Debug.Trace("BRMerchChestScript OnCreateMerchandise result: " + result) Debug.Trace("BRMerchChestScript OnCreateMerchandiseSuccess created: " + created + " id: " + id)
if result == -2 if created
Debug.Trace("BRMerchChestScript no container changes to save to the server")
elseif result == -1
Debug.MessageBox("Failed to save shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
else
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
BRScript.MerchandiseListId = result; BRScript.MerchandiseListId = id;
Debug.Notification("Saved merchandise successfully") Debug.Notification("Saved merchandise successfully")
else
Debug.Trace("BRMerchChestScript no container changes to save to the server")
endif endif
endEvent
event OnCreateMerchandiseFail(string error)
Debug.Trace("BRMerchChestScript OnCreateMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to save shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent endEvent

View File

@ -17,7 +17,7 @@ event OnActivate(ObjectReference akActionRef)
bool result = BRMerchandiseList.NextPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) bool result = BRMerchandiseList.NextPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev)
Debug.Trace("BRMerchandiseList.NextPage result: " + result) Debug.Trace("BRMerchandiseList.NextPage result: " + result)
if !result if !result
Debug.MessageBox("Failed to load shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
endif endif
endif endif
endEvent endEvent

View File

@ -17,7 +17,7 @@ event OnActivate(ObjectReference akActionRef)
bool result = BRMerchandiseList.PrevPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) bool result = BRMerchandiseList.PrevPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev)
Debug.Trace("BRMerchandiseList.PrevPage result: " + result) Debug.Trace("BRMerchandiseList.PrevPage result: " + result)
if !result if !result
Debug.MessageBox("Failed to load shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
endif endif
endif endif
endEvent endEvent

View File

@ -17,20 +17,22 @@ event OnActivate(ObjectReference akActionRef)
bool result = BRMerchandiseList.Toggle(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) bool result = BRMerchandiseList.Toggle(BRScript.ApiUrl, BRScript.ApiKey, BRScript.MerchandiseListId, MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev)
Debug.Trace("BRMerchandiseList.Toggle result: " + result) Debug.Trace("BRMerchandiseList.Toggle result: " + result)
if !result if !result
Debug.MessageBox("Failed to load or clear shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
endif endif
endif endif
endEvent endEvent
event OnLoadMerchandise(bool result) event OnLoadMerchandiseSuccess(bool result)
Debug.Trace("BRMerchToggleScript OnLoadMerchandise result: " + result) Debug.Trace("BRMerchToggleScript OnLoadMerchandiseSuccess result: " + result)
if result ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) while !BRMerchandiseList.Replace3D(MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkItemRef)
while !BRMerchandiseList.Replace3D(MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkItemRef) Debug.Trace("BRMerchandiseList.Replace3D returned false, waiting and trying again")
Debug.Trace("BRMerchandiseList.Replace3D returned false, waiting and trying again") Utility.Wait(0.05)
Utility.Wait(0.05) endWhile
endWhile endEvent
else
Debug.MessageBox("Failed to load or clear shop merchandise. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") event OnLoadMerchandiseFail(string error)
endif Debug.Trace("BRMerchToggleScript OnLoadMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent endEvent

View File

@ -10,13 +10,14 @@ int property ShopId auto
string property ShopName auto string property ShopName auto
string property ShopDescription auto string property ShopDescription auto
; TODO: loop up interior refs by shop id instead of saving this ; TODO: loop up interior refs by shop id instead of saving this
int property InteriorRefListId = 29 auto ; TODO: temp fixing to id 20 int property InteriorRefListId auto ; TODO: temp fixing to id 20
int property MerchandiseListId = 2 auto ; TODO: temp fixing to id 2 int property MerchandiseListId auto ; TODO: temp fixing to id 2
ObjectReference property ShopXMarker auto ObjectReference property ShopXMarker auto
bool property StartModFailed = false auto bool property StartModFailed = false auto
bool property UpdateShopComplete = false auto bool property UpdateShopComplete = false auto
bool property GetShopComplete = false auto bool property GetShopComplete = false auto
UILIB_1 property UILib auto UILIB_1 property UILib auto
string property BugReportCopy = "Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE." auto
int function GetVersion() int function GetVersion()
return 1 return 1
@ -31,7 +32,7 @@ function Maintenance()
Debug.Trace("BRQuestScript Maintenance") Debug.Trace("BRQuestScript Maintenance")
UILib = (Self as Form) as UILIB_1 UILib = (Self as Form) as UILIB_1
if !BRClient.Init() if !BRClient.Init()
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please ensure that the folder Documents\\My Games\\Skyrim Special Edition\\SKSE exists and is accessible by Skyrim.") Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\nPlease ensure that the folder Documents\\My Games\\Skyrim Special Edition\\SKSE exists and is accessible by Skyrim.")
endif endif
int newVersion = GetVersion() int newVersion = GetVersion()
if ModVersion < newVersion if ModVersion < newVersion
@ -46,14 +47,14 @@ bool function StartMod()
StartModFailed = false StartModFailed = false
bool result = BRClient.StatusCheck(ApiUrl, self) bool result = BRClient.StatusCheck(ApiUrl, self)
if !result if !result
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl) Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\nThe API server might be down: " + ApiUrl)
StartModFailed = true StartModFailed = true
endif endif
return result return result
endFunction endFunction
event OnStatusCheck(bool result) event OnStatusCheckSuccess(bool result)
Debug.Trace("BRQuestScript OnStatusCheck result: " + result) Debug.Trace("BRQuestScript OnStatusCheckSuccess result: " + result)
if result if result
ApiKey = BRClient.GenerateApiKey() ApiKey = BRClient.GenerateApiKey()
Debug.Trace("apiKey: " + ApiKey) Debug.Trace("apiKey: " + ApiKey)
@ -61,29 +62,33 @@ event OnStatusCheck(bool result)
string playerName = PlayerRef.GetBaseObject().GetName() string playerName = PlayerRef.GetBaseObject().GetName()
bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self) bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self)
if !ownerResult if !ownerResult
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to create new owner in the API.\n\n" + BugReportCopy)
StartModFailed = true StartModFailed = true
endif endif
else endif
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl) endEvent
event OnStatusCheckFail(string error)
Debug.Trace("BRQuestScript OnStatusCheckFail error: " + error)
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\nThe API server might be down: " + ApiUrl)
StartModFailed = true
endEvent
event OnCreateOwnerSuccess(int id)
Debug.Trace("BRQuestScript OnCreateOwnerSuccess id: " + id)
string playerName = PlayerRef.GetBaseObject().GetName()
OwnerId = id
bool shopResult = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop", "", self)
if !shopResult
Debug.MessageBox("Failed to create new shop in the API.\n\n" + BugReportCopy)
StartModFailed = true StartModFailed = true
endif endif
endEvent endEvent
event OnCreateOwner(int result) event OnCreateOwnerFail(string error)
Debug.Trace("BRQuestScript OnCreateOwner result: " + result) Debug.Trace("BRQuestScript OnCreateOwnerFail error: " + error)
string playerName = PlayerRef.GetBaseObject().GetName() Debug.MessageBox("Failed to create new owner in the API.\n\n" + error + "\n\n" + BugReportCopy)
if result > -1 StartModFailed = true
OwnerId = result
bool shopResult = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop", "", self)
if !shopResult
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif
else
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif
endEvent endEvent
event OnCreateShopSuccess(int id, string name, string description) event OnCreateShopSuccess(int id, string name, string description)
@ -96,7 +101,7 @@ endEvent
event OnCreateShopFail(string error) event OnCreateShopFail(string error)
Debug.Trace("BRQuestScript OnCreateShopFail error: " + error) Debug.Trace("BRQuestScript OnCreateShopFail error: " + error)
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\nPlease submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\n" + BugReportCopy)
StartModFailed = true StartModFailed = true
endEvent endEvent
@ -106,26 +111,27 @@ bool function SaveInteriorRefs()
if result if result
return true return true
else else
Debug.MessageBox("Failed to save shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to save shop.\n\n" + BugReportCopy)
return false return false
endif endif
endFunction endFunction
event OnCreateInteriorRefList(int result) event OnCreateInteriorRefListSuccess(int id)
Debug.Trace("BRQuestSCript OnCreateInteriorRefList result: " + result) Debug.Trace("BRQuestSCript OnCreateInteriorRefListSuccess id: " + id)
if result > -1 InteriorRefListId = id
InteriorRefListId = result Debug.MessageBox("Successfully saved shop.")
Debug.MessageBox("Successfully saved shop.") endEvent
else
Debug.MessageBox("Failed to save shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") event OnCreateInteriorRefListFail(string error)
endif Debug.Trace("BRQuestSCript OnCreateInteriorRefListFail error: " + error)
Debug.MessageBox("Failed to save shop.\n\n" + error + "\n\n" + BugReportCopy)
endEvent endEvent
bool function LoadInteriorRefs() bool function LoadInteriorRefs()
; TODO: this should not save anything if player is not currently in their shop ; TODO: this should not load anything if player is not currently in their shop
bool result = BRInteriorRefList.ClearCell() bool result = BRInteriorRefList.ClearCell()
if !result if !result
Debug.MessageBox("Failed to load shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to clear existing shop before loading in new shop.\n\n" + BugReportCopy)
endif endif
Debug.Trace("ClearCell result: " + result) Debug.Trace("ClearCell result: " + result)
@ -133,20 +139,22 @@ bool function LoadInteriorRefs()
if result if result
return true return true
else else
Debug.MessageBox("Failed to load shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy)
return false return false
endif endif
endFunction endFunction
event OnLoadInteriorRefList(bool result) event OnLoadInteriorRefListSuccess(bool result)
Debug.Trace("BRQuestSCript OnLoadInteriorRefList result: " + result) Debug.Trace("BRQuestSCript OnLoadInteriorRefListSuccess result: " + result)
if result Debug.MessageBox("Successfully loaded shop")
Debug.MessageBox("Successfully loaded shop")
else
Debug.MessageBox("Failed to load shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
endif
endEvent endEvent
event OnLoadInteriorRefListFail(string error)
Debug.Trace("BRQuestSCript OnLoadInteriorRefListFail error: " + error)
Debug.MessageBox("Failed to load shop.\n\n" + error + "\n\n" + BugReportCopy)
endEvent
; currently unused, was testing out UILib
int function ListMerchandise() int function ListMerchandise()
string[] options = new string[5] string[] options = new string[5]
options[0] = "First Item" options[0] = "First Item"
@ -164,7 +172,7 @@ function UpdateShop(int id, string name, string description)
UpdateShopComplete = false UpdateShopComplete = false
bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, self) bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, self)
if !result if !result
Debug.MessageBox("Failed to update shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to update shop.\n\n" + BugReportCopy)
UpdateShopComplete = true UpdateShopComplete = true
endif endif
endFunction endFunction
@ -179,7 +187,7 @@ endEvent
event OnUpdateShopFail(string error) event OnUpdateShopFail(string error)
Debug.Trace("BRQuestScript OnUpdateShopFail error: " + error) Debug.Trace("BRQuestScript OnUpdateShopFail error: " + error)
Debug.MessageBox("Failed to update shop.\n\n" + error + "\n\nPlease submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to update shop.\n\n" + error + "\n\n" + BugReportCopy)
UpdateShopComplete = true UpdateShopComplete = true
endEvent endEvent
@ -188,7 +196,7 @@ function GetShop(int id)
GetShopComplete = false GetShopComplete = false
bool result = BRShop.Get(ApiUrl, ApiKey, id, self) bool result = BRShop.Get(ApiUrl, ApiKey, id, self)
if !result if !result
Debug.MessageBox("Failed to get shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to get shop.\n\n" + BugReportCopy)
GetShopComplete = true GetShopComplete = true
endif endif
endFunction endFunction
@ -203,6 +211,6 @@ endEvent
event OnGetShopFail(string error) event OnGetShopFail(string error)
Debug.Trace("BRQuestScript OnGetShopFail error: " + error) Debug.Trace("BRQuestScript OnGetShopFail error: " + error)
Debug.MessageBox("Failed to get shop.\n\n" + error + "\n\nPlease submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to get shop.\n\n" + error + "\n\n" + BugReportCopy)
GetShopComplete = true GetShopComplete = true
endEvent endEvent