cdf
Version:
A library for creating oldschool demo-like animations with JavaScript
70 lines (59 loc) • 1.94 kB
JavaScript
/** CODEFF to CODEF bindings */
(function (global, codef_var) {
var codef = global[codef_var];
var lib = codef;
if(!codef.shutup) console.log('CODEF legacy v.1.1', codef);
if (global.THREE) {
['FlatShading', 'Texture', 'SmoothShading', 'SphericalReflectionMapping', 'LineBasicMaterial', 'MeshBasicMaterial', 'MeshLambertMaterial']
.forEach(function (name) {
global[name] = THREE[name];
});
}
lib.Canvas.prototype.triangle = function (x1, y1, x2, y2, x3, y3, color) {
return this.poly([[x1,y1],[x2,y2],[x3,y3]], color);
};
lib.Canvas.prototype.quad = function (x1, y1, x2, y2, x3, y3, x4, y4, color) {
//TODO: Move to legacy
this.ctx.save();
if (arguments.length < 8) {
if(x3)this.ctx.fillStyle = x3;
this.ctx.fillRect(x1, y1, x2, y2);
} else {
this.poly([[x1,y1],[x2,y2],[x3,y3],[x4,y4]], color);
}
this.ctx.restore();
return this;
};
if(codef.decrunch){
global.AtariDecrunch = codef.decrunch.atari;
global.AmigaDecrunch = codef.decrunch.amiga;
global.DOSDecrunch = codef.decrunch.dos;
}
var legacy = [
'addstats', 'updatestats', 'codef_stats',
'canvas', 'image',
'starfield3D', 'starfield2D_img', 'starfield2D_dot',
'codef3D',
'scrolltext_horizontal', 'scrolltext_vertical', 'ltrobj', 'sortPosx', 'sortPosy',
'FX',
'grad',
'music'
];
// TODO: Check if legacy for mouse works fine
if(codef.MouseTracker){
codef.MouseTracker.prototype.MouseUpdate = function () {
codef.MouseTracker.prototype.update.call(this);
this.canvas_list.forEach(function(c){
c.MouseButt = c.mouse.button;
c.MousePosX = c.mouse.x;
c.MousePosY = c.mouse.y;
});
}
}
global['requestAnimFrame'] = codef['frame'];
legacy.forEach(function (legacy_name) {
if (codef[legacy_name]) {
global[legacy_name] = codef[legacy_name];
}
});
})(this, 'cdf');