You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

2 years ago
'use strict';
let debug = false,
font: any,
settings: any;
2 years ago
let socket: any;
2 years ago
let antiCacheQuery = '?_=' + new Date().getTime();
let manager;
const p = new p5((p: p5) => {
p.preload = () => {
settings = p.loadJSON('data/settings/settings.json' + antiCacheQuery, {}, 'json', (json: any) => {
console.log('Local settings loaded: ', json);
}, (error: any) => {
console.log('Local settings failed: ', error);
});
font = p.loadFont('data/styles/fonts/Tajawal/Tajawal-Regular.ttf' + antiCacheQuery, (font: any) => {
console.log('Local font loaded: ', font);
}, (error: any) => {
console.log('Local font failed: ', error);
});
}
p.setup = () => {
interfaceSetup();
canvasSetup();
eventsSetup();
loadDynamicScripts().then(() => {
//Load other stuff
manager = new Manager();
});
}
p.draw = () => {
p.background(30);
if (manager){
manager.update();
manager.draw();
}
if (debug) debugInformation();
}
});
function debugInformation(){
}
function interfaceSetup(){
}
function canvasSetup(){
p.frameRate(60);
let element = $('#canvas_holder');
let w = element.width(),
h = element.height();
let canvas = p.createCanvas(w, h);
canvas.parent('canvas_holder');
p.textFont(font);
}
async function loadDynamicScripts(){
const json = await p.httpGet('data/settings/libraries.json' + antiCacheQuery, 'json') as Object;
let requests = [];
for (let script in json) {
if (json[script]) {
let url = '/lib/benjocraeft/' + script + '.js';
requests.push($.getScript(url, () => {
console.log('Successfully loaded script: ', url);
}));
}
}
await $.when(...requests);
console.log('All dynamic scripts have been loaded!');
}