Skip to content

Commit 275f8a6

Browse files
committed
refactor: only include wasm interop layer on wbegl builds
1 parent 1b563b1 commit 275f8a6

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

Assets/Dojo/Runtime/Starknet/StarknetInterop.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if UNITY_WEBGL && !UNITY_EDITOR
12
using System;
23
using System.Diagnostics;
34
using System.Linq;
@@ -242,4 +243,5 @@ public static string PoseidonHash(FieldElement[] felts)
242243
return PoseidonHash(new CString(JsonConvert.SerializeObject(felts.Select(f => f.Hex()).ToArray())));
243244
}
244245
}
245-
}
246+
}
247+
#endif // UNITY_WEBGL

Assets/Dojo/Runtime/Torii/ToriiWasmClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if UNITY_WEBGL && !UNITY_EDITOR
12
using System;
23
using System.Collections.Generic;
34
using System.Linq;
@@ -275,4 +276,5 @@ public async Task<IntPtr> RegisterTokenBalanceUpdateEvent(FieldElement[] contrac
275276
return await SubscriptionHelper.Tcs.Task;
276277
}
277278
}
278-
}
279+
}
280+
#endif // UNITY_WEBGL

Assets/Dojo/Runtime/Torii/ToriiWasmInterop.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if UNITY_WEBGL && !UNITY_EDITOR
12
using UnityEngine;
23
using System;
34
using System.Runtime.InteropServices;
@@ -121,4 +122,5 @@ public class ToriiWasmInterop : MonoBehaviour
121122
[DllImport("__Internal")]
122123
public static extern void PublishMessage(IntPtr clientPtr, CString typedData, CString signature, Action<string> cb);
123124
}
124-
}
125+
}
126+
#endif // UNITY_WEBGL

Assets/Dojo/Runtime/WorldManager.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ namespace Dojo
1111
public class WorldManager : MonoBehaviour
1212
{
1313
public SynchronizationMaster synchronizationMaster;
14+
#if UNITY_WEBGL && !UNITY_EDITOR
15+
public ToriiWasmClient toriiClient;
16+
#else
1417
public ToriiClient toriiClient;
15-
public ToriiWasmClient wasmClient;
18+
#endif
1619
[SerializeField] public WorldManagerData dojoConfig;
1720

1821
async void Awake()
1922
{
2023
#if UNITY_WEBGL && !UNITY_EDITOR
21-
wasmClient = new ToriiWasmClient(dojoConfig.toriiUrl, dojoConfig.relayWebrtcUrl, dojoConfig.worldAddress);
22-
await wasmClient.CreateClient();
24+
toriiClient = new ToriiWasmClient(dojoConfig.toriiUrl, dojoConfig.relayWebrtcUrl, dojoConfig.worldAddress);
25+
await toriiClient.CreateClient();
2326
#else
2427
toriiClient = new ToriiClient(dojoConfig.toriiUrl, dojoConfig.relayUrl, dojoConfig.worldAddress);
2528
#endif
@@ -117,7 +120,7 @@ public void RemoveEntity(string key)
117120
public async Task<byte[]> Publish(TypedData typedData, FieldElement[] signature)
118121
{
119122
#if UNITY_WEBGL && !UNITY_EDITOR
120-
return await wasmClient.PublishMessage(typedData, signature);
123+
return await toriiClient.PublishMessage(typedData, signature);
121124
#else
122125
return await Task.Run(() => toriiClient.PublishMessage(typedData, signature).ToArray());
123126
#endif

0 commit comments

Comments
 (0)