diff --git a/gulpfile.js b/gulpfile.js index 4cf8763..e40e4b9 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,10 +6,9 @@ const Config = require('./config.json'); const packageInfo = require('./package.json'); const {Sdk, Haxe, Project, FlashPlayer} = require('gulp-haxetool'); const path = require('path'); -const fs = require('fs'); -const through = require('through2'); const dateformat = require('dateformat'); const argv = require('yargs').argv; +const publish = require('./tasks/gulp-publish'); if (Config.SdkDir) { Sdk.dir = Config.SdkDir; @@ -89,7 +88,10 @@ const client = new Project( ], config.branch({ name: 'client', - sources: ['src/client/haxe'], + sources: [ + 'src/fixes/haxe', + 'src/client/haxe', + ], main: 'ru.m.tankz.Client', preloader: 'ru.m.tankz.Preloader', assets: [ @@ -157,29 +159,7 @@ const server = new Project( /** * publish */ -exports.publish = function publish() { - const packages = []; - return gulp.src('target/client/@(android|archive|debian)/*') - .pipe(through.obj(function (file, enc, cb) { - const path = file.path.replace(file.base + '/', ''); - packages.push({ - type: path.split('/').shift(), - path: path, - filename: path.split('/').pop(), - url: `${Config.PublishUrl}/${path}`, - }); - this.push(file); - cb(null); - })) - .pipe(gulp.dest(Config.PublishDir)) - .on('end', function () { - fs.writeFileSync(path.join(Config.PublishDir, 'packages.json'), JSON.stringify({ - 'name': packageInfo.name, - 'version': packageInfo.version, - 'packages': packages, - }, null, 4)); - }); -}; +module.exports.publish = publish(config.name, config.version, Config.PublishDir); /** * default diff --git a/src/fixes/haxe/lime/utils/Float32Array.hx b/src/fixes/haxe/lime/utils/Float32Array.hx new file mode 100644 index 0000000..736d9c3 --- /dev/null +++ b/src/fixes/haxe/lime/utils/Float32Array.hx @@ -0,0 +1,164 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Float32Array as JSFloat32Array; +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Float32Array as JSFloat32Array; +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +@:arrayAccess +abstract Float32Array(JSFloat32Array) from JSFloat32Array to JSFloat32Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSFloat32Array(elements); + } + else if (array != null) + { + this = new JSFloat32Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSFloat32Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSFloat32Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSFloat32Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSFloat32Array(buffer, byteoffset); + } + else + { + this = new JSFloat32Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:Float):Float + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):Float + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float32Array + { + if (byteOffset == null) return new JSFloat32Array(cast bytes.getData()); + if (len == null) return new JSFloat32Array(cast bytes.getData(), byteOffset); + return new JSFloat32Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBuffer; +import lime.utils.ArrayBufferView; + +@:forward +abstract Float32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + public static var hello:Int; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Float32); + } + else if (array != null) + { + this = new ArrayBufferView(0, Float32).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Float32).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Float32).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Float32).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for Float32Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):Float32Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float32Array + { + return new Float32Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function toString() + return this != null ? 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; + + @:extern inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int):Float + { + return ArrayBufferIO.getFloat32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:Float):Float + { + ArrayBufferIO.setFloat32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/Float64Array.hx b/src/fixes/haxe/lime/utils/Float64Array.hx new file mode 100644 index 0000000..b546a33 --- /dev/null +++ b/src/fixes/haxe/lime/utils/Float64Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Float64Array as JSFloat64Array; +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Float64Array as JSFloat64Array; +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +abstract Float64Array(JSFloat64Array) from JSFloat64Array to JSFloat64Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 8; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSFloat64Array(elements); + } + else if (array != null) + { + this = new JSFloat64Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSFloat64Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSFloat64Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSFloat64Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSFloat64Array(buffer, byteoffset); + } + else + { + this = new JSFloat64Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:Float):Float + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):Float + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float64Array + { + if (byteOffset == null) return new JSFloat64Array(cast bytes.getData()); + if (len == null) return new JSFloat64Array(cast bytes.getData(), byteOffset); + return new JSFloat64Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + function toString() + return this != null ? 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract Float64Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 8; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Float64); + } + else if (array != null) + { + this = new ArrayBufferView(0, Float64).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Float64).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Float64).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Float64).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for Float64Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):Float64Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float64Array + { + return new Float64Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int):Float + { + return ArrayBufferIO.getFloat64(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:Float):Float + { + ArrayBufferIO.setFloat64(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } + + inline function toString() + return this != null ? 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/Int16Array.hx b/src/fixes/haxe/lime/utils/Int16Array.hx new file mode 100644 index 0000000..1cd5faf --- /dev/null +++ b/src/fixes/haxe/lime/utils/Int16Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Int16Array as JSInt16Array; +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Int16Array as JSInt16Array; +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +abstract Int16Array(JSInt16Array) from JSInt16Array to JSInt16Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 2; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSInt16Array(elements); + } + else if (array != null) + { + this = new JSInt16Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSInt16Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSInt16Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSInt16Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSInt16Array(buffer, byteoffset); + } + else + { + this = new JSInt16Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):Int + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int16Array + { + if (byteOffset == null) return new JSInt16Array(cast bytes.getData()); + if (len == null) return new JSInt16Array(cast bytes.getData(), byteOffset); + return new JSInt16Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract Int16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 2; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Int16); + } + else if (array != null) + { + this = new ArrayBufferView(0, Int16).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Int16).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Int16).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Int16).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for Int16Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):Int16Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int16Array + { + return new Int16Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getInt16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:Int) + { + ArrayBufferIO.setInt16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } + + inline function toString() + return this != null ? 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/Int32Array.hx b/src/fixes/haxe/lime/utils/Int32Array.hx new file mode 100644 index 0000000..21e417c --- /dev/null +++ b/src/fixes/haxe/lime/utils/Int32Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Int32Array as JSInt32Array; +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Int32Array as JSInt32Array; +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +abstract Int32Array(JSInt32Array) from JSInt32Array to JSInt32Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSInt32Array(elements); + } + else if (array != null) + { + this = new JSInt32Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSInt32Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSInt32Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSInt32Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSInt32Array(buffer, byteoffset); + } + else + { + this = new JSInt32Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):Int + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int32Array + { + if (byteOffset == null) return new JSInt32Array(cast bytes.getData()); + if (len == null) return new JSInt32Array(cast bytes.getData(), byteOffset); + return new JSInt32Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Int32); + } + else if (array != null) + { + this = new ArrayBufferView(0, Int32).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Int32).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Int32).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Int32).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for Int32Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):Int32Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int32Array + { + return new Int32Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getInt32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:Int) + { + ArrayBufferIO.setInt32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } + + inline function toString() + return this != null ? 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/Int8Array.hx b/src/fixes/haxe/lime/utils/Int8Array.hx new file mode 100644 index 0000000..4485788 --- /dev/null +++ b/src/fixes/haxe/lime/utils/Int8Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Int8Array as JSInt8Array; +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Int8Array as JSInt8Array; +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +abstract Int8Array(JSInt8Array) from JSInt8Array to JSInt8Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSInt8Array(elements); + } + else if (array != null) + { + this = new JSInt8Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSInt8Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSInt8Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSInt8Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSInt8Array(buffer, byteoffset); + } + else + { + this = new JSInt8Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):Int + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int8Array + { + return new JSInt8Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Int8); + } + else if (array != null) + { + this = new ArrayBufferView(0, Int8).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Int8).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Int8).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Int8).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for Int8Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):Int8Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int8Array + { + if (byteOffset == null) return new Int8Array(null, null, cast bytes.getData()); + if (len == null) return new Int8Array(null, null, cast bytes.getData(), byteOffset); + return new Int8Array(null, null, cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getInt8(this.buffer, this.byteOffset + idx); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:Int) + { + ArrayBufferIO.setInt8(this.buffer, this.byteOffset + idx, val); + return val; + } + + inline function toString() + return this != null ? 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/README.md b/src/fixes/haxe/lime/utils/README.md new file mode 100644 index 0000000..e829930 --- /dev/null +++ b/src/fixes/haxe/lime/utils/README.md @@ -0,0 +1,8 @@ +environment: +* lime 7.6.0 +* haxe 3.4.7 +* openfl build html5 + +code: ` to ArrayBufferView` + +error: You can only declare from/to with compatible types diff --git a/src/fixes/haxe/lime/utils/UInt16Array.hx b/src/fixes/haxe/lime/utils/UInt16Array.hx new file mode 100644 index 0000000..7e8ac16 --- /dev/null +++ b/src/fixes/haxe/lime/utils/UInt16Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Uint8Array as JSUInt8Array; +import js.lib.Uint16Array as JSUInt16Array; +#else +import js.html.Uint8Array as JSUInt8Array; +import js.html.Uint16Array as JSUInt16Array; +#end +@:forward +abstract UInt16Array(JSUInt16Array) from JSUInt16Array to JSUInt16Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 2; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSUInt16Array(elements); + } + else if (array != null) + { + this = new JSUInt16Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSUInt16Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSUInt16Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSUInt16Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSUInt16Array(buffer, byteoffset); + } + else + { + this = new JSUInt16Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):UInt + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt16Array + { + if (byteOffset == null) return new JSUInt16Array(cast bytes.getData()); + if (len == null) return new JSUInt16Array(cast bytes.getData(), byteOffset); + return new JSUInt16Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 2; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Uint16); + } + else if (array != null) + { + this = new ArrayBufferView(0, Uint16).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Uint16).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Uint16).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Uint16).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for UInt16Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):UInt16Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt16Array + { + return new UInt16Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getUint16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:UInt) + { + ArrayBufferIO.setUint16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } + + inline function toString() + return this != null ? 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/UInt32Array.hx b/src/fixes/haxe/lime/utils/UInt32Array.hx new file mode 100644 index 0000000..2db3844 --- /dev/null +++ b/src/fixes/haxe/lime/utils/UInt32Array.hx @@ -0,0 +1,161 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Uint8Array as JSUInt8Array; +import js.lib.Uint32Array as JSUInt32Array; +#else +import js.html.Uint8Array as JSUInt8Array; +import js.html.Uint32Array as JSUInt32Array; +#end +@:forward +abstract UInt32Array(JSUInt32Array) from JSUInt32Array to JSUInt32Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSUInt32Array(elements); + } + else if (array != null) + { + this = new JSUInt32Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSUInt32Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSUInt32Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSUInt32Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSUInt32Array(buffer, byteoffset); + } + else + { + this = new JSUInt32Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):UInt + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt32Array + { + if (byteOffset == null) return new JSUInt32Array(cast bytes.getData()); + if (len == null) return new JSUInt32Array(cast bytes.getData(), byteOffset); + return new JSUInt32Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract UInt32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 4; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Uint32); + } + else if (array != null) + { + this = new ArrayBufferView(0, Uint32).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Uint32).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Uint32).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Uint32).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for UInt32Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):UInt32Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt32Array + { + return new UInt32Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getUint32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT)); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:UInt) + { + ArrayBufferIO.setUint32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val); + return val; + } + + inline function toString() + return this != null ? 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/UInt8Array.hx b/src/fixes/haxe/lime/utils/UInt8Array.hx new file mode 100644 index 0000000..597dd96 --- /dev/null +++ b/src/fixes/haxe/lime/utils/UInt8Array.hx @@ -0,0 +1,159 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Uint8Array as JSUInt8Array; +#else +import js.html.Uint8Array as JSUInt8Array; +#end +@:forward +abstract UInt8Array(JSUInt8Array) from JSUInt8Array to JSUInt8Array/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSUInt8Array(elements); + } + else if (array != null) + { + this = new JSUInt8Array(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSUInt8Array(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSUInt8Array(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSUInt8Array(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSUInt8Array(buffer, byteoffset); + } + else + { + this = new JSUInt8Array(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt + return this[idx] = val; + + @:arrayAccess @:extern inline function __get(idx:Int):UInt + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int, ?len:Int):UInt8Array + { + if (byteOffset == null) return new JSUInt8Array(cast bytes.getData()); + if (len == null) return new JSUInt8Array(cast bytes.getData(), byteOffset); + return new JSUInt8Array(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#else +import lime.utils.ArrayBufferView; + +@:forward +abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Uint8); + } + else if (array != null) + { + this = new ArrayBufferView(0, Uint8).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Uint8).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Uint8).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Uint8).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for UInt8Array"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):UInt8Array + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8Array + { + return new UInt8Array(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function toString() + return this != null ? 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]' : null; + + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getUint8(this.buffer, this.byteOffset + idx); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:UInt) + { + ArrayBufferIO.setUint8(this.buffer, this.byteOffset + idx, val); + return val; + } +} +#end // !js diff --git a/src/fixes/haxe/lime/utils/UInt8ClampedArray.hx b/src/fixes/haxe/lime/utils/UInt8ClampedArray.hx new file mode 100644 index 0000000..f12f5ae --- /dev/null +++ b/src/fixes/haxe/lime/utils/UInt8ClampedArray.hx @@ -0,0 +1,171 @@ +package lime.utils; + +#if (js && !doc_gen) +#if haxe4 +import js.lib.Uint8Array as JSUInt8Array; +import js.lib.Uint8ClampedArray as JSUInt8ClampedArray; +#else +import js.html.Uint8Array as JSUInt8Array; +import js.html.Uint8ClampedArray as JSUInt8ClampedArray; +#end +@:forward +abstract UInt8ClampedArray(JSUInt8ClampedArray) from JSUInt8ClampedArray to JSUInt8ClampedArray/* to ArrayBufferView*/ +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + @:generic + public inline function new(?elements:Int, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new JSUInt8ClampedArray(elements); + } + else if (array != null) + { + this = new JSUInt8ClampedArray(untyped array); + #if (openfl && commonjs) + } + else if (vector != null) + { + this = new JSUInt8ClampedArray(untyped (vector)); + #elseif openfl + } + else if (vector != null) + { + this = new JSUInt8ClampedArray(untyped untyped (vector).__array); + #end + } + else if (view != null) + { + this = new JSUInt8ClampedArray(untyped view); + } + else if (buffer != null) + { + if (len == null) + { + this = new JSUInt8ClampedArray(buffer, byteoffset); + } + else + { + this = new JSUInt8ClampedArray(buffer, byteoffset, len); + } + } + else + { + this = null; + } + } + + @:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt + return this[idx] = _clamp(val); + + @:arrayAccess @:extern inline function __get(idx:Int):UInt + return this[idx]; + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8ClampedArray + { + if (byteOffset == null) return new JSUInt8ClampedArray(cast bytes.getData()); + if (len == null) return new JSUInt8ClampedArray(cast bytes.getData(), byteOffset); + return new JSUInt8ClampedArray(cast bytes.getData(), byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer)); + } + + inline function toString() + return this != null ? 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]' : null; + + // internal + // clamp a Int to a 0-255 Uint8 + static function _clamp(_in:Float):Int + { + var _out = Std.int(_in); + _out = _out > 255 ? 255 : _out; + return _out < 0 ? 0 : _out; + } // _clamp +} +#else +import lime.utils.ArrayBufferView; + +@:forward +@:arrayAccess +abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferView +{ + public inline static var BYTES_PER_ELEMENT:Int = 1; + + public var length(get, never):Int; + + @:generic + public inline function new(?elements:Int, ?buffer:ArrayBuffer, ?array:Array, #if openfl ?vector:openfl.Vector, #end ?view:ArrayBufferView, + ?byteoffset:Int = 0, ?len:Null) + { + if (elements != null) + { + this = new ArrayBufferView(elements, Uint8Clamped); + } + else if (array != null) + { + this = new ArrayBufferView(0, Uint8Clamped).initArray(array); + #if openfl + } + else if (vector != null) + { + this = new ArrayBufferView(0, Uint8Clamped).initArray(untyped (vector).__array); + #end + } + else if (view != null) + { + this = new ArrayBufferView(0, Uint8Clamped).initTypedArray(view); + } + else if (buffer != null) + { + this = new ArrayBufferView(0, Uint8Clamped).initBuffer(buffer, byteoffset, len); + } + else + { + throw "Invalid constructor arguments for UInt8ClampedArray"; + } + } + + // Public API + public inline function subarray(begin:Int, end:Null = null):UInt8ClampedArray + return this.subarray(begin, end); + + // non spec haxe conversions + inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8ClampedArray + { + return new UInt8ClampedArray(bytes, byteOffset, len); + } + + inline public function toBytes():haxe.io.Bytes + { + return this.buffer; + } + + // Internal + inline function get_length() + return this.length; + + @:noCompletion + @:arrayAccess @:extern + public inline function __get(idx:Int) + { + return ArrayBufferIO.getUint8(this.buffer, this.byteOffset + idx); + } + + @:noCompletion + @:arrayAccess @:extern + public inline function __set(idx:Int, val:UInt) + { + ArrayBufferIO.setUint8Clamped(this.buffer, this.byteOffset + idx, val); + return val; + } + + inline function toString() + return this != null ? 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]' : null; +} +#end // !js diff --git a/tasks/gulp-publish.js b/tasks/gulp-publish.js new file mode 100644 index 0000000..18f268d --- /dev/null +++ b/tasks/gulp-publish.js @@ -0,0 +1,110 @@ +const gulp = require('gulp'); +const fs = require('fs'); +const path = require('path'); +const through = require('through2'); + +class Package { + + constructor(platform, type, version) { + this.platform = platform; + this.type = type; + this.version = version; + } + + get key() { + return [this.platform, this.type].join(':'); + } + + static getPlatform(filename) { + for (const [platform, r] of [ + ['android', /^.*?\.apk$/], + ['debian', /^.*?\.deb$/], + ['linux', /^.*?linux\.tar\.gz$/], + ['windows', /^.*?windows\.zip$/], + ['windows', /^.*?\.exe$/], + ]) { + if (r.test(filename)) { + return platform; + } + } + return null; + } + + static getType(filename) { + for (const [type, r] of [ + ['apk', /^.*?\.apk$/], + ['deb', /^.*?\.deb$/], + ['archive', /^.*?\.tar\.gz$/], + ['archive', /^.*?\.zip$/], + ['installer', /^.*?\.exe$/], + ]) { + if (r.test(filename)) { + return type; + } + } + return null; + } + + static getVersion(filename) { + const m = /(\d+)\.(\d+).(\d+)/.exec(filename); + if (m) { + return parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3]); + } + return null; + } + + static parseFilename(filename) { + const platform = this.getPlatform(filename); + const type = this.getType(filename); + const version = this.getVersion(filename); + if (platform && type && version) { + return new Package(platform, type, version); + } + return null; + } +} + +module.exports = (name, version, publishDir) => function publish(cb) { + const packages = {}; + return gulp.series([ + function copy() { + return gulp.src('target/client/@(android|archive|debian|windows)/*') + .pipe(through.obj(function (file, enc, cb) { + const pack = Package.parseFilename(file.path); + if (pack) { + this.push(file); + } + cb(null); + })) + .pipe(gulp.dest(publishDir)) + }, + function generate() { + return gulp.src(`${publishDir}/*/*`) + .pipe(through.obj(function (file, enc, cb) { + const path = file.path.replace(file.base + '/', ''); + const pack = Package.parseFilename(file.path); + if (pack) { + if (!packages[pack.key] || packages[pack.key].version < pack.version) { + packages[pack.key] = { + platform: pack.platform, + type: pack.type, + version: pack.version, + path: path, + filename: path.split('/').pop(), + url: `${publishDir}/${path}`, + } + } + } + cb(null); + })).on('end', function () { + fs.writeFileSync(path.join(publishDir, 'packages.json'), JSON.stringify({ + name: name, + version: version, + packages: Object.values(packages), + }, null, 4)); + }) + } + ])(cb); +}; + +module.exports.Package = Package;