r3-legacy/gulpfile.js

163 lines
5.2 KiB
JavaScript
Raw Normal View History

var gulp = require('gulp');
var concat = require('gulp-concat');
var sort = require('gulp-sort');
var minify = require('gulp-minify');
2018-11-15 14:50:58 +01:00
var replace = require('gulp-string-replace');
2016-10-14 12:32:53 +02:00
2018-11-21 20:57:14 +01:00
gulp.task('build', build);
gulp.task('monitor', monitor);
2019-07-24 14:45:42 +02:00
var code = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
code += '\t\tapiComponent = {};\n';
code += '\t}\n';
code += '\tthis.apiComponent = apiComponent;\n';
2019-07-24 08:08:02 +02:00
code += '\n';
2019-07-24 14:45:42 +02:00
code += '\tR3.API.Component.call(\n';
code += '\t\tthis,\n';
code += '\t\tthis.apiComponent.parent,\n';
code += '\t\tthis.apiComponent.id,\n';
2019-08-10 19:48:08 +02:00
code += '\t\tthis.apiComponent.name,\n';
code += '\t\tthis.apiComponent.register,\n';
code += '\t\tthis.apiComponent.selected\n';
2019-07-25 22:22:32 +02:00
code += '\t)';
2019-07-24 14:45:42 +02:00
2019-10-06 21:11:18 +02:00
var code2 = 'R3.D3.API.Geometry.Buffer.call(\n';
2019-07-24 14:45:42 +02:00
code2 += '\t\tthis,\n';
2019-10-06 21:11:18 +02:00
code2 += '\t\tapiComponent\n';
2019-07-25 22:22:32 +02:00
code2 += '\t)';
2019-07-24 14:45:42 +02:00
2019-10-06 21:11:18 +02:00
var code3 = 'R3.D3.API.Geometry.Normal.call(\n';
2019-07-24 14:45:42 +02:00
code3 += '\t\tthis,\n';
2019-10-06 21:11:18 +02:00
code3 += '\t\tapiComponent\n';
2019-07-25 22:22:32 +02:00
code3 += '\t)';
2019-07-24 14:45:42 +02:00
2019-10-06 21:11:18 +02:00
var code4 = 'R3.D3.API.Material.call(\n';
2019-07-24 14:45:42 +02:00
code4 += '\t\tthis,\n';
2019-10-06 21:11:18 +02:00
code4 += '\t\tapiComponent\n';
2019-07-25 22:22:32 +02:00
code4 += '\t)';
2019-07-24 14:45:42 +02:00
var code5 = 'if (R3.Utils.UndefinedOrNull(apiTexture)) {\n';
code5 += '\t\tapiTexture = {};\n';
code5 += '\t}\n';
code5 += '\tthis.apiTexture = apiTexture;\n';
code5 += '\n';
code5 += '\tR3.D3.API.Texture.call(\n';
code5 += '\t\tthis,\n';
code5 += '\t\tthis.apiTexture,\n';
code5 += '\t\tthis.apiTexture.parentMaterials,\n';
code5 += '\t\tthis.apiTexture.mipmaps,\n';
code5 += '\t\tthis.apiTexture.mapping,\n';
code5 += '\t\tthis.apiTexture.wrapS,\n';
code5 += '\t\tthis.apiTexture.wrapT,\n';
code5 += '\t\tthis.apiTexture.magFilter,\n';
code5 += '\t\tthis.apiTexture.minFilter,\n';
code5 += '\t\tthis.apiTexture.anisotropy,\n';
code5 += '\t\tthis.apiTexture.format,\n';
code5 += '\t\tthis.apiTexture.storageType,\n';
code5 += '\t\tthis.apiTexture.offset,\n';
code5 += '\t\tthis.apiTexture.repeat,\n';
code5 += '\t\tthis.apiTexture.rotation,\n';
code5 += '\t\tthis.apiTexture.center,\n';
code5 += '\t\tthis.apiTexture.matrixAutoUpdate,\n';
code5 += '\t\tthis.apiTexture.generateMipMaps,\n';
code5 += '\t\tthis.apiTexture.premultiplyAlpha,\n';
code5 += '\t\tthis.apiTexture.flipY,\n';
code5 += '\t\tthis.apiTexture.unpackAlignment,\n';
code5 += '\t\tthis.apiTexture.encoding,\n';
code5 += '\t\tthis.apiTexture.version,\n';
code5 += '\t\tthis.apiTexture.animated,\n';
code5 += '\t\tthis.apiTexture.reverseAnimation,\n';
code5 += '\t\tthis.apiTexture.forward\n';
2019-07-25 22:22:32 +02:00
code5 += '\t)';
var code6 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
code6 += '\t\tapiComponent = {};\n';
code6 += '\t}\n';
code6 += '\tthis.apiComponent = apiComponent;\n';
code6 += '\n';
code6 += '\tthis.graphics\t= null;\n';
code6 += '\tthis.physics\t= null;\n';
2019-10-06 21:11:18 +02:00
code6 += '\tthis.coder\t\t= null;\n';
2019-07-25 22:22:32 +02:00
code6 += '\tthis.gui\t\t= null;\n';
code6 += '\tthis.stats\t\t= null;\n';
code6 += '\n';
code6 += '\tR3.Event.Emit(\n';
code6 += '\t\tR3.Event.GET_RUNTIME,\n';
code6 += '\t\tfunction(runtime) {\n';
code6 += '\t\t\tthis.graphics\t= runtime.graphics;\n';
code6 += '\t\t\tthis.physics\t= runtime.physics;\n';
2019-10-06 21:11:18 +02:00
code6 += '\t\t\tthis.coder\t\t= runtime.coder;\n';
2019-07-25 22:22:32 +02:00
code6 += '\t\t\tthis.gui\t\t= runtime.gui;\n';
code6 += '\t\t\tthis.stats\t\t= runtime.stats;\n';
code6 += '\t\t}.bind(this)\n';
2019-10-06 21:11:18 +02:00
code6 += '\t);\n';
code6 += '\n';
code6 += '\tthis.initialize(apiComponent)';
var code7 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
code7 += '\t\tapiComponent = {};\n';
code7 += '\t}\n';
code7 += '\n';
code7 += '\tif (R3.Utils.UndefinedOrNull(apiComponent.register)) {\n';
code7 += '\t\tapiComponent.register = false;\n';
code7 += '\t}\n';
code7 += '\n';
code7 += '\tR3.Event.Emit(\n';
code7 += '\t\tR3.Event.GET_REGISTER_FACES,\n';
code7 += '\t\tnull,\n';
code7 += '\t\tfunction(register) {\n';
code7 += '\t\t\tif (register) {\n';
code7 += '\t\t\t\tapiComponent.register = true;\n';
code7 += '\t\t\t}\n';
code7 += '\t\t}\n';
code7 += '\t)';
var code8 = 'R3.Component.call(this)';
var code9 = 'R3.Component.prototype.createInstance.call(this)';
var code10 = 'R3.Component.prototype.updateInstance.call(this, property)';
var code11 = 'R3.D3.Geometry.Buffer.call(\n';
code11 += '\t\tthis,\n';
code11 += '\t\ttrue\n';
code11 += '\t);';
2019-07-24 08:08:02 +02:00
2018-11-21 20:57:14 +01:00
function build() {
return gulp.src('./src/r3-*.js')
.pipe(sort())
.pipe(concat('r3.js'))
.pipe(replace('__DATE__', new Date().toString()))
2019-10-06 21:11:18 +02:00
.pipe(replace('__API_COMPONENT__', code))
.pipe(replace('__API_GEOMETRY_BUFFER__', code2))
.pipe(replace('__API_GEOMETRY_NORMAL__', code3))
.pipe(replace('__API_MATERIAL__', code4))
.pipe(replace('__API_TEXTURE__', code5))
.pipe(replace('__RUNTIME_COMPONENT__', code6))
.pipe(replace('__DEREGISTER_COMPONENT__', code7))
.pipe(replace('__UPGRADE_TO_RUNTIME__', code8))
.pipe(replace('__CREATE_INSTANCE__', code9))
.pipe(replace('__UPDATE_INSTANCE__', code10))
.pipe(replace('__RUNTIME_BUFFER_COMPONENT__', code11))
2018-11-21 20:57:14 +01:00
.pipe(minify({
ext:{
src:'.js',
min:'-min.js'
}
}))
.pipe(gulp.dest('./build/'));
}
function monitor() {
gulp.watch('src/*.js', build);
}
2016-10-14 12:32:53 +02:00
gulp.task(
'default',
2018-11-21 20:57:14 +01:00
gulp.series(
build,
monitor
)
2019-07-24 08:08:02 +02:00
);