Playfab Shop Handling

This commit is contained in:
ZackRhodes 2022-12-09 23:32:16 -05:00
parent 9a272cc7b1
commit 3b303dc129
5 changed files with 65 additions and 11 deletions

View File

@ -50,6 +50,7 @@ function playFabLoginCallback(data, error) {
if (data) {
//NOTE: SAVE 'playFabId' to a global variable somewhere, I just declare mine at the start of the playfab stuff. Use this variable to tell if your player is logged in to playfab or not.
playFabId = data.data.PlayFabId;
PlayFab.PlayFabID = playFabId
GameUI.notify.info("Logged in to PlayFab Cloud");
PlayFab.ClientApi.UpdateUserTitleDisplayName({"DisplayName": Steam.getSteamId().screenName})

View File

@ -212,7 +212,7 @@ export const Cloud = {
displayName: steamOn ? Steam.getSteamId().screenName : "",//user.displayName,
email: user.email,
};
//ShopPurchaseData.syncSTD();
SteamFunctions.SyncPlayFabSTD()
} else {
this.user = null;
}

View File

@ -5,6 +5,8 @@ const SteamFunctions = {
purchaseChecker: [],
purchasesInitiated: true,
macUser: false,
macInterval: 0,
macIntervalOn: false,
SteamInitialize() {
this.forceRefresh();
//this.BackfillAchievements();
@ -105,6 +107,11 @@ const SteamFunctions = {
SteamFunctions.purchaseChecker.push(purchaseResult.data.OrderId);
if (window.navigator.platform === "MacIntel") {
shell.openExternal("https://store.steampowered.com/checkout/approvetxn/" + txnID + "/?returnurl=steam");
SteamFunctions.macInterval = setInterval(async()=>{
SteamFunctions.PurchaseValidation()
},2000)
SteamFunctions.macIntervalOn = true
setTimeout(()=>{clearInterval(SteamFunctions.macInterval);SteamFunctions.macIntervalOn = false},300000)
}
} else if (purchaseError !== null) {
console.log(purchaseError);
@ -127,10 +134,18 @@ const SteamFunctions = {
if (consumeResult !== null) {
console.log(consumeResult);
const stdsBought = Number(PurchaseName.replace("STD", ""));
const currencyAddRequest = {Amount: stdsBought,VirtualCurrency: "ST"}
PlayFab.ClientApi.AddUserVirtualCurrency(currencyAddRequest, (result, error) => {
if (result !== null) {
console.log(result);
ShopPurchaseData.totalSTD += stdsBought;
//player.IAP.totalSTD += stdsBought;
GameUI.notify.info(`${stdsBought} STDs Obtained!`);
} else if (error !== null) {
console.log(error);
}
})
SteamFunctions.purchaseChecker = SteamFunctions.purchaseChecker.filter(item => item !== OrderIdentifier);
GameUI.notify.info(`${stdsBought} STDs Obtained!`);
SteamFunctions.SyncPlayFabSTD()
} else if (consumeError !== null) {
console.log(consumeError);
}
@ -146,7 +161,40 @@ const SteamFunctions = {
anOrder => SteamFunctions.ConfirmSteamPurchase(anOrder)
);
}
},
SyncPlayFabSTD(){
PlayFab.ClientApi.GetUserInventory({PlayFabId: PlayFab.PlayFabId}, (result, error) => {
if (result !== null) {
console.log(result);
const CurrentSTD = result.data.VirtualCurrency.ST
const Inventory = result.data.Inventory
ShopPurchaseData.totalSTD = CurrentSTD
const inventoryData = {}
Inventory.forEach(
ShopItem => inventoryData[ShopItem.ItemId] = ShopItem.RemainingUses
);
for (const key of Object.keys(GameDatabase.shopPurchases)) ShopPurchaseData[key] = inventoryData[key] ?? 0;
GameUI.update();
} else if (error !== null) {
console.log(error);
}
})
},
PurchaseShopItem(itemCost,itemKey,itemConfig){
console.log(itemCost,itemKey,itemConfig)
const itemPurchaseRequest = {
ItemId: itemKey,
Price: itemCost,
VirtualCurrency: "ST"
}
PlayFab.ClientApi.PurchaseItem(itemPurchaseRequest, (result, error) => {
if (result !== null) {
console.log(result);
} else if (error !== null) {
console.log(error);
}
})
if (itemConfig.singleUse) itemConfig.onPurchase();
SteamFunctions.SyncPlayFabSTD();
}
};

View File

@ -1,4 +1,5 @@
<script>
import { purchase } from 'vue-gtag';
export default {
name: "ShopButton",
props: {
@ -21,6 +22,9 @@ export default {
this.nextMult = this.purchase.nextMultForDisplay;
this.canAfford = this.purchase.canBeBought;
this.iapDisabled = !ShopPurchaseData.isIAPEnabled;
},
TestPurchase(){
SteamFunctions.PurchaseShopItem(this.purchase.cost,this.purchase.config.key,this.purchase.config)
}
},
};
@ -42,7 +46,7 @@ export default {
<button
class="o-shop-button-button"
:class="{ 'o-shop-button-button--disabled': !canAfford }"
@click="purchase.purchase()"
@click="TestPurchase()"
>
Cost: {{ purchase.cost }}
<img

View File

@ -111,18 +111,19 @@ export default {
@click="toggleEnable()"
>
{{ enableText }}
Disable in-app-purchases
</PrimaryButton>
<PrimaryButton
<!--PrimaryButton
v-tooltip="respecText"
:class="respecClass()"
@click="respec()"
>
Respec Shop
</PrimaryButton>
</PrimaryButton-->
</div>
<div v-if="!canRespec">
<!--div v-if="!canRespec">
Time until respec available: {{ respecTimeStr }}
</div>
</div-->
<div
v-if="loggedIn"
class="c-login-info"