Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Assets/PlayroomKit/modules/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static string SerializeInitOptions(InitOptions options)
node["roomCode"] = options.roomCode;
node["skipLobby"] = options.skipLobby;
node["reconnectGracePeriod"] = options.reconnectGracePeriod;
node["discord"] = options.discord;
node["discord"] = SerializeDiscord(options.discord);
node["persistentMode"] = options.persistentMode;

if (options.avatars != null)
Expand Down Expand Up @@ -98,6 +98,27 @@ public static string SerializeInitOptions(InitOptions options)
return node.ToString();
}

private static JSONNode SerializeDiscord(object discord)
{
if (discord is bool b)
return new JSONBool(b);

if (discord is DiscordOptions opts)
{
var discordNode = new JSONObject();
if (opts.Scope != null)
{
var scopeArray = new JSONArray();
foreach (var s in opts.Scope)
scopeArray.Add(s);
discordNode["scope"] = scopeArray;
}
return discordNode;
}

return JSONNull.CreateOrGet();
}

private static JSONNode ConvertValueToJSON(object value)
{
if (value is string stringValue)
Expand Down
12 changes: 12 additions & 0 deletions Assets/PlayroomKit/modules/Options/DiscordOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace Playroom
{
public class DiscordOptions
{
public string? Prompt;
public List<string>? Scope;
public string? State;
}
}

11 changes: 11 additions & 0 deletions Assets/PlayroomKit/modules/Options/DiscordOptions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions Assets/PlayroomKit/modules/Options/InitOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public class InitOptions
public bool skipLobby = false;
public int reconnectGracePeriod = 0;
public int? maxPlayersPerRoom;

[CanBeNull]
public string gameId;
public bool discord = false;
public bool persistentMode = false;

public Dictionary<string, object> defaultStates = null;
Expand All @@ -27,6 +26,9 @@ public class InitOptions
private object matchmakingField;
private object turnBasedField;

public object discord = false;


public object matchmaking
{
get => matchmakingField;
Expand Down Expand Up @@ -59,5 +61,20 @@ public object turnBased
}
}
}
public object discordOptions
{
get => discord;
set
{
if (value is bool || value is DiscordOptions)
{
discord = value;
}
else
{
throw new ArgumentException("discordOptions must be a boolean or a DiscordOptions object.");
}
}
}
}
}
60 changes: 60 additions & 0 deletions Assets/PlayroomKit/modules/Store/ServerReward.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using SimpleJSON;
using UnityEngine;

namespace Playroom
{
[Serializable]
public class ServerReward
{
public string serverId;
public string id;
public string title;
public string description;
public string image;
public string message;
public bool active;
public string key;
public string skuId;
public string type;
public bool status;

private static ServerReward FromJSONNode(JSONNode node)
{
ServerReward reward = new ServerReward
{
serverId = node["server_id"]?.Value ?? string.Empty,
id = node["id"]?.Value ?? string.Empty,
title = node["title"]?.Value ?? string.Empty,
description = node["description"]?.Value ?? string.Empty,
image = node["image"]?.Value ?? string.Empty,
message = node["message"]?.Value ?? string.Empty,
active = node["active"] != null && node["active"].AsBool,
key = node["key"]?.Value ?? string.Empty,
skuId = node["sku_id"]?.Value ?? string.Empty,
type = node["type"]?.Value ?? string.Empty,
status = node["status"] != null && node["status"].AsBool
};

return reward;
}

public static List<ServerReward> FromJSON(string jsonString)
{
List<ServerReward> serverRewards = new();
JSONNode root = JSON.Parse(jsonString);

if (!root.IsArray)
Debug.LogWarning("Expected an array");

foreach (JSONNode item in root.AsArray)
{
var data = FromJSONNode(item);
serverRewards.Add(data);
}

return serverRewards;
}
}
}
11 changes: 11 additions & 0 deletions Assets/PlayroomKit/modules/Store/ServerReward.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Assets/Scenes/TestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,16 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: dc3a2b9cdc24aab40906ce4bcdee9943, type: 3}
m_Name:
m_EditorClassIdentifier:
gameId: FmOBeUfQO2AOLNIrJNSJ
baseUrl: https://ws.joinplayroom.com/api/store
gameApiKey:
gameApiKey: 510a71af-3a69-4f5d-9b9b-296a1871e624
token: eyJhbGciOiJIUzI1NiJ9.eyJkaXNjb3JkSWQiOiI0NzY3MDk1MjQwMTE2MTQyMTkiLCJyb29tSWQiOiJEQ1JEX2ktMTM4OTk1NjgzMTE0NDgzNzE0MC1wYy0xMzcxOTI3NzM0MTY2NDg3MDkwIiwiZ2FtZUlkIjoiRm1PQmVVZlFPMkFPTE5JckpOU0oiLCJndWlsZElkIjpudWxsLCJjaGFubmVsSWQiOiIxMzcxOTI3NzM0MTY2NDg3MDkwIiwiYWNjZXNzVG9rZW4iOiJNVE0zTURReE5qSTRORFk0T0RNeU1qWTRNZy5CNjdvckR6UjV1V0Q4dWE2TlZlUzNtczRpdEM2cGoiLCJhdXRoIjoiZGlzY29yZCIsInQiOjE3NTE0NjE5NzF9.Te4Fgg6KrSs9bqsxKPlyDYZotcumECoGCi_Q5cWCCAM
text: {fileID: 1547749}
skus: []
entitlements: []
discordSkus: []
discordEntitlements: []
serverRewards: []
--- !u!4 &1054460207
Transform:
m_ObjectHideFlags: 0
Expand Down
Loading