Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
oWave committed Aug 19, 2024
1 parent b32e087 commit ffacc4b
Show file tree
Hide file tree
Showing 25 changed files with 1,451 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "18"
node-version: "20"
cache: "yarn"

- run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
node_modules/
.vscode/
.vite-cache/
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dist/module.js"
],
"styles": [
"styles/main.css"
"dist/style.css"
],
"flags": {
"hotReload": {
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"author": "oWave",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"watch": "esbuild src/index.ts --outfile=dist/module.js --sourcemap --bundle --watch",
"build": "esbuild src/index.ts --outfile=dist/module.js --bundle",
"lint": "eslint src/",
"dev": "vite serve",
"build": "vite build",
"unpack": "fvtt package workon \"pf2e-flatcheck-helper\" && fvtt package unpack \"effects\"",
"pack": "fvtt package workon \"pf2e-flatcheck-helper\" && fvtt package pack \"effects\""
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/jquery": "^3.5.30",
"@types/node": "^22.3.0",
"typescript": "*",
"vite": "^5.4.0",
"vite-plugin-checker": "^0.7.2"
"vite-plugin-checker": "^0.7.2",
"vite-tsconfig-paths": "^5.0.1"
},
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447",
"dependencies": {}
Expand Down
108 changes: 0 additions & 108 deletions src/flat.ts

This file was deleted.

54 changes: 42 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MODULE_ID } from "./constants"
import { setupDelay } from "./delay"
import { setupEmanationAutomation } from "./emanation"
import { setupFlat } from "./flat"
import { setupLink } from "./life-link"
import { DelayModule } from "./modules/delay"
import { EmanationModule } from "./modules/emanation/emanation"
import { settings } from "./settings"
import { FlatModule } from "./modules/flat/flat"
import { LifeLinkModule } from "./modules/life-link"

type Callback = (data: any) => void

Expand All @@ -21,6 +21,9 @@ class SocketHandler {
register(type: string, handler: Callback) {
this.#callbacks[type] = handler
}
unregister(type: string) {
delete this.#callbacks[type]
}

emit(type: string, data: any) {
if (!(type in this.#callbacks)) {
Expand All @@ -33,24 +36,51 @@ class SocketHandler {
}
}

const module = {
const MODULE = {
socketHandler: new SocketHandler(),
settings,
modules: {
flat: new FlatModule(),
delay: new DelayModule(),
emanation: new EmanationModule(),
lifeLink: new LifeLinkModule(),
},
}

export default module
export default MODULE

Hooks.on("init", () => {
module.settings.init()
module.socketHandler.init()
MODULE.settings.init()
MODULE.socketHandler.init()

for (const [name, module] of Object.entries(MODULE.modules)) {
const enabled =
module.settingsKey == null
? true
: (game.settings.get(MODULE_ID, module.settingsKey) as boolean)

setupDelay()
setupFlat()
setupLink()
if (enabled) module.enable()
}
})

Hooks.on("ready", () => {
setupEmanationAutomation()
for (const [name, module] of Object.entries(MODULE.modules)) {
if (module.enabled) module.onReady()
}
})

Hooks.on("updateSetting", (setting: { key: string }, data) => {
if (!setting.key.startsWith(MODULE_ID)) return

const key = setting.key.split(".", 2).at(1)
if (!key) return

for (const m of Object.values(MODULE.modules).filter((m) => m.settingsKey === key)) {
if (data.value === "true") {
m.enable()
if (m.enabled) m.onReady()
} else if (data.value === "false") m.disable()
}
})

Hooks.on("renderSettingsConfig", (app: SettingsConfig, $html: JQuery) => {
Expand Down
Loading

0 comments on commit ffacc4b

Please sign in to comment.