feat: overhaul UI main and profile

This commit is contained in:
2026-04-15 16:26:49 +08:00
parent 01661a56ba
commit f10d777c90
16 changed files with 1888 additions and 710 deletions
+46
View File
@@ -23,6 +23,9 @@ function InitModule(ctx, logger, nk, initializer) {
initializer.registerRpc("get_user_profile", rpcGetUserProfile);
initializer.registerRpc("update_user_profile", rpcUpdateUserProfile);
// Store RPCs
initializer.registerRpc("purchase_item", rpcPurchaseItem);
// Leaderboard RPCs
initializer.registerRpc("get_leaderboard_stats", rpcGetLeaderboardStats);
initializer.registerRpc("admin_update_stats", rpcAdminUpdateStats);
@@ -377,6 +380,49 @@ function rpcAdminSetUserRole(ctx, logger, nk, payload) {
}
}
// =============================================================================
// Store / Economy RPCs
// =============================================================================
function rpcPurchaseItem(ctx, logger, nk, payload) {
if (!ctx.userId) throw new Error("Not authenticated");
var request = JSON.parse(payload);
var itemId = request.item_id;
var priceGold = request.price_gold || 0;
var priceStar = request.price_star || 0;
var category = request.category || "accessory"; // head, costume, glove, accessory
if (!itemId) throw new Error("Item ID required");
try {
var changeset = {};
if (priceGold > 0) changeset["gold"] = -priceGold;
if (priceStar > 0) changeset["star"] = -priceStar;
// Check wallet and deduct
// nk.walletUpdate throws an error if insufficient funds
nk.walletUpdate(ctx.userId, changeset, {}, true);
// Record purchase in inventory
var inventoryObj = {
collection: "inventory",
key: itemId,
userId: ctx.userId,
value: { category: category, purchased_at: new Date().toISOString() },
permissionRead: 1,
permissionWrite: 0
};
nk.storageWrite([inventoryObj]);
logger.info("User " + ctx.userId + " purchased " + itemId);
return JSON.stringify({ success: true, item: itemId });
} catch (e) {
logger.error("Purchase failed: " + e.message);
throw new Error("Purchase failed: " + e.message);
}
}
// =============================================================================
// User Profile RPCs
// =============================================================================