Skip to content

Commit d9a5296

Browse files
committed
fix: rollback to callback version
1 parent 671cdcf commit d9a5296

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

Assets/PlayroomKit/modules/PlayroomBuildService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,18 +500,13 @@ private static void DiscordEntitlementsCallback(string data)
500500
public void DiscordPriceFormat(float price, string currency, string locale, Action<string> callback)
501501
{
502502
CheckPlayRoomInitialized();
503-
504-
Debug.Log($"[Unity]: price {price}, currency {currency}, locale {locale}");
505-
506503
CallbackManager.RegisterCallback(callback, "formattedPrice");
507504
DiscordPriceFormatInternal(price, currency, locale, DiscordPriceFormatCallbackInvoker);
508505
}
509506

510507
[MonoPInvokeCallback(typeof(Action<string>))]
511508
private static void DiscordPriceFormatCallbackInvoker(string formattedPrice)
512509
{
513-
Debug.LogWarning($"UNITY: {formattedPrice}");
514-
515510
CallbackManager.InvokeCallback("formattedPrice", formattedPrice);
516511
}
517512
#endregion

Assets/PlayroomKit/src/index.js

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

11741174
},
1175-
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."
1180-
);
1181-
return 0;
1182-
}
1183-
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);
11841185
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;
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));
11941192
}).catch(err => {
1195-
console.error("Failed to load Discord SDK:", err);
1193+
console.error("Discord SDK load failed:", err);
1194+
{{{ makeDynCall("vi", "callbackPtr") }}}(0);
11961195
});
11971196
},
1197+
11981198
//#endregion
11991199

12001200

Assets/Scripts/GameManager.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,35 @@ 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+
86115
playroomKit = new PlayroomKit();
87116
}
88117

@@ -159,12 +188,17 @@ private void Update()
159188
});
160189
}
161190

191+
if (Input.GetKeyDown(KeyCode.R))
192+
{
193+
text.text = "";
194+
}
195+
162196
if (Input.GetKeyDown(KeyCode.F))
163197
{
164198
discordSkus.ForEach((sku) =>
165199
{
166-
Debug.LogWarning($"{sku.Name}: {playroomKit.DiscordPriceFormat(sku.Price.Amount, sku.Price.Currency)}");
167-
text.text = playroomKit.DiscordPriceFormat(sku.Price.Amount, sku.Price.Currency);
200+
Debug.LogWarning($"{sku.Name}: {sku.Price.Amount}, {sku.Price.Currency}");
201+
playroomKit.DiscordPriceFormat(sku.Price.Amount, sku.Price.Currency, "en-US", (formattedPrice) => text.text += $"{sku.Name} - {formattedPrice}");
168202
});
169203
}
170204

@@ -323,7 +357,14 @@ void DrawDiscordDebugWindow(int windowID)
323357
GUILayout.BeginVertical(GUI.skin.box);
324358
DrawInspectorField("Id", sku.Id);
325359
DrawInspectorField("Name", sku.Name);
326-
DrawInspectorField("Price", sku.Price.ToString());
360+
if (sku.Price != null)
361+
{
362+
GUILayout.Label("Price", EditorLabelBold());
363+
GUILayout.BeginVertical(GUI.skin.box);
364+
DrawInspectorField("Amount", sku.Price.Amount.ToString());
365+
DrawInspectorField("Currency", sku.Price.Currency);
366+
GUILayout.EndVertical();
367+
}
327368
DrawInspectorField("Type", sku.Type.ToString());
328369
DrawInspectorField("Application Id", sku.ApplicationId);
329370
GUILayout.EndVertical();

0 commit comments

Comments
 (0)