Thanks Alpha Systems for that.
Click Save and Exit and wait until you will be back to the main menu.
game.loadData(src)
functiongame.saveCache(__dirname,files)
method for storing files for offline playReload the page
Save exporter & importer
modIf you want to create your own mod, create javascript file in mods/ directory, for example: mods/my-mod/my-mod.js
Now you must to add exported install function:
export function install(){
}
Now you can add some logic, for example I tried to add listener for buttons in-game that open links, and print in console.log what they want to open:
export function install(){
const original_open=window.open;
window.open=function(url, target, windowFeatures){
console.log(url,target,windowFeatures);
original_open(url,target,windowFeatures);
}
}
Now you need to modify mods.json, add your new mod to list:
{
"mods":[
// Other mods:
{...},
// Your mod:
{
"name":"Example mod",
"description":"Example description",
"script":"example-script",
"version":"1.0.0"
}
]
}
Now you can start the server, e.g. via NodeJS http-server and run the game:
Below is an simple example of loading a custom data.js file:
import { game } from "../toolkit.js";
const __dirname=import.meta.url.split("/").splice(0,import.meta.url.split("/").length-1).join("/");
const offlineFiles=[
"assets/image.png",
"assets/audio.ogg"
];
export async function install(){
await game.loadData(`${__dirname}/custom-data.js`);
await game.saveCache(__dirname,offlineFiles);
}
mods/
└── before-dayz/
├── before-dayz.js
├── custom-data.js
└── assets/
├── image.png
└── audio.ogg
All data.js modifications are saved to the browser memory, so offline play is possible