Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkLightTuna committed Sep 18, 2023
1 parent 9db2651 commit 8adc530
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
14 changes: 3 additions & 11 deletions src/module.mjs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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) => {
Expand Down
5 changes: 4 additions & 1 deletion src/settings-form-application.mjs
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions src/sync.mjs
Original file line number Diff line number Diff line change
@@ -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(
{
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/util.mjs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
}

0 comments on commit 8adc530

Please sign in to comment.