com.superfive.js 1.0.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/LICENSE +21 -0
- package/Readme.md +203 -0
- package/dist/main.js +49 -0
- package/dist/main.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Francois
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# SuperFive JS API
|
|
2
|
+
|
|
3
|
+
This is the JS API for the SuperFive.io gaming platform where players can compete in a hypercasual games tournament. Use it to adapt your game for the platform.
|
|
4
|
+
|
|
5
|
+
## API usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import {
|
|
9
|
+
isInPlatformMode,
|
|
10
|
+
subscribeToPlatformMessages
|
|
11
|
+
} from 'com.superfive.js'
|
|
12
|
+
|
|
13
|
+
// Check if the platform is loading this game
|
|
14
|
+
if (isInPlatformMode()) {
|
|
15
|
+
|
|
16
|
+
// Subscribe to the platform's messages
|
|
17
|
+
subscribeToPlatformMessages();
|
|
18
|
+
window.addEventListener('platformMessage', (event: Event) => {
|
|
19
|
+
const customEvent = event as CustomEvent;
|
|
20
|
+
const { type } = customEvent.detail;
|
|
21
|
+
|
|
22
|
+
if (type === 'game_restart') {
|
|
23
|
+
this.yourRestartGame();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API events
|
|
31
|
+
|
|
32
|
+
The platform can send the following events to your game:
|
|
33
|
+
|
|
34
|
+
### `platformMessage` (Custom Event)
|
|
35
|
+
|
|
36
|
+
This event is dispatched when the platform sends a message to your game. Listen for this event to handle platform communications.
|
|
37
|
+
|
|
38
|
+
**Event Structure:**
|
|
39
|
+
```js
|
|
40
|
+
{
|
|
41
|
+
detail: {
|
|
42
|
+
type: string, // The message type
|
|
43
|
+
payload: any // Optional payload data
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Available Message Types:**
|
|
49
|
+
- `game_restart` - Platform requests the game to (re)start
|
|
50
|
+
- `game_mute` - Platform requests the game to mute/unmute audio
|
|
51
|
+
|
|
52
|
+
**Example:**
|
|
53
|
+
```js
|
|
54
|
+
window.addEventListener('platformMessage', (event) => {
|
|
55
|
+
const customEvent = event as CustomEvent;
|
|
56
|
+
const { type, payload } = customEvent.detail;
|
|
57
|
+
|
|
58
|
+
switch (type) {
|
|
59
|
+
case 'game_restart':
|
|
60
|
+
// Restart your game
|
|
61
|
+
break;
|
|
62
|
+
case 'game_mute':
|
|
63
|
+
// Handle mute/unmute based on payload
|
|
64
|
+
const isMuted = payload.muted;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API methods
|
|
71
|
+
|
|
72
|
+
### Platform Detection
|
|
73
|
+
|
|
74
|
+
#### `isInPlatformMode(): boolean`
|
|
75
|
+
|
|
76
|
+
Checks if the game is running within the SuperFive platform.
|
|
77
|
+
|
|
78
|
+
**Returns:** `boolean` - `true` if running in platform mode, `false` otherwise
|
|
79
|
+
|
|
80
|
+
**Example:**
|
|
81
|
+
```js
|
|
82
|
+
if (isInPlatformMode()) {
|
|
83
|
+
// Game is running in SuperFive platform
|
|
84
|
+
console.log('Platform mode detected');
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `getDifficulty(): number`
|
|
89
|
+
|
|
90
|
+
Gets the difficulty level set by the platform.
|
|
91
|
+
|
|
92
|
+
**Returns:** `number` - Difficulty level (0-2)
|
|
93
|
+
- `0` - Easy (default)
|
|
94
|
+
- `1` - Medium
|
|
95
|
+
- `2` - Hard
|
|
96
|
+
|
|
97
|
+
**Example:**
|
|
98
|
+
```js
|
|
99
|
+
const difficulty = getDifficulty();
|
|
100
|
+
console.log(`Game difficulty: ${difficulty}`);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### `startMuted(): boolean`
|
|
104
|
+
|
|
105
|
+
The player can set if they want to play without sound effects.
|
|
106
|
+
This should be checked before starting the game or playing any sounds.
|
|
107
|
+
|
|
108
|
+
**Returns:** `boolean`
|
|
109
|
+
|
|
110
|
+
**Example:**
|
|
111
|
+
```js
|
|
112
|
+
const isMuted = startMuted();
|
|
113
|
+
console.log(`Game muted?: ${isMuted}`);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Message Handling
|
|
117
|
+
|
|
118
|
+
#### `subscribeToPlatformMessages(): void`
|
|
119
|
+
|
|
120
|
+
Subscribes to platform messages. Call this when your game starts to receive platform events.
|
|
121
|
+
|
|
122
|
+
**Example:**
|
|
123
|
+
```js
|
|
124
|
+
// Subscribe to platform messages
|
|
125
|
+
subscribeToPlatformMessages();
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### `unsubscribeFromPlatformMessages(): void`
|
|
129
|
+
|
|
130
|
+
Unsubscribes from platform messages. Call this when your game is shutting down.
|
|
131
|
+
|
|
132
|
+
**Example:**
|
|
133
|
+
```js
|
|
134
|
+
// Clean up when game ends
|
|
135
|
+
unsubscribeFromPlatformMessages();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Sending Messages to Platform
|
|
139
|
+
|
|
140
|
+
#### `sendPlatformMessage(type, payload?): void`
|
|
141
|
+
|
|
142
|
+
Sends a message to the SuperFive platform.
|
|
143
|
+
|
|
144
|
+
**Parameters:**
|
|
145
|
+
- `type` - Message type (see PlatformMessage types below)
|
|
146
|
+
- `payload` - Optional data to send with the message
|
|
147
|
+
|
|
148
|
+
**Example:**
|
|
149
|
+
```js
|
|
150
|
+
// Send custom message with data
|
|
151
|
+
sendPlatformMessage('custom_event', { score: 100 });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### `sendReady(): void`
|
|
155
|
+
|
|
156
|
+
Notifies the platform that your game is loaded and ready to play.
|
|
157
|
+
|
|
158
|
+
**Example:**
|
|
159
|
+
```js
|
|
160
|
+
// When your game is fully loaded
|
|
161
|
+
sendReady();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### `sendWin(): void`
|
|
165
|
+
|
|
166
|
+
Notifies the platform that the player has won the game.
|
|
167
|
+
|
|
168
|
+
**Example:**
|
|
169
|
+
```js
|
|
170
|
+
// When player completes the game successfully
|
|
171
|
+
sendWin();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### `sendLose(): void`
|
|
175
|
+
|
|
176
|
+
Notifies the platform that the player has lost the game.
|
|
177
|
+
|
|
178
|
+
**Example:**
|
|
179
|
+
```js
|
|
180
|
+
// When player fails the game
|
|
181
|
+
sendLose();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Message Types
|
|
185
|
+
|
|
186
|
+
The following message types can be sent to the platform:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
type PlatformMessageType =
|
|
190
|
+
| 'game_ready' // Game is loaded and ready
|
|
191
|
+
| 'game_won' // Player won the game
|
|
192
|
+
| 'game_lost' // Player lost the game
|
|
193
|
+
| 'game_restart' // Platform requests restart
|
|
194
|
+
| 'game_mute' // Platform requests mute/unmute
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
# Game development
|
|
198
|
+
|
|
199
|
+
- The game should work in portrait (9:16)
|
|
200
|
+
- The game should work on desktop (mouse input) and mobile (touch input)
|
|
201
|
+
- The game should not start unless it receives the ``game_restart`` message from the platform
|
|
202
|
+
- The game should not play any music - only sound effects (the platform plays music)
|
|
203
|
+
- The game can have different difficulty levels (0 = 'Easy', 1 = 'Medium', 2 = 'Hard').
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function getUrlParam(name) {
|
|
2
|
+
return new URLSearchParams(window.location.search).get(name);
|
|
3
|
+
}
|
|
4
|
+
function isInPlatformMode() {
|
|
5
|
+
return getUrlParam("p") === "1";
|
|
6
|
+
}
|
|
7
|
+
function startMuted() {
|
|
8
|
+
return getUrlParam("muted") === "1";
|
|
9
|
+
}
|
|
10
|
+
function getDifficulty() {
|
|
11
|
+
return parseInt(getUrlParam("difficulty") || "0", 10);
|
|
12
|
+
}
|
|
13
|
+
function subscribeToPlatformMessages() {
|
|
14
|
+
if (!isInPlatformMode()) return;
|
|
15
|
+
window.addEventListener("message", handlePlatformMessage);
|
|
16
|
+
}
|
|
17
|
+
function unsubscribeFromPlatformMessages() {
|
|
18
|
+
window.removeEventListener("message", handlePlatformMessage);
|
|
19
|
+
}
|
|
20
|
+
function handlePlatformMessage(event) {
|
|
21
|
+
const data = event.data;
|
|
22
|
+
if (!data || !data.type) return;
|
|
23
|
+
if (typeof data.type !== "string") return;
|
|
24
|
+
const customEvent = new CustomEvent("platformMessage", { detail: {
|
|
25
|
+
type: data.type,
|
|
26
|
+
payload: data.payload
|
|
27
|
+
} });
|
|
28
|
+
window.dispatchEvent(customEvent);
|
|
29
|
+
}
|
|
30
|
+
function sendPlatformMessage(type, payload) {
|
|
31
|
+
if (!isInPlatformMode()) return;
|
|
32
|
+
const message = {
|
|
33
|
+
type,
|
|
34
|
+
payload
|
|
35
|
+
};
|
|
36
|
+
window.parent.postMessage(message, "*");
|
|
37
|
+
}
|
|
38
|
+
function sendReady() {
|
|
39
|
+
sendPlatformMessage("game_ready");
|
|
40
|
+
}
|
|
41
|
+
function sendWin() {
|
|
42
|
+
sendPlatformMessage("game_won");
|
|
43
|
+
}
|
|
44
|
+
function sendLose() {
|
|
45
|
+
sendPlatformMessage("game_lost");
|
|
46
|
+
}
|
|
47
|
+
export { getDifficulty, isInPlatformMode, sendLose, sendPlatformMessage, sendReady, sendWin, startMuted, subscribeToPlatformMessages, unsubscribeFromPlatformMessages };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","names":["message: PlatformMessage"],"sources":["../src/main.ts"],"sourcesContent":["import type { PlatformMessage } from './types.ts';\n\nfunction getUrlParam(name: string): string | null {\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(name);\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 getUrlParam('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 getUrlParam('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(getUrlParam('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":"AAEA,SAAS,YAAY,MAA6B;AAEhD,QADkB,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAC5C,IAAI,KAAK;;AAQ5B,SAAgB,mBAA4B;AAC1C,QAAO,YAAY,IAAI,KAAK;;AAQ9B,SAAgB,aAAsB;AACpC,QAAO,YAAY,QAAQ,KAAK;;AAalC,SAAgB,gBAAwB;AACtC,QAAO,SAAS,YAAY,aAAa,IAAI,KAAK,GAAG;;AAYvD,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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "com.superfive.js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/main.js",
|
|
6
|
+
"module": "./dist/main.js",
|
|
7
|
+
"types": "./dist/main.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/main.js",
|
|
11
|
+
"types": "./dist/main.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"description": "The JS API for the SuperFive.io gaming platform where players can compete in a hypercasual games tournament",
|
|
18
|
+
"author": "Dibulo",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://superfive.io",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/dibulo/superfive-js-api.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/dibulo/superfive-js-api/issues"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"superfive",
|
|
30
|
+
"gaming",
|
|
31
|
+
"js",
|
|
32
|
+
"api"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "vite",
|
|
36
|
+
"build": "tsc -p tsconfig.build.json && vite build",
|
|
37
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
38
|
+
"preview": "vite preview",
|
|
39
|
+
"prepublishOnly": "pnpm run build"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "~5.9.3",
|
|
43
|
+
"vite": "npm:rolldown-vite@7.1.14"
|
|
44
|
+
},
|
|
45
|
+
"pnpm": {
|
|
46
|
+
"overrides": {
|
|
47
|
+
"vite": "npm:rolldown-vite@7.1.14"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|