-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
196 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ dist-ssr | |
bin/ | ||
src/neutralino.js | ||
.tmp | ||
.storage | ||
|
||
# Uncompressed music | ||
*.wav | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"team": "Chocobois", | ||
"title": "Game Jam Template", | ||
"description": "We make game, but faster!", | ||
"itch": { | ||
"upload": false, | ||
"username": "username", | ||
"game": "game-name" | ||
}, | ||
"neutralino": { | ||
"allow": ["app.exit", "window.center"] | ||
} | ||
"team": "Chocobois", | ||
"title": "Game Jam Template", | ||
"description": "We make game, but faster!", | ||
"itch": { | ||
"upload": false, | ||
"username": "username", | ||
"game": "game-name" | ||
}, | ||
"neutralino": { | ||
"allow": ["app.exit", "window.center", "storage.*"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
{ | ||
"name": "chocobois-jam-template", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "vite-node automation/dev.ts", | ||
"dev": "vite-node automation/dev.ts", | ||
"dev-neu": "vite-node automation/neu-dev.ts", | ||
"build": "rimraf dist && vite build", | ||
"postinstall": "vite-node automation/setup.ts" | ||
}, | ||
"dependencies": { | ||
"@neutralinojs/lib": "^5.3.0", | ||
"phaser": "^3.80.1", | ||
"phaser3-rex-plugins": "^1.80.6" | ||
}, | ||
"devDependencies": { | ||
"@electron/asar": "^3.2.10", | ||
"@neutralinojs/neu": "^11.2.2", | ||
"png-to-ico": "^2.1.8", | ||
"resedit": "^2.0.2", | ||
"rimraf": "^6.0.1", | ||
"sharp": "^0.33.4", | ||
"terser": "^5.31.6", | ||
"typescript": "^5.5.4", | ||
"vite": "^5.4.1", | ||
"vite-node": "^2.0.5", | ||
"vite-plugin-checker": "^0.7.2", | ||
"vite-plugin-image-optimizer": "^1.1.8", | ||
"vite-plugin-zip-pack": "^1.2.4", | ||
"vite-tsconfig-paths": "^5.0.1" | ||
} | ||
"name": "chocobois-jam-template", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "vite-node automation/dev.ts", | ||
"dev": "vite-node automation/dev.ts", | ||
"dev-neu": "vite-node automation/neu-dev.ts", | ||
"build": "rimraf dist && vite build", | ||
"postinstall": "vite-node automation/setup.ts" | ||
}, | ||
"dependencies": { | ||
"@neutralinojs/lib": "^5.5.0", | ||
"phaser": "^3.87.0", | ||
"phaser3-rex-plugins": "^1.80.12" | ||
}, | ||
"devDependencies": { | ||
"@electron/asar": "^3.2.10", | ||
"@neutralinojs/neu": "^11.2.2", | ||
"png-to-ico": "^2.1.8", | ||
"resedit": "^2.0.3", | ||
"rimraf": "^6.0.1", | ||
"sharp": "^0.33.5", | ||
"terser": "^5.37.0", | ||
"typescript": "^5.7.2", | ||
"vite": "^6.0.3", | ||
"vite-node": "^2.0.5", | ||
"vite-plugin-checker": "^0.8.0", | ||
"vite-plugin-image-optimizer": "^1.1.8", | ||
"vite-plugin-zip-pack": "^1.2.4", | ||
"vite-tsconfig-paths": "^5.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import "@/util/neu"; | ||
import "@/util/storage"; | ||
import { Game } from "./game"; | ||
|
||
Game(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Neutralino from "@neutralinojs/lib"; | ||
|
||
export const isNeutralino = !!window.NL_TOKEN; | ||
|
||
if (isNeutralino) { | ||
Neutralino.init(); | ||
Neutralino.events.on("windowClose", () => { | ||
Neutralino.app.exit(); | ||
}); | ||
Neutralino.window.center(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { storage } from "@neutralinojs/lib"; | ||
import { isNeutralino } from "@/util/neu"; | ||
|
||
type AppStorage = { | ||
readonly length: number; | ||
getItem: (key: string) => Promise<string | null>; | ||
setItem: (key: string, value: string) => Promise<void>; | ||
removeItem: (key: string) => Promise<void>; | ||
key: (index: number) => Promise<string | null>; | ||
clear: () => Promise<void>; | ||
}; | ||
|
||
const keyRegex = new RegExp("^[a-zA-Z-_0-9]{1,50}$"); | ||
const keyError = | ||
"Invalid storage key format. The key should match regex: ^[a-zA-Z-_0-9]{1,50}$"; | ||
const keyCheck = (key: string) => { | ||
if (!key.match(keyRegex)) { | ||
throw keyError; | ||
} | ||
}; | ||
|
||
class NeutralinoStorageClass { | ||
#length: number; | ||
|
||
get length() { | ||
return this.#length; | ||
} | ||
constructor(resolve: (value: AppStorage | PromiseLike<AppStorage>) => void) { | ||
this.#length = 0; | ||
storage | ||
.getKeys() | ||
.then((keys) => { | ||
this.#length = keys.length; | ||
resolve(this); | ||
}) | ||
.catch(() => { | ||
resolve(this); | ||
}); | ||
} | ||
async setItem(key: string, value: string) { | ||
keyCheck(key); | ||
await storage.setData(key, value); | ||
const keys = await storage.getKeys(); | ||
this.#length = keys.length; | ||
} | ||
async removeItem(key: string) { | ||
keyCheck(key); | ||
await storage.setData(key, undefined!); | ||
const keys = await storage.getKeys(); | ||
this.#length = keys.length; | ||
} | ||
async getItem(key: string) { | ||
keyCheck(key); | ||
try { | ||
return await storage.getData(key); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
async key(index: number): Promise<string | null> { | ||
try { | ||
const keys = await storage.getKeys(); | ||
return keys[index] ?? null; | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
async clear() { | ||
const keys = await storage.getKeys(); | ||
await Promise.all(keys.map((key) => storage.setData(key, undefined!))); | ||
this.#length = keys.length; | ||
} | ||
} | ||
|
||
const LocalStorage = { | ||
async removeItem(key: string) { | ||
return localStorage.removeItem(key); | ||
}, | ||
async getItem(key: string) { | ||
keyCheck(key); | ||
return localStorage.getItem(key); | ||
}, | ||
async setItem(key: string, value: string) { | ||
keyCheck(key); | ||
localStorage.setItem(key, value); | ||
}, | ||
async key(index: number) { | ||
return localStorage.key(index); | ||
}, | ||
async clear() { | ||
return localStorage.clear(); | ||
}, | ||
get length() { | ||
return localStorage.length; | ||
}, | ||
}; | ||
|
||
const AppStorage: AppStorage = await new Promise((resolve) => { | ||
if (isNeutralino) { | ||
new NeutralinoStorageClass(resolve); | ||
} else { | ||
resolve(LocalStorage); | ||
} | ||
}); | ||
|
||
declare global { | ||
var appStorage: AppStorage; | ||
} | ||
|
||
globalThis.appStorage = AppStorage; | ||
|
||
export default AppStorage; |