@adlad/plugin-viverse 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adlad-plugin-viverse.js +1 -1
- package/package.json +1 -1
- package/src/mod.js +6 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
function viversePlugin({appId:e,domain:t="account.htcvive.com",cookieDomain:i}){let a=!1;if(!e)throw new Error("No app id was provided");const o={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData"};let n,s;o>0&&console.log(o);let
|
|
1
|
+
function viversePlugin({appId:e,domain:t="account.htcvive.com",cookieDomain:i}){let a=!1;if(!e)throw new Error("No app id was provided");const o={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData"};let n,s;o>0&&console.log(o);let r=null;const l=new Map,c="adlad_viverse_";return{name:"viverse",async initialize(l){if(a)throw new Error("Viverse plugin is being initialized more than once");if(a=!0,await l.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),n=new globalThis[o.viverse][o.client]({[o.clientId]:e,[o.domain]:t,[o.cookieDomain]:i}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on the viverse.com.");const c=await n[o.checkAuth]();r=c?.access_token||null;const d=new globalThis[o.viverse][o.storage];s=await d[o.newCloudSaveClient](e)},customRequests:{async setStorageItem(e,t){const i=JSON.stringify(t);if(r)await s[o.setPlayerData](e,{s:i},r);else{await new Promise((e=>setTimeout(e,1e3)));try{localStorage.setItem(c+e,i)}catch{l.set(e,i)}}},async getStorageItem(e){let t;if(r){const i=await s[o.getPlayerData](e,r);t="object"==typeof i&&null!=i?i.s:null}else{await new Promise((e=>setTimeout(e,1e3)));try{t=localStorage.getItem(c+e)}catch{t=l.get(e)}}return t&&"string"==typeof t?JSON.parse(t):null},showAuthPrompt(){n[o.loginWithWorlds]()}}}}export{viversePlugin};
|
package/package.json
CHANGED
package/src/mod.js
CHANGED
|
@@ -98,6 +98,9 @@ export function viversePlugin({
|
|
|
98
98
|
// So in order to prevent the sdk from parsing our strings, we'll just provide an object.
|
|
99
99
|
await cloudSaveClient[props.setPlayerData](key, { s: stringifiedValue }, accessToken);
|
|
100
100
|
} else {
|
|
101
|
+
// Calls to the viverse sdk normally do not resolve instantly, which might cause bugs in the application.
|
|
102
|
+
// Let's simulate this behavior so it's easier to reproduce these issues in local development.
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
101
104
|
try {
|
|
102
105
|
localStorage.setItem(localStoragePrefix + key, stringifiedValue);
|
|
103
106
|
} catch {
|
|
@@ -121,6 +124,9 @@ export function viversePlugin({
|
|
|
121
124
|
stringifiedValue = null;
|
|
122
125
|
}
|
|
123
126
|
} else {
|
|
127
|
+
// Calls to the viverse sdk normally do not resolve instantly, which might cause bugs in the application.
|
|
128
|
+
// Let's simulate this behavior so it's easier to reproduce these issues in local development.
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
124
130
|
try {
|
|
125
131
|
stringifiedValue = localStorage.getItem(localStoragePrefix + key);
|
|
126
132
|
} catch {
|