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.

95 lines
2.2 KiB

2 years ago
'use strict';
let debug = false,
font,
settings,
loader;
//Only for online games
let socket;
let antiCacheQuery = '?_=' + new Date().getTime();
let colors;
const p = new p5((p) => {
p.preload = () => {
settings = p.loadJSON('data/settings/settings.json' + antiCacheQuery, {}, 'json', (json) => {
console.log('Local settings loaded: ', json);
}, (error) => {
console.log('Local settings failed: ', error);
});
font = p.loadFont('data/styles/fonts/Tajawal/Tajawal-Regular.ttf' + antiCacheQuery, (font) => {
console.log('Local font loaded: ', font);
}, (error) => {
console.log('Local font failed: ', error);
});
};
p.setup = () => {
interfaceSetup();
canvasSetup();
//loader = new Loader(p.createVector(p.width / 2, p.height / 2), Math.min(p.width, p.height) / 2);
loadDynamicScripts().then(() => {
//Load other stuff, then =>
//loader = null;
colors = new Colors();
colors.display();
});
};
p.draw = () => {
p.background(30);
if (loader){
loader.update();
loader.display();
}
if (colors){
colors.display();
}
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);
p.frameRate(5);
}
async function loadDynamicScripts(){
const json = await p.httpGet('data/settings/libraries.json' + antiCacheQuery, 'json');
let requests = [];
for (let script in json) {
if (json.hasOwnProperty(script)){
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!');
}