Skip to content

Commit

Permalink
ResourceBuilder updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbudone committed Apr 14, 2018
1 parent bedd642 commit 01c379c
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 339 deletions.
2 changes: 2 additions & 0 deletions NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ WORKING ON (was previously working on)
- Validate JSON on startup: validate all JSON data files on startup to ensure we don't run into unexpected issues
* - Combat feel:
- enemy runs to you before you've reached them, so you are both out of place
Attacking enemy: Enemy should anticipate that you're about to attack them, and wait instead of aggro
Not attacking enemy: If you pass by an enemy and go into aggro range -- ???
- takes a while to autoattack enemy
- damage feels too late: you get hit at the same time that you kill the enemy?
- Reloading npcs:
Expand Down
23 changes: 21 additions & 2 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ requirejs(['keys', 'environment'], (Keys, Environment) => {
}
});

requirejs(
const continueStartup = () => {

requirejs(
[
'objectmgr', 'utilities', 'extensions', 'event', 'errors', 'fsm', 'profiler'
],
Expand Down Expand Up @@ -365,7 +367,7 @@ requirejs(['keys', 'environment'], (Keys, Environment) => {
_.each(The.world.areas, (area) => {
_.each(area.movables, (movable) => {
if (movable.playerID) return;
movable.character.loadStats();
movable.character.reloadNPC();
});
});
}
Expand Down Expand Up @@ -718,4 +720,21 @@ requirejs(['keys', 'environment'], (Keys, Environment) => {
})
.catch((e) => { errorInGame(e); });
});
};

// Check ResourceBuilder in case our resources are out of sync
const { exec } = require('child_process');
console.log("Checking resourceBuilder if resources are in sync");
exec('node resourceBuilder.js --needs-rebuild', (error, stdout, stderr) => {

console.log(stdout);
console.error(stderr);

if (error) {
console.error(error);
return;
}

continueStartup();
});
});
90 changes: 49 additions & 41 deletions resourceBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@ const Settings = {
}

// Process Server arguments
process.argv.forEach((val) => {
for (let i=0; i<process.argv.length; ++i) {

if (val === "--force-rebuild") {
const arg = process.argv[i];

if (arg === "--force-rebuild") {
console.log("Recaching all resources");
Settings.forceRebuild = true;
}

if (val === "--needs-rebuild") {
if (arg === "--needs-rebuild") {
console.log("Checking if resources need rebuilding");
Settings.checkNeedsRebuild = true;
}
});

if (arg === "--package") {
const filterPackage = process.argv[++i];
console.log("Filtering package: " + filterPackage);
Settings.filterPackage = filterPackage;
}
}

// Prepare openpgp stuff
openpgp.initWorker({ path: 'node_modules/openpgp/dist/openpgp.worker.js' }) // set the relative web worker path
Expand Down Expand Up @@ -98,23 +106,44 @@ openpgp.config.aead_protect = true // activate fast AES-GCM mode (not yet OpenPG
//
//
// -- get rid of areahashes and just use world.json for hash (would need 2 types of hashes stored here)
// -- Process hashing: compare processedHash === distHash && rawHash === hash (in case raw asset changed, but also in case we encrypt so hash !== distHash ever)
// 8) Filter asset if necessary (specified package or resource)
// 9) --force-rebuild
// 10) Integrate w/ Grunt
// 11) --needs-rebuild
// 8) Filter asset if necessary (specified package or resource) --- if we update an asset does that mean we'll always update the package? If so then we should only filter packages in Grunt. Can Grunt listen for changes and wait X seconds before recompiling? (exceptions: npcs.json or other pure data files?), could store a list of files that have changed and pass them all into here
// - what if we have nested packages, and change one of those packages -- might need a delay?
// - delay: what if we change a package (automated) and continue processing w/ intention of changing another package or the same one again -- delay is dependent on that process finishing
// - we could ONLY watch certain packages, and expect other packages (eg. sheets) to rebuild via exporter -- but what if we touch it manually?
// - some files we want to reload immediately (eg. npcs, buffs, testing)
//
// -- Watch/Rebuild immediately: list of packages (npcs, buffs, etc.)
// -- Watch/Rebuild after delay (careful w/ delay time): list of packages (sheets, media, avatars, world)
// 10) Integrate w/ Grunt & Server
// - Grunt: Watch Resource packages; list of those w/ rebuild delay/immediate
// - Grunt: Rebuild when necessary -- read exit code for indicator of failure
// - Server: --needs-rebuild ; read exit code to determine, then exit if needed
// -- move this to tools/
// -- nicer output (colours n shiz)
// -- clean this file up
// -- get rid of references to old caching system in js
// -- hash -> processedHash; rawHash -> hash
// -- get rid of cache.json

let Resources = null;

const packageRoutines = {
"resources": {
"read": (data) => {
const assets = [];
_.forEach(data, (packageDetails, packageName) => {
let packageData = data;
if (Settings.filterPackage) {
packageData = {};
const package = data[Settings.filterPackage];
if (!package) {
console.error("Could not find package: " + Settings.filterPackage + "!");
process.exit(1);
}

packageData[Settings.filterPackage] = package;
}

_.forEach(packageData, (packageDetails, packageName) => {
assets.push({
name: packageName,
file: 'resources/data/' + packageDetails.file,
Expand Down Expand Up @@ -387,42 +416,21 @@ let fileHash = (file) => {
};

let readPackage = (package, file) => {

return new Promise((success, fail) => {
fs.readFile(file, (err, bufferData) => {

// FIXME: Would be nice to not need to read file twice for hash + read
const hash = crypto.createHash('md5'),
rawAssetFd = fs.createReadStream(file);

rawAssetFd.on('end', () => {

// Finished piping raw asset into the hasher
hash.end();

const rawAssetHash = hash.read().toString('hex');

rawAssetFd.destroy();
hash.destroy();

fs.readFile(file, (err, bufferData) => {

if (err) {
console.error(`Error reading package: ${err}`);
fail(err);
return;
}
if (err) {
console.error(`Error reading package: ${err}`);
fail(err);
return;
}

const data = JSON.parse(bufferData),
packageRoutine = packageRoutines[package],
assets = packageRoutine.read(data);
const data = JSON.parse(bufferData),
packageRoutine = packageRoutines[package],
assets = packageRoutine.read(data);

success({data, assets});
//success({data, assets, hash: rawAssetHash});
});
success({data, assets});
});

rawAssetFd.pipe(hash);

});
};

Expand Down
96 changes: 1 addition & 95 deletions resources/data/media.json
Original file line number Diff line number Diff line change
@@ -1,95 +1 @@
{
"list": [
{
"name": "deathsickness",
"file": "icons/deathsickness.png",
"hash": "",
"output": "icons/deathsickness.webp",
"type": "image",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": "convert"
}
},
{
"name": "muted",
"file": "icons/muted.png",
"hash": "",
"output": "icons/muted.webp",
"type": "image",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": "convert"
}
},
{
"name": "unmuted",
"file": "icons/unmuted.png",
"hash": "",
"output": "icons/unmuted.webp",
"type": "image",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": "convert"
}
},
{
"name": "toolbelt",
"file": "icons/toolbelt.png",
"hash": "",
"output": "icons/toolbelt.webp",
"type": "image",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": "convert"
}
},
{
"name": "uiclick",
"file": "sounds/uiclick.mp3",
"hash": "",
"output": "sounds/uiclick.mp3",
"type": "sound",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": false
}
},
{
"name": "grunt",
"file": "sounds/grunt.mp3",
"hash": "",
"output": "sounds/grunt.mp3",
"type": "sound",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": false
}
},
{
"name": "rivervale",
"file": "sounds/rivervale.mp4",
"hash": "",
"output": "sounds/rivervale.mp4",
"type": "sound",
"options": {
"cached": false,
"encrypted": false,
"packed": false,
"preprocess": false
}
}
]
}
{"list":[{"name":"deathsickness","file":"icons/deathsickness.png","hash":"ce77407d138136f8c2335afe02ee5308","output":"icons/deathsickness.webp","type":"image","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":"convert"},"rawHash":"18d132e5c66047c71bd90a7195ca8d1e"},{"name":"muted","file":"icons/muted.png","hash":"dd64a34c6a307f7619efd7002879ef7f","output":"icons/muted.webp","type":"image","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":"convert"},"rawHash":"3c94322488ec73b12d81ef2184e5562e"},{"name":"unmuted","file":"icons/unmuted.png","hash":"a9251224cfcd8015cba47499cbcdfc19","output":"icons/unmuted.webp","type":"image","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":"convert"},"rawHash":"aa0406e2d1a2201f65cf32d2d255a86b"},{"name":"toolbelt","file":"icons/toolbelt.png","hash":"e3eaa364fe46a0addbeb3de8437b04d4","output":"icons/toolbelt.webp","type":"image","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":"convert"},"rawHash":"03328d931989fe312279ea46bf715ac6"},{"name":"uiclick","file":"sounds/uiclick.mp3","hash":"fed2eaf723576f39f59374562f2a6e19","output":"sounds/uiclick.mp3","type":"sound","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":false},"rawHash":"fed2eaf723576f39f59374562f2a6e19"},{"name":"grunt","file":"sounds/grunt.mp3","hash":"1ff24b0e1866b7c25f1025c698a97e21","output":"sounds/grunt.mp3","type":"sound","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":false},"rawHash":"1ff24b0e1866b7c25f1025c698a97e21"},{"name":"rivervale","file":"sounds/rivervale.mp4","hash":"33fe9ad7a029666e4abf6f94bd555106","output":"sounds/rivervale.mp4","type":"sound","options":{"cached":false,"encrypted":false,"packed":false,"preprocess":false},"rawHash":"33fe9ad7a029666e4abf6f94bd555106"}]}
79 changes: 1 addition & 78 deletions resources/data/resources.json
Original file line number Diff line number Diff line change
@@ -1,78 +1 @@
{
"media": {
"file": "media.json",
"options": {}
},
"sheets": {
"file": "sheets.json",
"options": {},
"hash": "4d28c7a0f9a2b9f3932c917fbc06190e"
},
"avatars": {
"file": "avatars.json",
"options": {},
"hash": "c66a7881e9f59139e5018be8a15db88c"
},
"npcs": {
"file": "npcs.json",
"options": {
"reloadable": true
},
"hash": "2da5f79e80b7470a8a58ee28fc0afb37"
},
"world": {
"file": "world.json",
"options": {},
"hash": "d3bccff2787a77abfee37251e914c48c"
},
"items": {
"file": "items.json",
"options": {},
"hash": "d35cbbfe03db647f3395941551aa4aee"
},
"buffs": {
"file": "buffs.json",
"options": {},
"hash": "d870c474633540c0f5a8509b4ba771d0"
},
"interactables": {
"file": "interactables.json",
"options": {},
"hash": "5f1950a78647aa90bc4048bb8b71cde3"
},
"quests": {
"file": "quests.json",
"options": {},
"hash": "429119de868b2b2b90cbdcdb4e6433ac"
},
"interactions": {
"file": "interactions.json",
"options": {},
"hash": "9557113f15326cddd142e843d9a2e231"
},
"scripts": {
"file": "scripts.json",
"options": {},
"hash": "5472e25e76309cf2cccd7886cf130ab8"
},
"components": {
"file": "components.json",
"options": {},
"hash": "316b4a9789084cfcf260fecb02c503c8"
},
"rules": {
"file": "rules.json",
"options": {},
"hash": "efdfbeab80c256347e3d63afdf7ccf0d"
},
"fx": {
"file": "fx.json",
"options": {},
"hash": "9cae6486264cb67ac14b3f8dd5851f64"
},
"testing": {
"file": "testing.json",
"options": {},
"hash": "d297e75c9190aa76e09638eb8d8e991c"
}
}
{"media":{"file":"media.json","options":{},"hash":"e2e48a203fba2b0b258addc06221aea5","rawHash":"e2e48a203fba2b0b258addc06221aea5"},"sheets":{"file":"sheets.json","options":{},"hash":"1ec4748fbea3f4ee90edf7a7180ed8af","rawHash":"1ec4748fbea3f4ee90edf7a7180ed8af"},"avatars":{"file":"avatars.json","options":{},"hash":"c66a7881e9f59139e5018be8a15db88c","rawHash":"c66a7881e9f59139e5018be8a15db88c"},"npcs":{"file":"npcs.json","options":{"reloadable":true},"hash":"2da5f79e80b7470a8a58ee28fc0afb37","rawHash":"2da5f79e80b7470a8a58ee28fc0afb37"},"world":{"file":"world.json","options":{},"hash":"40b914a125393d7907247078203a7e5d","rawHash":"40b914a125393d7907247078203a7e5d"},"items":{"file":"items.json","options":{},"hash":"d35cbbfe03db647f3395941551aa4aee","rawHash":"d35cbbfe03db647f3395941551aa4aee"},"buffs":{"file":"buffs.json","options":{},"hash":"d870c474633540c0f5a8509b4ba771d0","rawHash":"d870c474633540c0f5a8509b4ba771d0"},"interactables":{"file":"interactables.json","options":{},"hash":"5f1950a78647aa90bc4048bb8b71cde3","rawHash":"5f1950a78647aa90bc4048bb8b71cde3"},"quests":{"file":"quests.json","options":{},"hash":"429119de868b2b2b90cbdcdb4e6433ac","rawHash":"429119de868b2b2b90cbdcdb4e6433ac"},"interactions":{"file":"interactions.json","options":{},"hash":"9557113f15326cddd142e843d9a2e231","rawHash":"9557113f15326cddd142e843d9a2e231"},"scripts":{"file":"scripts.json","options":{},"hash":"5472e25e76309cf2cccd7886cf130ab8","rawHash":"5472e25e76309cf2cccd7886cf130ab8"},"components":{"file":"components.json","options":{},"hash":"316b4a9789084cfcf260fecb02c503c8","rawHash":"316b4a9789084cfcf260fecb02c503c8"},"rules":{"file":"rules.json","options":{},"hash":"efdfbeab80c256347e3d63afdf7ccf0d","rawHash":"efdfbeab80c256347e3d63afdf7ccf0d"},"fx":{"file":"fx.json","options":{},"hash":"9cae6486264cb67ac14b3f8dd5851f64","rawHash":"9cae6486264cb67ac14b3f8dd5851f64"},"testing":{"file":"testing.json","options":{},"hash":"d297e75c9190aa76e09638eb8d8e991c","rawHash":"d297e75c9190aa76e09638eb8d8e991c"}}
Loading

0 comments on commit 01c379c

Please sign in to comment.