var gulp = require('gulp'); var concat = require('gulp-concat'); var sort = require('gulp-sort'); var minify = require('gulp-minify'); var replace = require('gulp-string-replace'); gulp.task('build', build); gulp.task('monitor', monitor); var code = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code += '\t\tapiComponent = {};\n'; code += '\t}\n'; code += '\tthis.apiComponent = apiComponent;\n'; code += '\n'; code += '\tR3.API.Component.call(\n'; code += '\t\tthis,\n'; code += '\t\tthis.apiComponent.parent,\n'; code += '\t\tthis.apiComponent.id,\n'; code += '\t\tthis.apiComponent.name,\n'; code += '\t\tthis.apiComponent.register,\n'; code += '\t\tthis.apiComponent.selected\n'; code += '\t)'; var code2 = 'R3.D3.API.Geometry.Buffer.call(\n'; code2 += '\t\tthis,\n'; code2 += '\t\tapiComponent\n'; code2 += '\t)'; var code3 = 'R3.D3.API.Geometry.Normal.call(\n'; code3 += '\t\tthis,\n'; code3 += '\t\tapiComponent\n'; code3 += '\t)'; var code4 = 'R3.D3.API.Material.call(\n'; code4 += '\t\tthis,\n'; code4 += '\t\tapiComponent\n'; code4 += '\t)'; 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'; 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'; code6 += '\tthis.coder\t\t= null;\n'; 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'; code6 += '\t\t\tthis.coder\t\t= runtime.coder;\n'; 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'; 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);'; function build() { return gulp.src('./src/r3-*.js') .pipe(sort()) .pipe(concat('r3.js')) .pipe(replace('__DATE__', new Date().toString())) .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)) .pipe(minify({ ext:{ src:'.js', min:'-min.js' } })) .pipe(gulp.dest('./build/')); } function monitor() { gulp.watch('src/*.js', build); } gulp.task( 'default', gulp.series( build, monitor ) );