diff --git a/.eslintrc.json b/.eslintrc.json index 64f0a8d..865d80b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,6 +5,7 @@ "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { "@typescript-eslint/explicit-function-return-type": "warn", - "@typescript-eslint/explicit-member-accessibility": "warn" + "@typescript-eslint/explicit-member-accessibility": "warn", + "@typescript-eslint/no-namespace": "off" } } diff --git a/assets/Plugins.meta b/assets/Plugins.meta new file mode 100644 index 0000000..7251de8 --- /dev/null +++ b/assets/Plugins.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "11ea4add-991c-437e-8f89-2a1204514d87", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Plugins/Y8.meta b/assets/Plugins/Y8.meta new file mode 100644 index 0000000..6781267 --- /dev/null +++ b/assets/Plugins/Y8.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "97380d00-7f7e-46c8-8ced-e468657b8f44", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Plugins/Y8/Scripts.meta b/assets/Plugins/Y8/Scripts.meta new file mode 100644 index 0000000..2f62ae8 --- /dev/null +++ b/assets/Plugins/Y8/Scripts.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "cf65ddc3-4251-4d88-aaae-3353cb32f0d6", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Plugins/Y8/Scripts/Y8.ts b/assets/Plugins/Y8/Scripts/Y8.ts new file mode 100644 index 0000000..4a4b8c3 --- /dev/null +++ b/assets/Plugins/Y8/Scripts/Y8.ts @@ -0,0 +1,64 @@ +import { Component, _decorator } from "cc"; +import { Y8API } from "./Y8def"; + +const { ccclass, property } = _decorator; + +@ccclass("Y8") +export class Y8 extends Component { + @property(String) private appId = "ENTER APP ID"; + + public init(): Promise { + return new Promise((resolve) => { + // callback after Y8 script is loaded + window.idAsyncInit = (): void => { + // wait for app connection + ID.Event.subscribe("id.init", resolve); + ID.init({ appId: this.appId }); + }; + + // Load the script + (function (d, s, id): void { + const fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) { + return; + } + const js: HTMLScriptElement = d.createElement(s); + js.id = id; + js.src = document.location.protocol == "https:" ? "https://cdn.y8.com/api/sdk.js" : "http://cdn.y8.com/api/sdk.js"; + fjs.parentNode.insertBefore(js, fjs); + })(document, "script", "id-jssdk"); + }); + } + + public login(): Promise { + console.log("Logging in"); + return new Promise((resolve) => { + ID.login((response: Y8API.Authorization) => { + resolve(response); + }); + }); + } + + public async tryAutoLogin(): Promise { + const auth = await this.getLoginStatus(); + console.log(auth); + if (auth?.status == "not_linked" || auth?.status == "uncomplete") { + await this.login(); + } + } + + public async isLoggedIn(): Promise { + const auth = await this.getLoginStatus(); + return auth?.success == true; + } + + public sendCustomEvent(name: string, data?: string | number): void { + ID.Analytics.custom_event(name, data); + } + + private getLoginStatus(): Promise { + return new Promise((resolve) => { + ID.getLoginStatus(resolve); + }); + } +} diff --git a/assets/Plugins/Y8/Scripts/Y8.ts.meta b/assets/Plugins/Y8/Scripts/Y8.ts.meta new file mode 100644 index 0000000..2c4c642 --- /dev/null +++ b/assets/Plugins/Y8/Scripts/Y8.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "02815b81-6c1e-4a09-8ae4-f4bcb375745a", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Plugins/Y8/Scripts/Y8def.ts b/assets/Plugins/Y8/Scripts/Y8def.ts new file mode 100644 index 0000000..3f966b3 --- /dev/null +++ b/assets/Plugins/Y8/Scripts/Y8def.ts @@ -0,0 +1,39 @@ +declare global { + const ID: Y8API.ID; + interface Window { + idAsyncInit: () => void; + } +} + +export namespace Y8API { + export interface ID { + init: (appInfo: { appId: string }) => void; + getLoginStatus: (callback: (response?: Authorization) => void, skipCache?: boolean) => void; + login: (callback: (response?: Authorization) => void) => void; + register: (callback: (response?: Authorization) => void) => void; + Event: Event; + Analytics: Analytics; + } + + export interface Event { + subscribe: (eventName: string, callback: (response?: any) => void) => void; + } + + export interface Analytics { + custom_event: (name: string, data?: string | number) => void; + } + + export interface Authorization { + status: string; + success?: boolean; + authResponse: { + state: string; + access_token: string; + token_type: string; + expires_in: number; + scope: string; + redirect_uri: string; + details: any; + }; + } +} diff --git a/assets/Plugins/Y8/Scripts/Y8def.ts.meta b/assets/Plugins/Y8/Scripts/Y8def.ts.meta new file mode 100644 index 0000000..542f9e2 --- /dev/null +++ b/assets/Plugins/Y8/Scripts/Y8def.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "445aa0c8-388e-4665-aeee-0a51681e77e4", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Plugins/Y8/Y8.prefab b/assets/Plugins/Y8/Y8.prefab new file mode 100644 index 0000000..19f8cd1 --- /dev/null +++ b/assets/Plugins/Y8/Y8.prefab @@ -0,0 +1,86 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "Y8", + "_objFlags": 0, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "persistent": false, + "asyncLoadAssets": false + }, + { + "__type__": "cc.Node", + "_name": "Y8", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": null, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 2 + } + ], + "_prefab": { + "__id__": 4 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "02815uBbB5KCYrk9LyzdXRa", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 3 + }, + "appId": "63b3de081f76dda380d47195", + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "9cOBr9gAFNWbvsaSX5dfaa" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "5da9o8mwlJl5XD861jGbYx" + } +] \ No newline at end of file diff --git a/assets/Plugins/Y8/Y8.prefab.meta b/assets/Plugins/Y8/Y8.prefab.meta new file mode 100644 index 0000000..441df34 --- /dev/null +++ b/assets/Plugins/Y8/Y8.prefab.meta @@ -0,0 +1,13 @@ +{ + "ver": "1.1.40", + "importer": "prefab", + "imported": true, + "uuid": "f668086a-2bff-40eb-a029-dd891718441d", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": { + "syncNodeName": "Y8" + } +}