diff --git a/package.json b/package.json index e6d5518..e59a6c6 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,6 @@ }, "scripts": { "build": "esbuild src/module.mjs --bundle --minify --format=esm --outdir=dist", - "build-dev": "esbuild src/module.mjs --bundle --format=esm --outdir=dist && mkdir -p ../foundry_data/Data/modules/oronder/ && cp -r ./* ../foundry_data/Data/modules/oronder/" + "build-dev": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist && mkdir -p ../foundry_data/Data/modules/oronder/ && cp -r ./* ../foundry_data/Data/modules/oronder/" } } diff --git a/src/module.mjs b/src/module.mjs index 0906388..9284b3b 100644 --- a/src/module.mjs +++ b/src/module.mjs @@ -1,10 +1,7 @@ import {Logger} from "./util.mjs"; import {registerSettings} from "./settings.mjs"; -import {ACTORS, ID_MAP, MODULE_ID} from "./constants.mjs"; -import {enrich_actor, sync_actor} from "./sync.mjs" -import hash from 'object-hash'; - -// import {hash} from "./lib/object_hash.js"; +import {ID_MAP, MODULE_ID} from "./constants.mjs"; +import {sync_actor} from "./sync.mjs" let socket; @@ -46,12 +43,7 @@ Hooks.on("createActor", async (actor, data, options, userId) => { await sync_actor(actor) }) Hooks.on("updateActor", async (actor, data, options, userId) => { - const old_hash = localStorage.getItem(`${ACTORS}.actor.id`) - const actor_obj = enrich_actor(actor) - // const new_hash = hash(actor_obj) - const new_hash = '' - localStorage.setItem(`${ACTORS}.actor.id`, new_hash) - // await sync_actor(actor) + await sync_actor(actor) //todo handle incremental updates }) Hooks.on("deleteActor", async (actor, data, options, userId) => { diff --git a/src/settings-form-application.mjs b/src/settings-form-application.mjs index da4c5f3..f1ff861 100644 --- a/src/settings-form-application.mjs +++ b/src/settings-form-application.mjs @@ -1,5 +1,6 @@ import {Logger} from "./util.mjs"; import {AUTH, GUILD_ID, ID_MAP, MODULE_ID, ORONDER_BASE_URL, VALID_CONFIG} from "./constants.mjs"; +import {full_sync} from "./sync.mjs"; export class OronderSettingsFormApplication extends FormApplication { @@ -171,10 +172,12 @@ export class OronderSettingsFormApplication extends FormApplication { } return response.json() }) - .then(result => { + .then(async result => { for (const [foundry_name, discord_user_id] of Object.entries(result)) { this.object.players.find(p => p.foundry_name === foundry_name).discord_id = discord_user_id } + + await full_sync() }) .catch(error => { Logger.logError(error) diff --git a/src/sync.mjs b/src/sync.mjs index 61bf6e5..29cfb51 100644 --- a/src/sync.mjs +++ b/src/sync.mjs @@ -1,6 +1,5 @@ import {ACTORS, AUTH, GUILD_ID, ID_MAP, MODULE_ID, ORONDER_BASE_URL} from "./constants.mjs"; - -// import {hash} from "./lib/object_hash.js"; +import {hash} from "./util.mjs"; function prune_roll_data( { @@ -178,7 +177,7 @@ export async function sync_actor(actor) { const old_hash = localStorage.getItem(`${ACTORS}.actor.id`) const actor_obj = enrich_actor(actor) - const new_hash = 'hash(actor_obj)' + const new_hash = hash(actor_obj) // const new_hash = hash(actor_obj) if (!old_hash || old_hash !== new_hash) { const response = await upload(actor_obj) diff --git a/src/util.mjs b/src/util.mjs index 0dc35c6..dc21188 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -1,4 +1,5 @@ import {MODULE_DEBUG_TAG} from "./constants.mjs"; +import objectHash from 'object-hash'; /** * Utility class to handle logging to console with an attached debug tag to identify module logs. @@ -41,4 +42,10 @@ export class Logger { */ function _processLog(logString) { return [...MODULE_DEBUG_TAG, logString]; +} + +const hash_options = {unorderedArrays: true, respectType: false} + +export function hash(obj) { + return objectHash(obj, hash_options) } \ No newline at end of file