Use events for calls to async native functions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
scriptname BRClient
|
||||
|
||||
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
|
||||
@@ -1,5 +1,5 @@
|
||||
scriptname BRInteriorRefList
|
||||
|
||||
int function Create(string apiUrl, string apiKey, int shop_id, cell cell) global native
|
||||
bool function ClearCell(cell cell) global native
|
||||
bool function Load(string apiUrl, string apiKey, int interior_ref_id, cell cell, ObjectReference player) global native
|
||||
bool function Create(string apiUrl, string apiKey, int shop_id, quest quest) global native
|
||||
bool function ClearCell() global native
|
||||
bool function Load(string apiUrl, string apiKey, int interior_ref_id, ObjectReference player, quest quest) global native
|
||||
@@ -71,6 +71,7 @@ endState
|
||||
state START_MOD
|
||||
event OnSelectST()
|
||||
if BR.StartMod()
|
||||
Debug.Notification("Starting mod...")
|
||||
modStarted = true
|
||||
SetToggleOptionValueST(true, true)
|
||||
SetOptionFlagsST(OPTION_FLAG_DISABLED, true)
|
||||
@@ -87,7 +88,7 @@ endState
|
||||
state SAVE_REFS
|
||||
event OnSelectST()
|
||||
if BR.SaveInteriorRefs()
|
||||
debug.MessageBox("Successfully saved shop.")
|
||||
Debug.Notification("Saving shop...")
|
||||
endif
|
||||
endEvent
|
||||
|
||||
@@ -99,7 +100,7 @@ endState
|
||||
state LOAD_REFS
|
||||
event OnSelectST()
|
||||
if BR.LoadInteriorRefs()
|
||||
debug.MessageBox("Successfully loaded shop.")
|
||||
Debug.Notification("Loading shop...")
|
||||
endif
|
||||
endEvent
|
||||
|
||||
@@ -126,4 +127,8 @@ state LOAD_MERCH
|
||||
event OnHighlightST()
|
||||
SetInfoText("Load shop merchandise onto the merchant shelf of the shop.")
|
||||
endEvent
|
||||
endState
|
||||
endState
|
||||
|
||||
event OnShopCreate(int result)
|
||||
Debug.Trace("BRMCMConfigMenu OnShopCreate result: " + result)
|
||||
endEvent
|
||||
@@ -5,16 +5,11 @@ Quest Property BRQuest Auto
|
||||
|
||||
event OnMenuClose(string menuName)
|
||||
if menuName == "ContainerMenu"
|
||||
debug.Trace("BRMerchChestScript container menu closed")
|
||||
Debug.Trace("BRMerchChestScript container menu closed")
|
||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||
int result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self)
|
||||
if result == -2
|
||||
Debug.Trace("BRMerchChestScript no container changes to save to the server")
|
||||
elseif result == -1
|
||||
bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, self)
|
||||
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.")
|
||||
else
|
||||
BRScript.MerchandiseListId = result;
|
||||
Debug.Notification("Saved merchandise successfully")
|
||||
endif
|
||||
UnregisterForMenu("ContainerMenu")
|
||||
endif
|
||||
@@ -22,7 +17,20 @@ endEvent
|
||||
|
||||
event OnActivate(ObjectReference akActionRef)
|
||||
if akActionRef == PlayerRef
|
||||
debug.Trace("BRMerchChestScript container was opened")
|
||||
Debug.Trace("BRMerchChestScript container was opened")
|
||||
RegisterForMenu("ContainerMenu")
|
||||
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
|
||||
@@ -10,14 +10,14 @@ Activator property PlaceholderStatic auto
|
||||
Actor property PlayerRef auto
|
||||
Quest Property BRQuest Auto
|
||||
|
||||
Event OnActivate(ObjectReference akActionRef)
|
||||
event OnActivate(ObjectReference akActionRef)
|
||||
if akActionRef == PlayerRef
|
||||
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||
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
|
||||
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
|
||||
EndEvent
|
||||
endEvent
|
||||
@@ -10,14 +10,14 @@ Activator property PlaceholderStatic auto
|
||||
Actor property PlayerRef auto
|
||||
Quest Property BRQuest Auto
|
||||
|
||||
Event OnActivate(ObjectReference akActionRef)
|
||||
event OnActivate(ObjectReference akActionRef)
|
||||
if akActionRef == PlayerRef
|
||||
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||
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
|
||||
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
|
||||
EndEvent
|
||||
endEvent
|
||||
@@ -10,20 +10,20 @@ Activator property PlaceholderStatic auto
|
||||
Actor property PlayerRef auto
|
||||
Quest Property BRQuest Auto
|
||||
|
||||
Event OnActivate(ObjectReference akActionRef)
|
||||
event OnActivate(ObjectReference akActionRef)
|
||||
if akActionRef == PlayerRef
|
||||
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||
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
|
||||
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
|
||||
|
||||
Event OnLoadMerchandise(bool result)
|
||||
debug.Trace("BRMerchToggleScript OnLoadMerchandise result: " + result)
|
||||
event OnLoadMerchandise(bool result)
|
||||
Debug.Trace("BRMerchToggleScript OnLoadMerchandise result: " + result)
|
||||
if result
|
||||
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||
while !BRMerchandiseList.Replace3D(MerchantShelf, PlaceholderStatic, BRLinkMerchShelf, BRLinkItemRef)
|
||||
@@ -33,4 +33,4 @@ Event OnLoadMerchandise(bool result)
|
||||
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.")
|
||||
endif
|
||||
EndEvent
|
||||
endEvent
|
||||
@@ -9,4 +9,4 @@ bool function Replace3D(ObjectReference merchantShelf, Form placeholderStatic, K
|
||||
|
||||
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
|
||||
@@ -1,3 +1,3 @@
|
||||
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
|
||||
@@ -36,36 +36,56 @@ endFunction
|
||||
|
||||
bool function StartMod()
|
||||
debug.Trace("BRQuestScript StartMod")
|
||||
bool result = BRClient.StatusCheck(ApiUrl)
|
||||
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
|
||||
bool result = BRClient.StatusCheck(ApiUrl, self)
|
||||
if !result
|
||||
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl)
|
||||
endif
|
||||
return result
|
||||
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()
|
||||
; TODO: this should not save anything if player is not currently in their shop
|
||||
Cell currentCell = PlayerRef.GetParentCell()
|
||||
InteriorRefListId = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, currentCell)
|
||||
Debug.Trace("Interior ref list id: " + interiorRefListId)
|
||||
bool result = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, self)
|
||||
; Int numRefs = currentCell.GetNumRefs()
|
||||
; debug.Trace("Num of refs in current cell: " + numRefs)
|
||||
; Int refIndex = 0
|
||||
@@ -102,8 +122,7 @@ bool function SaveInteriorRefs()
|
||||
; debug.Trace("Ref " + refIndex)
|
||||
; refIndex += 1
|
||||
; endWhile
|
||||
debug.Trace("Done looping through refs")
|
||||
if InteriorRefListId > -1
|
||||
if result
|
||||
return true
|
||||
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.")
|
||||
@@ -111,13 +130,24 @@ bool function SaveInteriorRefs()
|
||||
endif
|
||||
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()
|
||||
; TODO: this should not save anything if player is not currently in their shop
|
||||
Cell currentCell = PlayerRef.GetParentCell()
|
||||
bool result = BRInteriorRefList.ClearCell(currentCell)
|
||||
debug.Trace("ClearCell result: " + result)
|
||||
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, currentCell, ShopXMarker)
|
||||
debug.Trace("Done loading interior refs from API")
|
||||
bool result = BRInteriorRefList.ClearCell()
|
||||
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.")
|
||||
endif
|
||||
Debug.Trace("ClearCell result: " + result)
|
||||
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, self)
|
||||
if result
|
||||
return true
|
||||
else
|
||||
@@ -126,6 +156,15 @@ bool function LoadInteriorRefs()
|
||||
endif
|
||||
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()
|
||||
string[] options = new string[5]
|
||||
options[0] = "First Item"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
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
|
||||
Reference in New Issue
Block a user