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.
 
 
 
 

100 lines
2.2 KiB

'use strict';
let projectName = "chainreact";
let debug = false,
productionMode = false,
font,
localSettings,
loader;
//Only for online games
let socket;
let game;
let gemContentImage;
let gemBorderImage;
let gemContentGraphics = {};
let antiCacheQuery = '?_=' + new Date().getTime();
let p;
p = new p5(s => {
s.preload = () => {
localSettings = p.loadJSON('data/settings/settings.json' + antiCacheQuery, json => {
console.log('Local settings loaded: ', json);
}, error => {
console.log('Local settings failed: ', error);
});
font = p.loadFont('data/styles/Tajawal/Tajawal-Regular.ttf', json => {
console.log('Local font loaded: ', json);
}, error => {
console.log('Local font failed: ', error);
});
gemContentImage = p.loadImage('data/images/gem_content.png', img => {
console.log('Image loaded: ', img);
}, error => {
console.log('Image failed: ', error);
});
gemBorderImage = p.loadImage('data/images/gem_border.png', img => {
console.log('Image loaded: ', img);
}, error => {
console.log('Image failed: ', error);
});
p.loadJSON('data/settings/libraries.json' + antiCacheQuery, json => {
loadScripts(json)
console.log('BenjoCraeft library scripts loaded: ', json)
});
};
s.setup = () => {
canvasSetup();
interfaceSetup();
}
s.draw = () => {
p.background(0, 0, 10);
if (game){
game.display();
game.update();
}
}
}, null, null);
function canvasSetup(){
p.setFrameRate(60);
let w = $('#canvas-holder').width(),
h = $('#canvas-holder').height();
let canvas = p.createCanvas(w, h);
canvas.parent('canvas-holder');
p.textFont(font);
p.textAlign(p.CENTER, p.CENTER);
p.imageMode(p.CENTER);
p.colorMode(p.HSB);
}
function interfaceSetup(){
window.onresize();
setInterval(() => window.onresize(), 500);
$('#start_feedback, #give_feedback').attr('disabled', 'disabled');
nameTyped($('#main > input'));
$('#main').fadeIn(menuesFadeTime);
}
function loadScripts(libs){
for (let script in libs){
if (libs[script]){
let url = '/lib/benjocraeft/' + script + '.js'
$.getScript(url, () => {
console.log('Successfully loaded script: ', url)
});
}
}
}