Skip to content

Commit 671cdcf

Browse files
committed
Revert "fix: simplified formatPrice"
This reverts commit 22710e8.
1 parent 22710e8 commit 671cdcf

File tree

8 files changed

+45
-113
lines changed

8 files changed

+45
-113
lines changed

Assets/PlayroomKit/PlayroomKit.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using UBB;
55
using Discord;
6-
using System.Runtime.InteropServices;
76

87

98
namespace Playroom
@@ -373,19 +372,11 @@ public void GetDiscordEntitlements(Action<List<DiscordEntitlement>> callback)
373372
_playroomService.GetDiscordEntitlements(callback);
374373
}
375374

376-
// public void DiscordPriceFormat(DiscordSkuPrice skuPrice, string locale, Action<string> callback)
377-
// {
378-
// CheckPlayRoomInitialized();
379-
// _playroomService.DiscordPriceFormat(skuPrice.Amount, skuPrice.Currency, locale, callback);
380-
// }
381-
382-
public string DiscordFormatPrice(DiscordSkuPrice skuPrice, string locale = "en-US")
375+
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback)
383376
{
384377
CheckPlayRoomInitialized();
385-
return DiscordPriceFormatInternal(skuPrice.Amount, skuPrice.Currency, locale);
378+
_playroomService.DiscordPriceFormat(price, currency, locale, callback);
386379
}
387-
388-
389380
#endregion
390381
}
391382
}

Assets/PlayroomKit/modules/Headers.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ private static extern string GetPersistentDataInternal(string key,
179179
[DllImport("__Internal")]
180180
private static extern void GetDiscordEntitlementsInternal(Action<string> callback);
181181

182-
// [DllImport("__Internal")]
183-
// private static extern void DiscordPriceFormatInternal(float price, string currency, string locale, Action<string> callback);
184-
185182
[DllImport("__Internal")]
186-
private static extern string DiscordPriceFormatInternal(int price, string currency, string locale);
183+
private static extern string DiscordPriceFormatInternal(float price, string currency, string locale, Action<string> callback);
184+
187185
#endregion
188186
}
189187
}

Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul
7676
public void StartDiscordPurchase(string skuId, Action<string> callback = null);
7777
public void GetDiscordSkus(Action<List<DiscordSku>> callback);
7878
public void GetDiscordEntitlements(Action<List<DiscordEntitlement>> callback);
79-
public string DiscordFormatPrice(int price, string currency, string locale);
79+
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback);
8080
#endregion
8181

8282

Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ public void GetDiscordEntitlements(Action<List<DiscordEntitlement>> callback)
338338
callback?.Invoke(new List<DiscordEntitlement>());
339339
}
340340

341-
public string DiscordFormatPrice(int price, string currency, string locale)
341+
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback)
342342
{
343343
DebugLogger.LogWarning("[MockMode] Discord SKUs are currently not supported in browser mock mode!");
344-
return $"${price}";
344+
callback?.Invoke("");
345345
}
346346
#endregion
347347
}

Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ public void GetDiscordEntitlements(Action<List<DiscordEntitlement>> callback)
238238
callback?.Invoke(new List<DiscordEntitlement>());
239239
}
240240

241-
public string DiscordFormatPrice(int price, string currency, string locale)
241+
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback)
242242
{
243243
DebugLogger.LogWarning("[MockMode] Discord SKUs are currently not supported in local mode!");
244-
return $"${price}";
244+
callback?.Invoke($"${price}");
245245
}
246246
#endregion
247247
}

Assets/PlayroomKit/modules/PlayroomBuildService.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,23 @@ private static void DiscordEntitlementsCallback(string data)
496496
throw;
497497
}
498498
}
499-
500-
public string DiscordFormatPrice(int price, string currency, string locale)
499+
500+
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback)
501501
{
502502
CheckPlayRoomInitialized();
503-
return DiscordPriceFormatInternal(price, currency, locale);
503+
504+
Debug.Log($"[Unity]: price {price}, currency {currency}, locale {locale}");
505+
506+
CallbackManager.RegisterCallback(callback, "formattedPrice");
507+
DiscordPriceFormatInternal(price, currency, locale, DiscordPriceFormatCallbackInvoker);
508+
}
509+
510+
[MonoPInvokeCallback(typeof(Action<string>))]
511+
private static void DiscordPriceFormatCallbackInvoker(string formattedPrice)
512+
{
513+
Debug.LogWarning($"UNITY: {formattedPrice}");
514+
515+
CallbackManager.InvokeCallback("formattedPrice", formattedPrice);
504516
}
505517
#endregion
506518

Assets/PlayroomKit/src/index.js

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,54 +1172,28 @@ mergeInto(LibraryManager.library, {
11721172
});
11731173

11741174
},
1175-
1176-
// callback variant
1177-
/* DiscordPriceFormatInternal: function(amount, currencyOrPtr, localeOrPtr, callbackPtr) {
1178-
var currency = (typeof currencyOrPtr === 'string')
1179-
? currencyOrPtr
1180-
: UTF8ToString(currencyOrPtr);
1181-
var locale = (typeof localeOrPtr === 'string')
1182-
? localeOrPtr
1183-
: UTF8ToString(localeOrPtr);
1184-
console.warn("[jslib] args received:", amount, currency, locale);
1185-
Playroom.getDiscordSDK().then(discordSDK => {
1186-
var formatted = discordSDK.PriceUtils.formatPrice(
1187-
{ amount: amount, currency: currency },
1188-
locale
1189-
);
1190-
console.warn("[jslib] formatted:", formatted);
1191-
{{{ makeDynCall("vi", "callbackPtr") }}}(stringToNewUTF8(formatted));
1192-
}).catch(err => {
1193-
console.error("Discord SDK load failed:", err);
1194-
{{{ makeDynCall("vi", "callbackPtr") }}}(0);
1195-
});
1196-
},
1197-
*/
11981175

1199-
DiscordPriceFormatInternal: function(amount, currencyOrPtr, localeOrPtr) {
1200-
var currency = (typeof currencyOrPtr === 'string')
1201-
? currencyOrPtr
1202-
: UTF8ToString(currencyOrPtr);
1203-
var locale = (typeof localeOrPtr === 'string')
1204-
? localeOrPtr
1205-
: UTF8ToString(localeOrPtr);
1206-
1207-
console.warn("[jslib] args received:", amount, currency, locale);
1208-
1209-
try {
1210-
var formatted = Playroom.getDiscordSDK().PriceUtils.formatPrice(
1211-
{ amount: amount, currency: currency },
1212-
locale
1176+
DiscordPriceFormatInternal: function (amount, currency, locale) {
1177+
if (!window.Playroom) {
1178+
console.error(
1179+
"Playroom library is not loaded. Please make sure to call InsertCoin first."
12131180
);
1214-
1215-
var bufferSize = lengthBytesUTF8(formatted) + 1;
1216-
var buffer = _malloc(bufferSize);
1217-
stringToUTF8(formatted, buffer, bufferSize);
1218-
return buffer;
1219-
} catch (err) {
1220-
console.error("[JSLIB] error while formatting prices:", err);
12211181
return 0;
12221182
}
1183+
1184+
Playroom.getDiscordSDK().then(discordSDK => {
1185+
var a = UTF8ToString(amount);
1186+
var c = UTF8ToString(currency);
1187+
var l = UTF8ToString(locale);
1188+
var formatted = discordSDK.PriceUtils.formatPrice({price: a, currency: c}, l);
1189+
console.log(formatted);
1190+
var bufferSize = lengthBytesUTF8(str) + 1;
1191+
var buffer = _malloc(bufferSize);
1192+
stringToUTF8(str, buffer, bufferSize);
1193+
return buffer;
1194+
}).catch(err => {
1195+
console.error("Failed to load Discord SDK:", err);
1196+
});
12231197
},
12241198
//#endregion
12251199

Assets/Scripts/GameManager.cs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,6 @@ void Awake()
8383
baseUrl = "https://ws.joinplayroom.com/api/store";
8484
}
8585

86-
// Initialize fake Discord SKUs
87-
discordSkus = new List<DiscordSku>
88-
{
89-
new DiscordSku
90-
{
91-
Id = "premium_pack_1",
92-
Name = "Premium Pack",
93-
Type = DiscordSkuType.APPLICATION,
94-
ApplicationId = "123456789",
95-
Price = new DiscordSkuPrice { Amount = 999, Currency = "USD" }
96-
},
97-
new DiscordSku
98-
{
99-
Id = "starter_pack",
100-
Name = "Starter Pack",
101-
Type = DiscordSkuType.APPLICATION,
102-
ApplicationId = "123456789",
103-
Price = new DiscordSkuPrice { Amount = 499, Currency = "USD" }
104-
},
105-
new DiscordSku
106-
{
107-
Id = "deluxe_edition",
108-
Name = "Deluxe Edition",
109-
Type = DiscordSkuType.APPLICATION,
110-
ApplicationId = "123456789",
111-
Price = new DiscordSkuPrice { Amount = 1999, Currency = "USD" }
112-
}
113-
};
114-
11586
playroomKit = new PlayroomKit();
11687
}
11788

@@ -188,19 +159,12 @@ private void Update()
188159
});
189160
}
190161

191-
if (Input.GetKeyDown(KeyCode.R))
192-
{
193-
194-
}
195-
196162
if (Input.GetKeyDown(KeyCode.F))
197163
{
198-
text.text = "";
199-
200164
discordSkus.ForEach((sku) =>
201165
{
202-
Debug.LogWarning($"{sku.Name}: {playroomKit.DiscordFormatPrice(sku.Price)}");
203-
text.text += playroomKit.DiscordFormatPrice(sku.Price);
166+
Debug.LogWarning($"{sku.Name}: {playroomKit.DiscordPriceFormat(sku.Price.Amount, sku.Price.Currency)}");
167+
text.text = playroomKit.DiscordPriceFormat(sku.Price.Amount, sku.Price.Currency);
204168
});
205169
}
206170

@@ -359,14 +323,7 @@ void DrawDiscordDebugWindow(int windowID)
359323
GUILayout.BeginVertical(GUI.skin.box);
360324
DrawInspectorField("Id", sku.Id);
361325
DrawInspectorField("Name", sku.Name);
362-
if (sku.Price != null)
363-
{
364-
GUILayout.Label("Price", EditorLabelBold());
365-
GUILayout.BeginVertical(GUI.skin.box);
366-
DrawInspectorField("Amount", sku.Price.Amount.ToString());
367-
DrawInspectorField("Currency", sku.Price.Currency);
368-
GUILayout.EndVertical();
369-
}
326+
DrawInspectorField("Price", sku.Price.ToString());
370327
DrawInspectorField("Type", sku.Type.ToString());
371328
DrawInspectorField("Application Id", sku.ApplicationId);
372329
GUILayout.EndVertical();

0 commit comments

Comments
 (0)