com.superfive.js 1.0.2 → 1.0.3
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/Readme.md +41 -2
- package/dist/main.d.ts +7 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -4
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -4,10 +4,17 @@ This is the JS API for the SuperFive.io gaming platform where players can compet
|
|
|
4
4
|
|
|
5
5
|
## API usage
|
|
6
6
|
|
|
7
|
+
In general adpating your game isn't gonna be much work. You only have to listen to a few events, consider some states and send a ``game_ready``.
|
|
8
|
+
|
|
9
|
+
### Quick example
|
|
10
|
+
|
|
7
11
|
```js
|
|
8
12
|
import {
|
|
9
13
|
isInPlatformMode,
|
|
10
|
-
subscribeToPlatformMessages
|
|
14
|
+
subscribeToPlatformMessages,
|
|
15
|
+
sendReady,
|
|
16
|
+
sendWin,
|
|
17
|
+
sendLose,
|
|
11
18
|
} from 'com.superfive.js'
|
|
12
19
|
|
|
13
20
|
// Check if the platform is loading this game
|
|
@@ -20,10 +27,29 @@ if (isInPlatformMode()) {
|
|
|
20
27
|
const { type } = customEvent.detail;
|
|
21
28
|
|
|
22
29
|
if (type === 'game_restart') {
|
|
23
|
-
|
|
30
|
+
yourStartGame();
|
|
24
31
|
}
|
|
25
32
|
});
|
|
26
33
|
|
|
34
|
+
create() {
|
|
35
|
+
// As soon as the game is loaded and ready to play send the 'ready event'
|
|
36
|
+
sendReady();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
yourStartGame() {
|
|
40
|
+
// The user on the plafrom clicked "Start Game" ...
|
|
41
|
+
// Your game should run now / play sound effects etc
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onWin() {
|
|
45
|
+
// If the player wins, pause the game, mute all sounds and let the platform know:
|
|
46
|
+
sendWin();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onLose() {
|
|
50
|
+
// If the player loses, pause the game, mute all sounds and let the platform know:
|
|
51
|
+
sendLose();
|
|
52
|
+
}
|
|
27
53
|
}
|
|
28
54
|
```
|
|
29
55
|
|
|
@@ -196,8 +222,21 @@ type PlatformMessageType =
|
|
|
196
222
|
|
|
197
223
|
# Game development
|
|
198
224
|
|
|
225
|
+
If your game is already hosted somewhere, send us the link (dev@superfive.io).
|
|
226
|
+
As we strive for quality we can not accept any game.
|
|
227
|
+
|
|
228
|
+
## Best practices
|
|
229
|
+
|
|
199
230
|
- The game should work in portrait (9:16)
|
|
200
231
|
- The game should work on desktop (mouse input) and mobile (touch input)
|
|
201
232
|
- The game should not start unless it receives the ``game_restart`` message from the platform
|
|
202
233
|
- The game should not play any music - only sound effects (the platform plays music)
|
|
234
|
+
- Make sure your game loads fast. We are trying to cater to people globally and everyone should be able to play.
|
|
203
235
|
- The game can have different difficulty levels (0 = 'Easy', 1 = 'Medium', 2 = 'Hard').
|
|
236
|
+
|
|
237
|
+
## Release
|
|
238
|
+
|
|
239
|
+
As for now we do not have any games store or games simulator to test the game integration.
|
|
240
|
+
Send us a static build of your game and we host it on our cloud.
|
|
241
|
+
|
|
242
|
+
Contact dev@superfive.io
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { PlatformMessage } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Get a parameter from the platform
|
|
4
|
+
*
|
|
5
|
+
* @param key The key of the parameter
|
|
6
|
+
* @returns The value of the parameter or null if the parameter is not found
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPlatformParam(key: string): string | null;
|
|
2
9
|
/**
|
|
3
10
|
* Check if the game is running in the SuperFive platform
|
|
4
11
|
*
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuBlD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAMD;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,IAAI,CAEtD;AA0BD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI,CAItF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAE/B"}
|
package/dist/main.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
function getHashParams(key) {
|
|
2
|
+
const hash = window.location.hash.replace(/^#!?/, "");
|
|
3
|
+
return new URLSearchParams(hash).get(key);
|
|
4
|
+
}
|
|
1
5
|
function getUrlParam(name) {
|
|
2
6
|
return new URLSearchParams(window.location.search).get(name);
|
|
3
7
|
}
|
|
8
|
+
function getPlatformParam(key) {
|
|
9
|
+
return getHashParams(key) || getUrlParam(key);
|
|
10
|
+
}
|
|
4
11
|
function isInPlatformMode() {
|
|
5
|
-
return
|
|
12
|
+
return getPlatformParam("p") === "1";
|
|
6
13
|
}
|
|
7
14
|
function startMuted() {
|
|
8
|
-
return
|
|
15
|
+
return getPlatformParam("muted") === "1";
|
|
9
16
|
}
|
|
10
17
|
function getDifficulty() {
|
|
11
|
-
return parseInt(
|
|
18
|
+
return parseInt(getPlatformParam("difficulty") || "0", 10);
|
|
12
19
|
}
|
|
13
20
|
function subscribeToPlatformMessages() {
|
|
14
21
|
if (!isInPlatformMode()) return;
|
|
@@ -44,6 +51,6 @@ function sendWin() {
|
|
|
44
51
|
function sendLose() {
|
|
45
52
|
sendPlatformMessage("game_lost");
|
|
46
53
|
}
|
|
47
|
-
export { getDifficulty, isInPlatformMode, sendLose, sendPlatformMessage, sendReady, sendWin, startMuted, subscribeToPlatformMessages, unsubscribeFromPlatformMessages };
|
|
54
|
+
export { getDifficulty, getPlatformParam, isInPlatformMode, sendLose, sendPlatformMessage, sendReady, sendWin, startMuted, subscribeToPlatformMessages, unsubscribeFromPlatformMessages };
|
|
48
55
|
|
|
49
56
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","names":["message: PlatformMessage"],"sources":["../src/main.ts"],"sourcesContent":["import type { PlatformMessage } from './types.ts';\n\nfunction
|
|
1
|
+
{"version":3,"file":"main.js","names":["message: PlatformMessage"],"sources":["../src/main.ts"],"sourcesContent":["import type { PlatformMessage } from './types.ts';\n\n/**\n * Get a parameter from the hash (!#p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getHashParams(key: string): string | null {\n const hash = window.location.hash.replace(/^#!?/, '')\n return new URLSearchParams(hash).get(key);\n}\n\n/**\n * Get a parameter from the url (?p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getUrlParam(name: string): string | null {\n return new URLSearchParams(window.location.search).get(name);\n}\n\n/**\n * Get a parameter from the platform\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nexport function getPlatformParam(key: string): string | null {\n return getHashParams(key) || getUrlParam(key);\n}\n\n/**\n * Check if the game is running in the SuperFive platform\n *\n * @returns True if the game is in platform mode, false otherwise\n */\nexport function isInPlatformMode(): boolean {\n return getPlatformParam('p') === '1';\n}\n\n/**\n * Check if the game should start muted\n *\n * @returns True if the game should start muted, false otherwise\n */\nexport function startMuted(): boolean {\n return getPlatformParam('muted') === '1';\n}\n\n/**\n * Get the difficulty of the game\n *\n * The difficulty is a number between 0 and 2\n * - 0: Easy\n * - 1: Medium\n * - 2: Hard\n *\n * @returns The difficulty of the game as a number between 0 and 2\n */\nexport function getDifficulty(): number {\n return parseInt(getPlatformParam('difficulty') || '0', 10);\n}\n\n// ==============================================================\n// Message Handling\n// ==============================================================\n\n/**\n * Subscribe to the platform's messages to handle platform events\n *\n * @returns void\n */\nexport function subscribeToPlatformMessages(): void {\n if (!isInPlatformMode()) return;\n window.addEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Unsubscribe from the platform's messages\n *\n * @returns void\n */\nexport function unsubscribeFromPlatformMessages(): void {\n window.removeEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Handle the platform's messages\n *\n * @param event The message event\n * @returns void\n */\nfunction handlePlatformMessage(event: MessageEvent): void {\n const data = event.data;\n if (!data || !data.type) return;\n\n // Validate message shape\n if (typeof data.type !== 'string') return;\n\n // Emit custom event for game to handle\n const customEvent = new CustomEvent('platformMessage', { \n detail: { type: data.type, payload: data.payload } \n });\n window.dispatchEvent(customEvent);\n}\n\n// ==============================================================\n// Sending Messages Methods\n// ==============================================================\n\n/**\n * Send a message to the platform\n *\n * @param type The type of the message\n * @param payload The payload of the message\n * @returns void\n */\nexport function sendPlatformMessage(type: PlatformMessage['type'], payload?: any): void {\n if (!isInPlatformMode()) return;\n const message: PlatformMessage = { type, payload };\n window.parent.postMessage(message, '*');\n}\n\n/**\n * Send a message to the platform to indicate that the game is ready (loaded and ready to play)\n *\n * @returns void\n */\nexport function sendReady(): void {\n sendPlatformMessage('game_ready');\n}\n\n/**\n * Send a message to the platform to indicate that the game is won\n *\n * @returns void\n */\nexport function sendWin(): void {\n sendPlatformMessage('game_won');\n}\n\n/**\n * Send a message to the platform to indicate that the game is lost\n *\n * @returns void\n */\nexport function sendLose(): void {\n sendPlatformMessage('game_lost');\n}\n"],"mappings":"AAQA,SAAS,cAAc,KAA4B;CACjD,MAAM,OAAO,OAAO,SAAS,KAAK,QAAQ,QAAQ,GAAG;AACrD,QAAO,IAAI,gBAAgB,KAAK,CAAC,IAAI,IAAI;;AAS3C,SAAS,YAAY,MAA6B;AAChD,QAAO,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAAC,IAAI,KAAK;;AAS9D,SAAgB,iBAAiB,KAA4B;AAC3D,QAAO,cAAc,IAAI,IAAI,YAAY,IAAI;;AAQ/C,SAAgB,mBAA4B;AAC1C,QAAO,iBAAiB,IAAI,KAAK;;AAQnC,SAAgB,aAAsB;AACpC,QAAO,iBAAiB,QAAQ,KAAK;;AAavC,SAAgB,gBAAwB;AACtC,QAAO,SAAS,iBAAiB,aAAa,IAAI,KAAK,GAAG;;AAY5D,SAAgB,8BAAoC;AAClD,KAAI,CAAC,kBAAkB,CAAE;AACzB,QAAO,iBAAiB,WAAW,sBAAsB;;AAQ3D,SAAgB,kCAAwC;AACtD,QAAO,oBAAoB,WAAW,sBAAsB;;AAS9D,SAAS,sBAAsB,OAA2B;CACxD,MAAM,OAAO,MAAM;AACnB,KAAI,CAAC,QAAQ,CAAC,KAAK,KAAM;AAGzB,KAAI,OAAO,KAAK,SAAS,SAAU;CAGnC,MAAM,cAAc,IAAI,YAAY,mBAAmB,EACrD,QAAQ;EAAE,MAAM,KAAK;EAAM,SAAS,KAAK;EAAS,EACnD,CAAC;AACF,QAAO,cAAc,YAAY;;AAcnC,SAAgB,oBAAoB,MAA+B,SAAqB;AACtF,KAAI,CAAC,kBAAkB,CAAE;CACzB,MAAMA,UAA2B;EAAE;EAAM;EAAS;AAClD,QAAO,OAAO,YAAY,SAAS,IAAI;;AAQzC,SAAgB,YAAkB;AAChC,qBAAoB,aAAa;;AAQnC,SAAgB,UAAgB;AAC9B,qBAAoB,WAAW;;AAQjC,SAAgB,WAAiB;AAC/B,qBAAoB,YAAY"}
|