Use events for calls to async native functions

This commit is contained in:
Tyler Hallada 2020-10-15 23:42:57 -04:00
parent 4c9ab4bef2
commit 561b9574b6
32 changed files with 113 additions and 61 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
scriptname BRClient scriptname BRClient
function Init() global native function Init() global native
bool function StatusCheck(string apiKey) global native bool function StatusCheck(string apiKey, quest quest) global native
string function GenerateApiKey() global native string function GenerateApiKey() global native

View File

@ -1,5 +1,5 @@
scriptname BRInteriorRefList scriptname BRInteriorRefList
int function Create(string apiUrl, string apiKey, int shop_id, cell cell) global native bool function Create(string apiUrl, string apiKey, int shop_id, quest quest) global native
bool function ClearCell(cell cell) global native bool function ClearCell() global native
bool function Load(string apiUrl, string apiKey, int interior_ref_id, cell cell, ObjectReference player) global native bool function Load(string apiUrl, string apiKey, int interior_ref_id, ObjectReference player, quest quest) global native

View File

@ -71,6 +71,7 @@ endState
state START_MOD state START_MOD
event OnSelectST() event OnSelectST()
if BR.StartMod() if BR.StartMod()
Debug.Notification("Starting mod...")
modStarted = true modStarted = true
SetToggleOptionValueST(true, true) SetToggleOptionValueST(true, true)
SetOptionFlagsST(OPTION_FLAG_DISABLED, true) SetOptionFlagsST(OPTION_FLAG_DISABLED, true)
@ -87,7 +88,7 @@ endState
state SAVE_REFS state SAVE_REFS
event OnSelectST() event OnSelectST()
if BR.SaveInteriorRefs() if BR.SaveInteriorRefs()
debug.MessageBox("Successfully saved shop.") Debug.Notification("Saving shop...")
endif endif
endEvent endEvent
@ -99,7 +100,7 @@ endState
state LOAD_REFS state LOAD_REFS
event OnSelectST() event OnSelectST()
if BR.LoadInteriorRefs() if BR.LoadInteriorRefs()
debug.MessageBox("Successfully loaded shop.") Debug.Notification("Loading shop...")
endif endif
endEvent endEvent
@ -126,4 +127,8 @@ state LOAD_MERCH
event OnHighlightST() event OnHighlightST()
SetInfoText("Load shop merchandise onto the merchant shelf of the shop.") SetInfoText("Load shop merchandise onto the merchant shelf of the shop.")
endEvent endEvent
endState endState
event OnShopCreate(int result)
Debug.Trace("BRMCMConfigMenu OnShopCreate result: " + result)
endEvent

View File

@ -5,16 +5,11 @@ Quest Property BRQuest Auto
event OnMenuClose(string menuName) event OnMenuClose(string menuName)
if menuName == "ContainerMenu" if menuName == "ContainerMenu"
debug.Trace("BRMerchChestScript container menu closed") Debug.Trace("BRMerchChestScript container menu closed")
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
int result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self) bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self)
if result == -2 if !result
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.") 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
BRScript.MerchandiseListId = result;
Debug.Notification("Saved merchandise successfully")
endif endif
UnregisterForMenu("ContainerMenu") UnregisterForMenu("ContainerMenu")
endif endif
@ -22,7 +17,20 @@ endEvent
event OnActivate(ObjectReference akActionRef) event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
debug.Trace("BRMerchChestScript container was opened") Debug.Trace("BRMerchChestScript container was opened")
RegisterForMenu("ContainerMenu") RegisterForMenu("ContainerMenu")
endif endif
endEvent
event OnCreateMerchandise(int result)
Debug.Trace("BRMerchChestScript OnCreateMerchandise result: " + result)
if result == -2
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
BRScript.MerchandiseListId = result;
Debug.Notification("Saved merchandise successfully")
endif
endEvent endEvent

View File

@ -10,14 +10,14 @@ Activator property PlaceholderStatic auto
Actor property PlayerRef auto Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
Event OnActivate(ObjectReference akActionRef) event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
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 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.")
endif endif
endif endif
EndEvent endEvent

View File

@ -10,14 +10,14 @@ Activator property PlaceholderStatic auto
Actor property PlayerRef auto Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
Event OnActivate(ObjectReference akActionRef) event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
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 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.")
endif endif
endif endif
EndEvent endEvent

View File

@ -10,20 +10,20 @@ Activator property PlaceholderStatic auto
Actor property PlayerRef auto Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
Event OnActivate(ObjectReference akActionRef) event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
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. 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 endif
endif endif
EndEvent endEvent
Event OnLoadMerchandise(bool result) event OnLoadMerchandise(bool result)
debug.Trace("BRMerchToggleScript OnLoadMerchandise result: " + result) Debug.Trace("BRMerchToggleScript OnLoadMerchandise result: " + result)
if 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)
@ -33,4 +33,4 @@ Event OnLoadMerchandise(bool result)
else 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.") 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.")
endif endif
EndEvent endEvent

View File

@ -9,4 +9,4 @@ bool function Replace3D(ObjectReference merchantShelf, Form placeholderStatic, K
Form function Buy(ObjectReference merchandisePlaceholder) global native Form function Buy(ObjectReference merchandisePlaceholder) global native
int function Create(string apiUrl, string apiKey, int shopId, ObjectReference merchantChest) global native bool function Create(string apiUrl, string apiKey, int shopId, ObjectReference merchantChest) global native

View File

@ -1,3 +1,3 @@
scriptname BROwner scriptname BROwner
int function Create(string apiUrl, string apiKey, string name, int modVersion) global native bool function Create(string apiUrl, string apiKey, string name, int modVersion, quest quest) global native

View File

@ -36,36 +36,56 @@ endFunction
bool function StartMod() bool function StartMod()
debug.Trace("BRQuestScript StartMod") debug.Trace("BRQuestScript StartMod")
bool result = BRClient.StatusCheck(ApiUrl) bool result = BRClient.StatusCheck(ApiUrl, self)
if result if !result
ApiKey = BRClient.GenerateApiKey()
Debug.Trace("apiKey: " + ApiKey)
Debug.Trace("apiUrl: " + ApiUrl)
string playerName = Game.GetPlayer().GetBaseObject().GetName()
OwnerId = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion)
if OwnerId > -1
ShopId = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop")
if ShopId > -1
Debug.Notification("Initialized Bazaar Realm client")
else
result = false
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.")
endif
else
result = false
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.")
endif
else
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl) Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl)
endif endif
return result return result
endFunction endFunction
event OnStatusCheck(bool result)
Debug.Trace("BRQuestScript OnStatusCheck result: " + result)
if result
ApiKey = BRClient.GenerateApiKey()
Debug.Trace("apiKey: " + ApiKey)
Debug.Trace("apiUrl: " + ApiUrl)
string playerName = PlayerRef.GetBaseObject().GetName()
bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self)
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.")
endif
else
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl)
endif
endEvent
event OnCreateOwner(int result)
Debug.Trace("BRQuestScript OnCreateOwner result: " + result)
string playerName = PlayerRef.GetBaseObject().GetName()
if result > -1
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.")
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.")
endif
endEvent
event OnCreateShop(int result)
Debug.Trace("BRQuestScript OnCreateShop result: " + result)
if result > -1
ShopId = result
Debug.Notification("Initialized Bazaar Realm client")
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.")
endif
endEvent
bool function SaveInteriorRefs() bool function SaveInteriorRefs()
; TODO: this should not save anything if player is not currently in their shop ; TODO: this should not save anything if player is not currently in their shop
Cell currentCell = PlayerRef.GetParentCell() bool result = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, self)
InteriorRefListId = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, currentCell)
Debug.Trace("Interior ref list id: " + interiorRefListId)
; Int numRefs = currentCell.GetNumRefs() ; Int numRefs = currentCell.GetNumRefs()
; debug.Trace("Num of refs in current cell: " + numRefs) ; debug.Trace("Num of refs in current cell: " + numRefs)
; Int refIndex = 0 ; Int refIndex = 0
@ -102,8 +122,7 @@ bool function SaveInteriorRefs()
; debug.Trace("Ref " + refIndex) ; debug.Trace("Ref " + refIndex)
; refIndex += 1 ; refIndex += 1
; endWhile ; endWhile
debug.Trace("Done looping through refs") if result
if InteriorRefListId > -1
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. 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.")
@ -111,13 +130,24 @@ bool function SaveInteriorRefs()
endif endif
endFunction endFunction
event OnCreateInteriorRefList(int result)
Debug.Trace("BRQuestSCript OnCreateInteriorRefList result: " + result)
if result > -1
InteriorRefListId = result
Debug.MessageBox("Successfully saved shop.")
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.")
endif
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 save anything if player is not currently in their shop
Cell currentCell = PlayerRef.GetParentCell() bool result = BRInteriorRefList.ClearCell()
bool result = BRInteriorRefList.ClearCell(currentCell) if !result
debug.Trace("ClearCell result: " + 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.")
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, currentCell, ShopXMarker) endif
debug.Trace("Done loading interior refs from API") Debug.Trace("ClearCell result: " + result)
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, self)
if result if result
return true return true
else else
@ -126,6 +156,15 @@ bool function LoadInteriorRefs()
endif endif
endFunction endFunction
event OnLoadInteriorRefList(bool result)
Debug.Trace("BRQuestSCript OnLoadInteriorRefList result: " + result)
if result
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
int function ListMerchandise() int function ListMerchandise()
string[] options = new string[5] string[] options = new string[5]
options[0] = "First Item" options[0] = "First Item"

View File

@ -1,3 +1,3 @@
scriptname BRShop scriptname BRShop
int function Create(string apiUrl, string apiKey, string name, string description = "") global native bool function Create(string apiUrl, string apiKey, string name, string description = "", quest quest) global native