├── input
├── .keep
├── dirt16.gif
├── grid.gif
├── grass16.gif
├── tiles16.gif
└── template16.gif
├── output
└── .keep
├── usage1.gif
├── usage2.png
├── .gitignore
├── src
├── Hex.hx
├── js
│ ├── BuildPNG.hx
│ └── FileOpener.hx
├── TileSet.hx
├── Tile.hx
├── Generator.hx
└── Main.hx
├── custom_index.html
├── LICENSE
├── project.flow
├── jslibs
├── FireEvent.js
├── FileSaver.min.js
└── pako.min.js
└── README.md
/input/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/output/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/usage1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/usage1.gif
--------------------------------------------------------------------------------
/usage2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/usage2.png
--------------------------------------------------------------------------------
/input/dirt16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/input/dirt16.gif
--------------------------------------------------------------------------------
/input/grid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/input/grid.gif
--------------------------------------------------------------------------------
/input/grass16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/input/grass16.gif
--------------------------------------------------------------------------------
/input/tiles16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/input/tiles16.gif
--------------------------------------------------------------------------------
/input/template16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/AutoTerrainGen/master/input/template16.gif
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/*
2 | /devlog/*
3 | .gitattributes
4 | *.dmp
5 | *.sublime-workspace
6 | *.log
7 | desktop.ini
8 |
--------------------------------------------------------------------------------
/src/Hex.hx:
--------------------------------------------------------------------------------
1 |
2 | abstract Hex(Int) from Int to Int {
3 | public inline function toString() {
4 | var h = StringTools.hex(this);
5 | var s = "0x";
6 | for(i in 0...4-h.length){
7 | s += "0";
8 | }
9 | s += h;
10 | return s;
11 | }
12 | }
--------------------------------------------------------------------------------
/custom_index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | {{#each project.app.web.libs~}}
12 |
13 | {{/each}}
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Darek Greenly
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/project.flow:
--------------------------------------------------------------------------------
1 | {
2 |
3 | luxe:{
4 | window: {
5 | width:1000,
6 | height:640,
7 | title:'Auto Terrain Generator for Tiled',
8 | fullscreen:false,
9 | resizable:false,
10 | borderless:false
11 | }
12 | },
13 |
14 | project : {
15 | name : 'AutoTerrainGen',
16 | version : '0.1.2',
17 | author : 'Darek Greenly',
18 |
19 | app : {
20 | name : 'AutoTerrainGen',
21 | package : 'com.darekgreenly.AutoTerrainGen',
22 | web : {
23 | libs : {
24 | FileSaver: 'FileSaver.min.js',
25 | pako: 'pako.min.js',
26 | FireEvent: 'FireEvent.js'
27 | }
28 | }
29 | },
30 |
31 | build : {
32 | dependencies : {
33 | luxe : '*',
34 | mint: '*',
35 | format: '*',
36 | FileSaver: '*',
37 | pako: '*'
38 | }
39 | },
40 |
41 | files : {
42 | assets : 'input/',
43 | FileSaver : 'jslibs/FileSaver.min.js => FileSaver.min.js',
44 | pako: 'jslibs/pako.min.js => pako.min.js',
45 | FireEvent: 'jslibs/FireEvent.js => FireEvent.js',
46 | index: { path:'custom_index.html => index.html', template:'project', not_listed:true }
47 | }
48 |
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/src/js/BuildPNG.hx:
--------------------------------------------------------------------------------
1 | package js;
2 |
3 | #if web
4 |
5 | import haxe.io.Bytes;
6 | import haxe.io.BytesData;
7 | import haxe.io.BytesOutput;
8 | import js.html.Uint8Array;
9 | import js.pako.Pako;
10 |
11 | class BuildPNG {
12 | private static var o:BytesOutput;
13 |
14 | // shamelessly stolen and adapted from https://github.com/HaxeFoundation/format/tree/master/format/png
15 | public static function build(width:Int, height:Int, data:Bytes):Uint8Array {
16 | // create a stream of bytes
17 | o = new BytesOutput();
18 | o.bigEndian = true;
19 |
20 | // add the PNG front matter
21 | for(b in [137,80,78,71,13,10,26,10])
22 | o.writeByte(b);
23 |
24 | // add the header
25 | var b = new BytesOutput();
26 | b.bigEndian = true;
27 | b.writeInt32(width);
28 | b.writeInt32(height);
29 | b.writeByte(8);
30 | b.writeByte(6);
31 | b.writeByte(0);
32 | b.writeByte(0);
33 | b.writeByte(0);
34 | writeChunk("IHDR", b.getBytes());
35 |
36 | // format the data
37 | var rgba = Bytes.alloc(width * height * 4 + height);
38 | var w = 0, r = 0;
39 | for(y in 0...height) {
40 | rgba.set(w++, 0); // no filter for this scanline
41 | for(x in 0...width) {
42 | rgba.set(w++, data.get(r + 2)); // r
43 | rgba.set(w++, data.get(r + 1)); // g
44 | rgba.set(w++, data.get(r)); // b
45 | rgba.set(w++, data.get(r + 3)); // a
46 | r += 4;
47 | }
48 | }
49 | // deflate the data
50 | var bytesData:BytesData = rgba.getData();
51 | var arrForm:Uint8Array = new Uint8Array(bytesData);
52 | var deflated:Uint8Array = Pako.deflate(arrForm);
53 | var d = Bytes.alloc(deflated.length);
54 | for(i in 0...deflated.length) {
55 | d.set(i, deflated[i]);
56 | }
57 | writeChunk("IDAT", d);
58 |
59 | // write the end
60 | writeChunk("IEND", Bytes.alloc(0));
61 |
62 | // return the array of bytes!
63 | return new Uint8Array(o.getBytes().getData());
64 | }
65 |
66 | private static function writeChunk(id:String, data:Bytes) {
67 | o.writeInt32(data.length);
68 | o.writeString(id);
69 | o.write(data);
70 | var crc = new haxe.crypto.Crc32();
71 | for(i in 0...4)
72 | crc.byte(id.charCodeAt(i));
73 | crc.update(data, 0, data.length);
74 | o.writeInt32(crc.get());
75 | }
76 | }
77 |
78 | #end
--------------------------------------------------------------------------------
/jslibs/FireEvent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically
3 | * by testing for a 'synthetic=true' property on the event object
4 | * @param {HTMLNode} node The node to fire the event handler on.
5 | * @param {String} eventName The name of the event without the "on" (e.g., "focus")
6 | */
7 | function fireEvent(node, eventName) {
8 | // Make sure we use the ownerDocument from the provided node to avoid cross-window problems
9 | var doc;
10 | if (node.ownerDocument) {
11 | doc = node.ownerDocument;
12 | } else if (node.nodeType == 9){
13 | // the node may be the document itself, nodeType 9 = DOCUMENT_NODE
14 | doc = node;
15 | } else {
16 | throw new Error("Invalid node passed to fireEvent: " + node.id);
17 | }
18 |
19 | if (node.dispatchEvent) {
20 | // Gecko-style approach (now the standard) takes more work
21 | var eventClass = "";
22 |
23 | // Different events have different event classes.
24 | // If this switch statement can't map an eventName to an eventClass,
25 | // the event firing is going to fail.
26 | switch (eventName) {
27 | case "click": // Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
28 | case "mousedown":
29 | case "mouseup":
30 | eventClass = "MouseEvents";
31 | break;
32 |
33 | case "focus":
34 | case "change":
35 | case "blur":
36 | case "select":
37 | eventClass = "HTMLEvents";
38 | break;
39 |
40 | default:
41 | throw "fireEvent: Couldn't find an event class for event '" + eventName + "'.";
42 | break;
43 | }
44 | var event = doc.createEvent(eventClass);
45 |
46 | var bubbles = eventName == "change" ? false : true;
47 | event.initEvent(eventName, bubbles, true); // All events created as bubbling and cancelable.
48 |
49 | event.synthetic = true; // allow detection of synthetic events
50 | node.dispatchEvent(event, true);
51 | } else if (node.fireEvent) {
52 | // IE-old school style
53 | var event = doc.createEventObject();
54 | event.synthetic = true; // allow detection of synthetic events
55 | node.fireEvent("on" + eventName, event);
56 | }
57 | };
--------------------------------------------------------------------------------
/src/TileSet.hx:
--------------------------------------------------------------------------------
1 | import luxe.Sprite;
2 | import phoenix.Texture;
3 |
4 | import snow.api.buffers.Uint8Array;
5 |
6 |
7 | class TileSet {
8 |
9 | public var texture:Texture;
10 |
11 | public var id:String;
12 |
13 | public var name:String;
14 |
15 | public var preview:Sprite;
16 |
17 | public var tiles:Array;
18 |
19 | public function new( t:Texture )
20 | {
21 | id = t.id;
22 |
23 | #if windows
24 | name = id.substring( id.lastIndexOf('\\')+1, id.lastIndexOf('.') );
25 | #else
26 | name = id.substring( id.lastIndexOf('/')+1, id.lastIndexOf('.') );
27 | #end
28 |
29 | texture = t;
30 |
31 | tiles = new Array();
32 |
33 | prepare_tiles();
34 | }
35 |
36 | function prepare_tiles() {
37 |
38 | var x = Main.tile_size;
39 |
40 | // o
41 | add_tile(x,x, Tile.T1);
42 | add_tile(0,x, Tile.T2);
43 | add_tile(0,0, Tile.T3);
44 | add_tile(x,0, Tile.T4);
45 | // \ /
46 | add_tile(2*x,0, Tile.T1 | Tile.T3);
47 | add_tile(3*x,0, Tile.T2 | Tile.T4);
48 |
49 | // <| |>
50 | add_tile(3*x,x, Tile.T1 | Tile.T4);
51 | add_tile(2*x,x, Tile.T2 | Tile.T3);
52 |
53 | // *** ___
54 | add_tile(2*x,2*x, Tile.T1 | Tile.T2);
55 | add_tile(3*x,2*x, Tile.T3 | Tile.T4);
56 |
57 | //
58 | add_tile(x,3*x, Tile.T2 | Tile.T3 | Tile.T4);
59 | add_tile(0,3*x, Tile.T1 | Tile.T3 | Tile.T4);
60 | add_tile(0,2*x, Tile.T1 | Tile.T2 | Tile.T4);
61 | add_tile(x,2*x, Tile.T1 | Tile.T2 | Tile.T3);
62 |
63 |
64 | // [] full
65 | add_tile(2*x,3*x, Tile.T1 | Tile.T2 | Tile.T3 | Tile.T4);
66 |
67 | }
68 |
69 | function add_tile(x:Int, y:Int, flag:Int) {
70 |
71 | var pixels:Uint8Array = new Uint8Array(Main.tile_size*Main.tile_size*4);
72 |
73 | texture.fetch( pixels, x, y, Main.tile_size, Main.tile_size);
74 |
75 | tiles.push( new Tile(pixels, flag, id) );
76 | }
77 |
78 |
79 | /**
80 | * Get pixels from the tile that has given pieces (flag)
81 | * @param flag Which pieces do I need? Tile.T1|Tile.T2 etc
82 | * @return Uint8Array with pixels of the tile
83 | */
84 | public function get(flag:Int):Uint8Array {
85 |
86 | var p:Uint8Array = new Uint8Array(Main.tile_size*Main.tile_size*4);
87 |
88 | for( t in tiles ){
89 | if(t.flag == flag){
90 | p = t.texture.fetch(p);
91 | break;
92 | }
93 | }
94 |
95 | return p;
96 |
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/src/js/FileOpener.hx:
--------------------------------------------------------------------------------
1 | package js;
2 |
3 | #if web
4 |
5 | import phoenix.Texture;
6 |
7 | import snow.api.buffers.Uint8Array;
8 | import snow.system.assets.Asset.AssetImage;
9 |
10 | import js.html.InputElement;
11 | import js.html.File;
12 | import js.html.FileReader;
13 | import js.html.ProgressEvent;
14 |
15 | import haxe.io.Bytes;
16 | import haxe.io.BytesData;
17 |
18 | class FileOpener {
19 | var filePicker:InputElement;
20 | var fileReader:FileReader;
21 | var dataCallback:Texture->Void;
22 |
23 | public function new() {
24 | // find the hidden filePicker input element
25 | // (it was placed there using the custom_index.html file)
26 | filePicker = cast js.Browser.document.getElementById("filePicker");
27 |
28 | // add a listener for when a user changes its value
29 | filePicker.addEventListener('change', handleFileSelect, false);
30 | }
31 |
32 | public function open(dataCallback:Texture->Void) {
33 | // simulate the user clicking on the hidden file picker
34 | this.dataCallback = dataCallback;
35 | untyped fireEvent(filePicker, "click");
36 | }
37 |
38 | private function handleFileSelect(evt) {
39 | // make sure they actually clicked something
40 | if(filePicker.files.length != 1) {
41 | return;
42 | }
43 |
44 | var file:File = filePicker.files.item(0);
45 | if(Luxe.resources.texture(file.name) != null) {
46 | dataCallback(Luxe.resources.texture(file.name));
47 | return;
48 | }
49 |
50 | // cancel any in-progress reads
51 | if(fileReader != null) {
52 | fileReader.abort();
53 | fileReader = null;
54 | }
55 |
56 | // create a new file reader
57 | fileReader = new FileReader();
58 |
59 | // fileReader is async, so define a callback for when it's done
60 | fileReader.onload = function(progress:ProgressEvent) {
61 | // get the file data as bytes
62 | var data:BytesData = cast fileReader.result;
63 | var bytes:Bytes = Bytes.ofData(data);
64 |
65 | // load the image using snow
66 | Luxe.core.app.assets.image_from_bytes(file.name, Uint8Array.fromBytes(bytes))
67 | .then(function(asset:AssetImage) {
68 | // add the image to luxe's resources
69 | Luxe.resources.add(new Texture({
70 | id: file.name,
71 | system: Luxe.resources,
72 | width: asset.image.width,
73 | height: asset.image.height,
74 | pixels: asset.image.pixels
75 | }));
76 |
77 | // inform the caller that the image was loaded
78 | dataCallback(Luxe.resources.texture(file.name));
79 | });
80 | }
81 |
82 | // read the file data as an array buffer (which can be translated into bytes)
83 | fileReader.readAsArrayBuffer(file);
84 | }
85 | }
86 |
87 | #end
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://waffle.io/Zielak/AutoTerrainGen)
2 | # Auto Terrain Generator
3 |
4 | > Create terrains for Tiled editor quicker
5 |
6 | ## Usage
7 |
8 | Use this tool to combine your tilesets into one terrain and paint quicker "landscape" in Tiled editor.
9 |
10 | ### 1. Prepare your tilesets
11 |
12 | Each tileset should containt every possible tile combination. Use below template to create your own. Only 15 tiles are used, the last one is ignored.
13 |
14 | I've tested this tool for generating terrain of 2, 3 and 4 tilesets. Adding more would probably cause longer generation time, and also I'm not sure how would Tiled react to that.
15 |
16 | 
17 |
18 | ### 2. Set correct tile size
19 |
20 | Default is 16px x 16px. Change it in "Configurate" window if you're using different tile size. Width and height must be equal, eg. 32px x 32px.
21 |
22 | ### 3. Load up all your tilesets
23 |
24 | Put all your tilesets into `input` folder, type your filename (with an extension!) and hit `LOAD`. Your tileset should appear in the list below.
25 |
26 | Here you can:
27 |
28 | - change name of the layer - this will appear in Tiled Terrains window
29 | - change order - bottom layers will be rendered on top of all the other tilesets. Reverse-photoshop style :)
30 | - remove tileset
31 | - click tileset preview to see how the generator split each tile in "Tileset Preview" window
32 |
33 | 
34 |
35 | ### 4. Hit GENERATE!
36 |
37 | The terrain will be available to preview in the bottom part of window.
38 |
39 | ### 5. Export bitmap and TSX file
40 |
41 | At the bottom you'll find:
42 |
43 | - "Export Bitmap" - save terrain PNG file in `output/` folder
44 | - "Export TSX" - save .tsx file for Tiled in the same folder
45 |
46 | ## Work in Tiled
47 |
48 | To use your new terrain you have to open new map, go to menu and hit "Map" -> "Add external tileset". Navigate to generator's `output/` folder and choose `output.tsx` file.
49 |
50 | # Happy designing!
51 |
52 | ----
53 |
54 | This tool was created using:
55 |
56 | - [luxe engine](http://luxeengine.com/docs/) - *luxe is a free, open source cross platform rapid development haxe based game engine for deploying games on Mac, Windows, Linux, Android, iOS and WebGL.*
57 | - [mint](http://snowkit.github.io/mint/) - *mint is minimal, renderer agnostic ui library for Haxe.*
58 | - [format](https://github.com/HaxeFoundation/format) - *The format library contains support for different file-formats for the Haxe programming language.*
59 |
60 | ----
61 |
--------------------------------------------------------------------------------
/jslibs/FileSaver.min.js:
--------------------------------------------------------------------------------
1 | /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
2 | var saveAs=saveAs||function(e){"use strict";if(typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),i="download"in r,o=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),f=e.webkitRequestFileSystem,u=e.requestFileSystem||f||e.mozRequestFileSystem,s=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},c="application/octet-stream",d=0,l=500,w=function(t){var r=function(){if(typeof t==="string"){n().revokeObjectURL(t)}else{t.remove()}};if(e.chrome){r()}else{setTimeout(r,l)}},p=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var i=e["on"+t[r]];if(typeof i==="function"){try{i.call(e,n||e)}catch(o){s(o)}}}},v=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob(["\ufeff",e],{type:e.type})}return e},y=function(t,s,l){if(!l){t=v(t)}var y=this,m=t.type,S=false,h,R,O=function(){p(y,"writestart progress write writeend".split(" "))},g=function(){if(R&&a&&typeof FileReader!=="undefined"){var r=new FileReader;r.onloadend=function(){var e=r.result;R.location.href="data:attachment/file"+e.slice(e.search(/[,;]/));y.readyState=y.DONE;O()};r.readAsDataURL(t);y.readyState=y.INIT;return}if(S||!h){h=n().createObjectURL(t)}if(R){R.location.href=h}else{var i=e.open(h,"_blank");if(i==undefined&&a){e.location.href=h}}y.readyState=y.DONE;O();w(h)},b=function(e){return function(){if(y.readyState!==y.DONE){return e.apply(this,arguments)}}},E={create:true,exclusive:false},N;y.readyState=y.INIT;if(!s){s="download"}if(i){h=n().createObjectURL(t);r.href=h;r.download=s;setTimeout(function(){o(r);O();w(h);y.readyState=y.DONE});return}if(e.chrome&&m&&m!==c){N=t.slice||t.webkitSlice;t=N.call(t,0,t.size,c);S=true}if(f&&s!=="download"){s+=".download"}if(m===c||f){R=e}if(!u){g();return}d+=t.size;u(e.TEMPORARY,d,b(function(e){e.root.getDirectory("saved",E,b(function(e){var n=function(){e.getFile(s,E,b(function(e){e.createWriter(b(function(n){n.onwriteend=function(t){R.location.href=e.toURL();y.readyState=y.DONE;p(y,"writeend",t);w(e)};n.onerror=function(){var e=n.error;if(e.code!==e.ABORT_ERR){g()}};"writestart progress write abort".split(" ").forEach(function(e){n["on"+e]=y["on"+e]});n.write(t);y.abort=function(){n.abort();y.readyState=y.DONE};y.readyState=y.WRITING}),g)}),g)};e.getFile(s,{create:false},b(function(e){e.remove();n()}),b(function(e){if(e.code===e.NOT_FOUND_ERR){n()}else{g()}}))}),g)}),g)},m=y.prototype,S=function(e,t,n){return new y(e,t,n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){if(!n){e=v(e)}return navigator.msSaveOrOpenBlob(e,t||"download")}}m.abort=function(){var e=this;e.readyState=e.DONE;p(e,"abort")};m.readyState=m.INIT=0;m.WRITING=1;m.DONE=2;m.error=m.onwritestart=m.onprogress=m.onwrite=m.onabort=m.onerror=m.onwriteend=null;return S}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!=null){define([],function(){return saveAs})}
--------------------------------------------------------------------------------
/src/Tile.hx:
--------------------------------------------------------------------------------
1 | import luxe.Resources;
2 | import phoenix.Texture;
3 |
4 | import snow.api.buffers.Uint8Array;
5 |
6 |
7 | class Tile {
8 |
9 | /**
10 | * |---+---|
11 | * | 1 | 2 |
12 | * |---+---|
13 | * | 4 | 3 |
14 | * |---+---|
15 | */
16 |
17 | public static inline var T1:Hex = 0x0001;
18 | public static inline var T2:Hex = 0x0010;
19 | public static inline var T3:Hex = 0x0100;
20 | public static inline var T4:Hex = 0x1000;
21 | public static inline var WHOLE:Hex = 0x1111;
22 |
23 | public var texture:Texture;
24 |
25 | public var pixels:Uint8Array;
26 | public var flag:Hex;
27 |
28 | // What tileset is placed in which piece?
29 | public var pieces:Array;
30 |
31 | var foreign_id:String;
32 | public var id:String = '';
33 |
34 | public function new(?p:Uint8Array, ?f:Hex = 0x1111, ?_id:String){
35 |
36 |
37 | if(_id != null) foreign_id = _id;
38 |
39 | // Is it part of tileset or tile ready for the output?
40 | flag = f;
41 |
42 | // Get pixels straight from above or prepare empty place
43 | if(p != null){
44 | pixels = p;
45 | prepare_texture();
46 | }else{
47 | pixels = new Uint8Array(Main.tile_size*Main.tile_size*4);
48 | }
49 |
50 | pieces = new Array();
51 | pieces[0] = -1;
52 | pieces[1] = -1;
53 | pieces[2] = -1;
54 | pieces[3] = -1;
55 |
56 | }
57 |
58 | /**
59 | * Not all tiles are used to be visible in UI.
60 | * Use this to change this one in usable Texture
61 | * @return ID of texture to get
62 | */
63 | function prepare_texture(){
64 |
65 | if(texture != null){
66 | return;
67 | }
68 |
69 | id = '${foreign_id}_${flag}';
70 |
71 | texture = new Texture({
72 | pixels: pixels,
73 | id: id,
74 | width: Main.tile_size,
75 | height: Main.tile_size,
76 | filter_mag: phoenix.FilterType.nearest,
77 | filter_min: phoenix.FilterType.nearest,
78 | });
79 |
80 | Luxe.resources.add(texture);
81 |
82 | }
83 |
84 |
85 | public function add_ontop( _pixels:Uint8Array, _layer:Int, _flag:Int ){
86 |
87 | if(texture != null) return;
88 |
89 | var color:C = {r:0, g:0, b:0, a:0};
90 | var n = 0;
91 |
92 | while( n < _pixels.length ){
93 |
94 | // get pixel
95 | color.r = _pixels[n];
96 | color.g = _pixels[n+1];
97 | color.b = _pixels[n+2];
98 | color.a = _pixels[n+3];
99 |
100 | // do nothing if transparent
101 | if(color.a > 0){
102 | // trace('gonna draw: ${color}');
103 | pixels[n] = color.r;
104 | pixels[n+1] = color.g;
105 | pixels[n+2] = color.b;
106 | pixels[n+3] = color.a;
107 | }
108 |
109 | n += 4;
110 |
111 | }
112 |
113 | // Now keep info about this action
114 | var _flags = [0x0001,0x0010,0x0100,0x1000];
115 | for(i in 0..._flags.length){
116 | if(_flags[i] & _flag > 0) pieces[i] = _layer;
117 | }
118 | }
119 |
120 | /**
121 | * Gives string for comparison of the same tiles
122 | * @return
123 | */
124 | public function toString():String{
125 | var s:String = '';
126 | for(i in pieces){
127 | if(i == -1) s += 'V';
128 | else s += i;
129 | }
130 | return s;
131 | }
132 |
133 | }
134 |
135 | typedef C = {
136 | var a:Int;
137 | var r:Int;
138 | var g:Int;
139 | var b:Int;
140 | }
141 |
--------------------------------------------------------------------------------
/src/Generator.hx:
--------------------------------------------------------------------------------
1 | import luxe.Sprite;
2 | import phoenix.Texture;
3 | import luxe.Color;
4 | import snow.api.buffers.Uint8Array;
5 | import Xml;
6 |
7 | class Generator {
8 |
9 | public static inline var T1:Hex = 0x0001;
10 | public static inline var T2:Hex = 0x0010;
11 | public static inline var T3:Hex = 0x0100;
12 | public static inline var T4:Hex = 0x1000;
13 | public static inline var WHOLE:Hex = 0x1111;
14 |
15 | // How much tiles have we generated?
16 | // Could use output_tiles.length...
17 | var tile_count:Int;
18 |
19 | //
20 | var tilesets:Array;
21 |
22 | // Each tile is stored here after generating. Use as source.
23 | var output_tiles:Array;
24 |
25 | //
26 | public var output:Texture;
27 |
28 | // TSX for the Tiled. Rebuilt after each output generation
29 | public var tsx:Xml;
30 |
31 | //
32 | public var output_pixels:Uint8Array;
33 |
34 | public var w:Int = 0;
35 | public var h:Int = 0;
36 |
37 |
38 | // Which pieces to generate right now?
39 | var piece_gen:Int;
40 |
41 | // Which pieces are from main tileset right now?
42 | var piece_main:Int;
43 |
44 | // Temp tile
45 | var tile:Tile;
46 |
47 | // Temp pixels array to store pixels of tiles
48 | var _pixels:Uint8Array;
49 |
50 | // Current MAIN tileset
51 | var _main:Int;
52 |
53 |
54 |
55 | public function new() {
56 |
57 | }
58 |
59 | public function update_tilesets( _ts:Array ) {
60 |
61 | tilesets = _ts;
62 | calculate_tiles();
63 |
64 | }
65 |
66 | public function generate() {
67 |
68 | prepare_output();
69 |
70 | // Has only combination of tileset with void
71 | // Thats actually the same as input...
72 | if(tilesets.length == 1){
73 | // stage_1();
74 | Luxe.events.fire('log.add', 'No work needed to do. Add at least one more tileset.');
75 | }
76 | // Max 2 types +void on one tile (T+2)
77 | if(tilesets.length >= 2){
78 |
79 | for(i in 0...tilesets.length){
80 | main(i);
81 | }
82 |
83 | }
84 |
85 |
86 | apply_output();
87 |
88 | rebuild_tsx();
89 |
90 | Luxe.events.fire('generator.done');
91 |
92 | }
93 |
94 | // Returns nth empty piece (0) in piece_gen and returns its flag (one piece only).
95 | function get_nth_piece_flag(flag:Int, i:Int):Int{
96 |
97 | var _pieces:Array = new Array();
98 |
99 | var _count:Int = i;
100 |
101 | _pieces[0] = (flag & 0x0001 > 0);
102 | _pieces[1] = (flag & 0x0010 > 0);
103 | _pieces[2] = (flag & 0x0100 > 0);
104 | _pieces[3] = (flag & 0x1000 > 0);
105 |
106 | for(j in 0..._pieces.length){
107 |
108 | if(_pieces[j]){
109 | _count--;
110 | if(_count >= 0) continue;
111 |
112 | return [0x0001, 0x0010, 0x0100, 0x1000][j];
113 | }
114 |
115 | }
116 | return 0x0000;
117 | }
118 |
119 | // Adds pieces of given layer on tile
120 | // if flag is not set, then it's current piece_gen
121 | function get_pieces(layer:Int, ?_flag:Int = 0){
122 |
123 | // Set default flag
124 | if(_flag == 0) _flag = piece_gen;
125 |
126 | // Void? nothing to do
127 | if(layer < 0) return;
128 |
129 | _pixels = tilesets[layer].get(_flag);
130 | tile.add_ontop(_pixels, layer, _flag);
131 | }
132 |
133 | function main_pieces(_flag:Int = 0){
134 | if(_flag == 0) _flag = piece_main;
135 | _pixels = tilesets[_main].get(_flag);
136 | tile.add_ontop(_pixels, _main, _flag);
137 | }
138 |
139 | // Puts all the pieces together in one tile
140 | // used in "max 2 different tiles"
141 | function add_pieces_2(i:Int){
142 |
143 | tile = new Tile();
144 |
145 | if(i > _main){
146 | main_pieces(Tile.WHOLE);
147 | get_pieces(i);
148 | }else if(i < _main){
149 | get_pieces(i, Tile.WHOLE);
150 | main_pieces();
151 | }else{
152 | // Adds Void when other == _main
153 | main_pieces();
154 | }
155 |
156 | try_to_add( tile );
157 |
158 | }
159 |
160 |
161 | // Puts all the pieces together in one tile
162 | // used in "max 3 different tiles"
163 | function add_pieces_3(i:Int, j:Int, ?k:Int){
164 |
165 | // trace('add_pieces_3( ${i}, ${j}, ${k} ) | _main = ${_main}');
166 |
167 | var _ordered:Array = new Array();
168 |
169 | _ordered[0] = {layer: _main, flag: piece_main};
170 | _ordered[1] = {layer: i, flag: get_nth_piece_flag(piece_gen, 0)};
171 | _ordered[2] = {layer: j, flag: get_nth_piece_flag(piece_gen, 1)};
172 | if( k != null ) _ordered[3] = {layer: k, flag: get_nth_piece_flag(piece_gen, 2)};
173 |
174 | _ordered.sort(function(a:LayerFlag,b:LayerFlag):Int {
175 | if (a.layer == b.layer) return 0;
176 | if (a.layer > b.layer) return 1;
177 | else return -1;
178 | });
179 |
180 | // Lower layers should also have pieces
181 | // of the higher layers
182 | if( k == null ){
183 | _ordered[0].flag = _ordered[0].flag | _ordered[1].flag | _ordered[2].flag;
184 | _ordered[1].flag = _ordered[1].flag | _ordered[2].flag;
185 | }else{
186 | _ordered[0].flag = _ordered[0].flag | _ordered[1].flag | _ordered[2].flag | _ordered[3].flag;
187 | _ordered[1].flag = _ordered[1].flag | _ordered[2].flag | _ordered[3].flag;
188 | _ordered[2].flag = _ordered[2].flag | _ordered[3].flag;
189 | }
190 |
191 |
192 |
193 | // Add combinations
194 | tile = new Tile();
195 |
196 | for(n in 0..._ordered.length){
197 |
198 | get_pieces(_ordered[n].layer, _ordered[n].flag);
199 |
200 | }
201 |
202 | try_to_add( tile );
203 |
204 | // trace('DONE');
205 |
206 | }
207 |
208 | // 3 different tiles in one (main and 2 other)
209 | // Ones and Twos. Threes won't fit 4th different tile.
210 | // three_others? is ther only one main piece here?
211 | function walk_tilesets_3(?three_others:Bool = false){
212 |
213 | var go_i:Int;
214 | var go_j:Int;
215 | var go_k:Int;
216 |
217 | for(i in 0...tilesets.length) {
218 |
219 | for(j in 0...tilesets.length) {
220 |
221 | if(!three_others){
222 | // There are only 2 other pieces
223 | go_j = j;
224 | go_i = i;
225 |
226 | // If one of those is same as MAIN,
227 | // then make it draw Void
228 | if(_main == i) go_i = -1;
229 | if(_main == j) go_j = -1;
230 |
231 | // Can't be the same, we're drawing
232 | // only different pieces here
233 | if(go_i == go_j) continue;
234 |
235 | add_pieces_3(go_i, go_j);
236 |
237 | }else{
238 | // There are 3 other pieces!
239 | for(k in 0...tilesets.length) {
240 | go_j = j;
241 | go_i = i;
242 | go_k = k;
243 |
244 | // If one of those is same as MAIN,
245 | // then make it draw Void
246 | if(_main == i) go_i = -1;
247 | if(_main == j) go_j = -1;
248 | if(_main == k) go_k = -1;
249 |
250 | // Can't be the same, we're drawing
251 | // only different pieces here
252 | if(go_i == go_j || go_i == go_k || go_j == go_k) continue;
253 |
254 | add_pieces_3(go_i, go_j, go_k);
255 |
256 | }
257 | }
258 |
259 | }
260 | }
261 |
262 | }
263 |
264 | function main( main:Int ) {
265 |
266 | _main = main;
267 |
268 | _pixels = new Uint8Array(Main.tile_size*Main.tile_size*4);
269 |
270 |
271 | // 2 different tiles (main and other)
272 | inline function walk_tilesets_2(){
273 |
274 | for(i in 0...tilesets.length) {
275 |
276 | add_pieces_2(i);
277 | }
278 |
279 | }
280 |
281 | /**
282 | * ==========================================================
283 | * ORIGINAL #################### M + 0 ###
284 | * ==========================================================
285 | */
286 |
287 | for(i in 0...tilesets.length) {
288 |
289 | var _ts = tilesets[i];
290 |
291 | for(_t in _ts.tiles) {
292 |
293 | // set pieces
294 | _t.pieces[0] = (0x0001 & _t.flag > 0) ? i : -1;
295 | _t.pieces[1] = (0x0010 & _t.flag > 0) ? i : -1;
296 | _t.pieces[2] = (0x0100 & _t.flag > 0) ? i : -1;
297 | _t.pieces[3] = (0x1000 & _t.flag > 0) ? i : -1;
298 |
299 | tile = new Tile();
300 |
301 | main_pieces(_t.flag);
302 |
303 | try_to_add( tile );
304 |
305 | }
306 |
307 | }
308 |
309 |
310 | /**
311 | * ==========================================================
312 | * 2 different pieces #################### M + 1 ###
313 | * ==========================================================
314 | */
315 |
316 |
317 | // Threes (3 pieces of the main tile)
318 |
319 |
320 | // |---+---|
321 | // | | X |
322 | // |---+---|
323 | // | X | X |
324 | // |---+---|
325 | piece_gen = T1;
326 | piece_main = T2 | T3 | T4;
327 | walk_tilesets_2();
328 |
329 |
330 | // |---+---|
331 | // | X | |
332 | // |---+---|
333 | // | X | X |
334 | // |---+---|
335 | piece_gen = T2;
336 | piece_main = T1 | T3 | T4;
337 | walk_tilesets_2();
338 |
339 |
340 | // |---+---|
341 | // | X | X |
342 | // |---+---|
343 | // | X | |
344 | // |---+---|
345 | piece_gen = T3;
346 | piece_main = T1 | T2 | T4;
347 | walk_tilesets_2();
348 |
349 |
350 | // |---+---|
351 | // | X | X |
352 | // |---+---|
353 | // | | X |
354 | // |---+---|
355 | piece_gen = T4;
356 | piece_main = T1 | T2 | T3;
357 | walk_tilesets_2();
358 |
359 |
360 |
361 |
362 | // Twos (2 pieces of the main tile)
363 |
364 |
365 | // |---+---|
366 | // | X | |
367 | // |---+---|
368 | // | | X |
369 | // |---+---|
370 | piece_gen = T2 | T4;
371 | piece_main = T1 | T3;
372 | walk_tilesets_2();
373 |
374 |
375 | // |---+---|
376 | // | | X |
377 | // |---+---|
378 | // | X | |
379 | // |---+---|
380 | piece_gen = T1 | T3;
381 | piece_main = T2 | T4;
382 | walk_tilesets_2();
383 |
384 |
385 | // |---+---|
386 | // | X | |
387 | // |---+---|
388 | // | X | |
389 | // |---+---|
390 | piece_gen = T2 | T3;
391 | piece_main = T1 | T4;
392 | walk_tilesets_2();
393 |
394 |
395 | // |---+---|
396 | // | | X |
397 | // |---+---|
398 | // | | X |
399 | // |---+---|
400 | piece_gen = T1 | T4;
401 | piece_main = T2 | T3;
402 | walk_tilesets_2();
403 |
404 |
405 | // |---+---|
406 | // | X | X |
407 | // |---+---|
408 | // | | |
409 | // |---+---|
410 | piece_gen = T3 | T4;
411 | piece_main = T1 | T2;
412 | walk_tilesets_2();
413 |
414 |
415 | // |---+---|
416 | // | | |
417 | // |---+---|
418 | // | X | X |
419 | // |---+---|
420 | piece_gen = T1 | T2;
421 | piece_main = T3 | T4;
422 | walk_tilesets_2();
423 |
424 |
425 | // Ones (one piece of the main tile)
426 |
427 |
428 | // |---+---|
429 | // | X | |
430 | // |---+---|
431 | // | | |
432 | // |---+---|
433 | piece_gen = T2 | T3 | T4;
434 | piece_main = T1;
435 | walk_tilesets_2();
436 |
437 |
438 | // |---+---|
439 | // | | X |
440 | // |---+---|
441 | // | | |
442 | // |---+---|
443 | piece_gen = T1 | T3 | T4;
444 | piece_main = T2;
445 | walk_tilesets_2();
446 |
447 |
448 | // |---+---|
449 | // | | |
450 | // |---+---|
451 | // | | X |
452 | // |---+---|
453 | piece_gen = T1 | T2 | T4;
454 | piece_main = T3;
455 | walk_tilesets_2();
456 |
457 |
458 | // |---+---|
459 | // | | |
460 | // |---+---|
461 | // | X | |
462 | // |---+---|
463 | piece_gen = T1 | T2 | T3;
464 | piece_main = T4;
465 | walk_tilesets_2();
466 |
467 |
468 |
469 |
470 | /**
471 | * ==========================================================
472 | * 3 different pieces ################## M + 2 #####
473 | * ==========================================================
474 | */
475 |
476 |
477 |
478 | // Ones (one piece of the main tile)
479 |
480 |
481 | // |---+---|
482 | // | X | |
483 | // |---+---|
484 | // | | |
485 | // |---+---|
486 | piece_gen = T2 | T3 | T4;
487 | piece_main = T1;
488 | walk_tilesets_3(true);
489 |
490 |
491 | // |---+---|
492 | // | | X |
493 | // |---+---|
494 | // | | |
495 | // |---+---|
496 | piece_gen = T1 | T3 | T4;
497 | piece_main = T2;
498 | walk_tilesets_3(true);
499 |
500 |
501 | // |---+---|
502 | // | | |
503 | // |---+---|
504 | // | | X |
505 | // |---+---|
506 | piece_gen = T1 | T2 | T4;
507 | piece_main = T3;
508 | walk_tilesets_3(true);
509 |
510 |
511 | // |---+---|
512 | // | | |
513 | // |---+---|
514 | // | X | |
515 | // |---+---|
516 | piece_gen = T1 | T2 | T3;
517 | piece_main = T4;
518 | walk_tilesets_3(true);
519 |
520 |
521 | // Twos (2 pieces of the main tile)
522 |
523 | //
524 | // |---+---|
525 | // | X | |
526 | // |---+---|
527 | // | | X |
528 | // |---+---|
529 | piece_gen = T2 | T4;
530 | piece_main = T1 | T3;
531 | walk_tilesets_3();
532 |
533 |
534 | // |---+---|
535 | // | | X |
536 | // |---+---|
537 | // | X | |
538 | // |---+---|
539 | piece_gen = T1 | T3;
540 | piece_main = T2 | T4;
541 | walk_tilesets_3();
542 |
543 |
544 | // |---+---|
545 | // | X | |
546 | // |---+---|
547 | // | X | |
548 | // |---+---|
549 | piece_gen = T2 | T3;
550 | piece_main = T1 | T4;
551 | walk_tilesets_3();
552 |
553 |
554 | // |---+---|
555 | // | | X |
556 | // |---+---|
557 | // | | X |
558 | // |---+---|
559 | piece_gen = T1 | T4;
560 | piece_main = T2 | T3;
561 | walk_tilesets_3();
562 |
563 |
564 | // |---+---|
565 | // | X | X |
566 | // |---+---|
567 | // | | |
568 | // |---+---|
569 | piece_gen = T3 | T4;
570 | piece_main = T1 | T2;
571 | walk_tilesets_3();
572 |
573 |
574 | // |---+---|
575 | // | | |
576 | // |---+---|
577 | // | X | X |
578 | // |---+---|
579 | piece_gen = T1 | T2;
580 | piece_main = T3 | T4;
581 | walk_tilesets_3();
582 |
583 | /**/
584 | }
585 |
586 |
587 | public function calculate_tiles() {
588 |
589 | var l:Int = tilesets.length;
590 |
591 | if(l == 1){
592 |
593 | tile_count = tilesets[0].tiles.length;
594 | }
595 |
596 | if(l >= 2){
597 |
598 | tile_count = 0;
599 |
600 | // Original
601 |
602 | tile_count = (tilesets.length+1) * 15;
603 |
604 | // M + 1
605 |
606 | // 4 ones (has 3 other pieces)
607 | tile_count += 4*(l*l*l);
608 |
609 | // 6 twos (has 2 other pieces)
610 | tile_count += 6*(l*l);
611 |
612 | // 4 threes (has 1 other piece)
613 | tile_count += 4*(l);
614 |
615 | // M + 2
616 |
617 | // 6 twos (has 2 main pieces)
618 | tile_count += 6*(l*l*l);
619 |
620 | // I don't even know
621 | tile_count += 4*( l );
622 |
623 | }
624 |
625 | Luxe.events.fire('config_text.update', '(Wrongly) predicting ${tile_count} tiles...');
626 |
627 | }
628 |
629 | function prepare_output() {
630 |
631 | output_tiles = new Array();
632 |
633 | }
634 |
635 | function apply_output() {
636 |
637 | w = Math.ceil( Math.sqrt(output_tiles.length) ) * Main.tile_size;
638 | h = w;
639 |
640 | var x:Int = 0;
641 | var y:Int = 0;
642 | var x2:Int = 0;
643 | var y2:Int = 0;
644 |
645 | Luxe.events.fire('log.add', 'Output dimensions: ${w}px x ${h}px');
646 | Luxe.events.fire('log.add', 'Got ${output_tiles.length} tiles in output.');
647 |
648 | var _pixels:Uint8Array = new Uint8Array( w*h*4 );
649 |
650 | // Get each tile
651 | for(_t in output_tiles){
652 |
653 | x2 = 0;
654 | y2 = 0;
655 |
656 | if(_t == null) continue;
657 |
658 | // trace('_t: ${_t}');
659 | // trace('_t.pixels: ${_t.pixels}');
660 | // trace('_t.pixels.length: ${_t.pixels.length}');
661 |
662 | // Draw each pixel
663 | for(i in 0..._t.pixels.length){
664 |
665 | _pixels[ ( (y+y2)*w*4 ) + x*4 + x2 ] = _t.pixels[i];
666 |
667 | if(x > 2){
668 | // trace('x2 = ${x2}');
669 | // trace('pixel: ${ ((y+y2)*w*4) + x*4 + x2}');
670 | }
671 |
672 | x2 ++;
673 |
674 | if(x2 >= Main.tile_size*4){
675 | y2 ++;
676 | x2 = 0;
677 | }
678 |
679 |
680 | }
681 |
682 | x += Main.tile_size;
683 |
684 | if(x >= w){
685 | x = 0;
686 | y += Main.tile_size;
687 | }
688 |
689 | }
690 |
691 | // Create new 'output' texture if it's not in resources yet
692 | if(Luxe.resources.texture('output') == null){
693 |
694 | output = new Texture({
695 | pixels: _pixels,
696 | id: 'output',
697 | width: w,
698 | height: h,
699 | filter_mag: phoenix.FilterType.nearest,
700 | filter_min: phoenix.FilterType.nearest,
701 | });
702 |
703 | Luxe.resources.add(output);
704 |
705 | }else{
706 |
707 | // Already have 'output' texture in resources, go on.
708 |
709 | output.width = output.width_actual = w;
710 | output.height = output.height_actual = h;
711 | output.submit(_pixels);
712 | }
713 |
714 | // place the pixels into output_pixels
715 | // Gotta swap reds with blues first
716 |
717 | inline function bset(p,v) {
718 | return _pixels[p] = v;
719 | }
720 |
721 | var p:Int = 0;
722 | for( i in 0..._pixels.length >> 2 ) {
723 | var r = _pixels[p];
724 | var g = _pixels[p + 1];
725 | var b = _pixels[p + 2];
726 | var a = _pixels[p + 3];
727 | bset(p++, b);
728 | p++;// bset(p++, g);
729 | bset(p++, r);
730 | p++;// bset(p++, a);
731 | }
732 |
733 | output_pixels = _pixels;
734 | }
735 |
736 | /**
737 | * Loops through every tile in output_tiles
738 | * if the given tile already exists - do nothing
739 | * add new tile only if it's unique
740 | * @param _t New generated
741 | * @return true if new tile was added to output
742 | */
743 | function try_to_add( _t:Tile ):Bool{
744 |
745 | var newtile:String = _t.toString();
746 |
747 | for( outile in output_tiles ){
748 |
749 | if(outile == null) continue;
750 | #if debug
751 | // trace('outile: ${outile}');
752 | // trace('outile.toString(): ${outile.toString()}');
753 | // trace('newtile: ${newtile}');
754 | #end
755 | if( outile.toString() == newtile ){
756 | #if debug
757 | // trace('given tile already exists! ignoring');
758 | #end
759 | return false;
760 | }
761 |
762 | }
763 |
764 | output_tiles.push( tile );
765 | return true;
766 |
767 | }
768 |
769 | function find_tile_by_flag(s:String):Int {
770 |
771 | for( i in 0...output_tiles.length ){
772 | if(output_tiles[i].toString() == s ) return i;
773 | }
774 | return -1;
775 | }
776 |
777 | /**
778 | * Rebuilds whole TSX XML object. Use after generating output
779 | */
780 | function rebuild_tsx() {
781 |
782 | trace('');
783 |
784 | tsx = Xml.createDocument();
785 | tsx.addChild( Xml.parse('') );
786 |
787 | var _tileset = Xml.createElement('tileset');
788 | _tileset.set('name', 'tileset');
789 | _tileset.set('tilewidth', '${Main.tile_size}');
790 | _tileset.set('tileheight', '${Main.tile_size}');
791 | _tileset.set('tilecount', '${output_tiles.length}');
792 |
793 | // Image
794 | //
795 | _tileset.addChild( Xml.parse('') );
796 |
797 |
798 | // terraintypes
799 | //
800 | var _terrains = Xml.createElement('terraintypes');
801 |
802 | for(i in 0...tilesets.length){
803 |
804 | var _tr:TileSet = tilesets[i];
805 | var _terrain = Xml.createElement('terrain');
806 | _terrain.set('name', _tr.name);
807 | var s:String = ''+i+i+i+i;
808 | _terrain.set('tile', '${find_tile_by_flag( s )}');
809 |
810 | _terrains.addChild(_terrain);
811 | }
812 | _tileset.addChild(_terrains);
813 |
814 |
815 | // Tiles
816 | //
817 | var _tx:Xml;
818 | var _tile:Tile;
819 | var str:String = '';
820 | for(i in 0...output_tiles.length){
821 |
822 | _tx = Xml.createElement('tile');
823 | _tile = output_tiles[i];
824 |
825 | if(_tile == null) continue;
826 |
827 | _tx.set('id', Std.string(i) );
828 |
829 | // Tiled order of "pieces"
830 | // |---+---|
831 | // | 1 | 2 |
832 | // |---+---|
833 | // | 3 | 4 |
834 | // |---+---|
835 | // Gotta change that
836 | str = '';
837 | str += (_tile.pieces[0] >= 0) ? Std.string(_tile.pieces[0]) : '';
838 | str += ',';
839 | str += (_tile.pieces[1] >= 0) ? Std.string(_tile.pieces[1]) : '';
840 | str += ',';
841 | str += (_tile.pieces[3] >= 0) ? Std.string(_tile.pieces[3]) : '';
842 | str += ',';
843 | str += (_tile.pieces[2] >= 0) ? Std.string(_tile.pieces[2]) : '';
844 |
845 | _tx.set('terrain', str);
846 |
847 | _tileset.addChild(_tx);
848 | }
849 |
850 | tsx.addChild( _tileset );
851 |
852 |
853 | }
854 |
855 |
856 |
857 |
858 | }
859 |
860 | typedef LayerFlag = {
861 |
862 | var layer:Int;
863 | var flag:Int;
864 | }
865 |
--------------------------------------------------------------------------------
/src/Main.hx:
--------------------------------------------------------------------------------
1 |
2 | import luxe.Input;
3 |
4 | import luxe.Color;
5 | import luxe.Component;
6 | import luxe.options.SpriteOptions;
7 | import luxe.Rectangle;
8 | import luxe.Sprite;
9 | import luxe.Vector;
10 | import luxe.Text;
11 | import luxe.Screen;
12 | import phoenix.Texture;
13 |
14 |
15 | import mint.Control;
16 | import mint.types.Types;
17 | import mint.render.luxe.LuxeMintRender;
18 | import mint.render.luxe.Convert;
19 | import mint.layout.margins.Margins;
20 |
21 |
22 | class Main extends luxe.Game {
23 |
24 | /**
25 | * Main rendered sprite, where everything is visible
26 | */
27 | public static var sprite:Sprite;
28 |
29 | /**
30 | * TODO: to change
31 | */
32 | public static var tile_size:Int = 16;
33 |
34 | var generator:Generator;
35 |
36 | var tilesets:Array;
37 |
38 |
39 | var disp : Text;
40 | var canvas: mint.Canvas;
41 | var rendering: LuxeMintRender;
42 | var layout: Margins;
43 |
44 | var window1:mint.Window;
45 | var path_input:mint.TextEdit;
46 | var load_button:mint.Button;
47 | var generate_button:mint.Button;
48 | var config_text:mint.Label;
49 | var tilesets_list:mint.List;
50 |
51 | var window_tileset:mint.Window;
52 | var tiles_list:mint.List;
53 | var tileset_title:mint.Label;
54 |
55 | var window_output:mint.Window;
56 | var output_scroll:mint.Scroll;
57 | var output_image:mint.Image;
58 | var grid_bg:Sprite;
59 |
60 | var export_bitmap_button:mint.Button;
61 | var export_tsx_button:mint.Button;
62 |
63 | #if web
64 | var fileOpener:js.FileOpener;
65 | #end
66 |
67 |
68 | override public function config(config:luxe.AppConfig) {
69 |
70 | config.preload.textures.push({ id:'input/grid.gif' });
71 |
72 | return config;
73 |
74 | } //config
75 |
76 | override function ready() {
77 |
78 | tilesets = new Array();
79 |
80 | Luxe.renderer.clear_color.rgb(0x121219);
81 |
82 |
83 | generator = new Generator();
84 |
85 | init_canvas();
86 | init_events();
87 |
88 | #if web
89 | fileOpener = new js.FileOpener();
90 | load_tileset('/input/dirt16.gif');
91 | load_tileset('/input/template16.gif');
92 | load_tileset('/input/grass16.gif');
93 | load_tileset('/input/tiles16.gif');
94 | #elseif desktop
95 | load_tileset('input/dirt16.gif');
96 | load_tileset('input/template16.gif');
97 | load_tileset('input/grass16.gif');
98 | load_tileset('input/tiles16.gif');
99 | #end
100 |
101 | } //ready
102 |
103 | override function onwindowresized(event:WindowEvent) {
104 |
105 | return;
106 |
107 | // FAIL
108 |
109 | canvas.w = event.event.x;
110 | canvas.h = event.event.y;
111 |
112 |
113 |
114 | disp.pos.x = Luxe.screen.w-10;
115 | disp.pos.y = Luxe.screen.h-10;
116 |
117 | export_bitmap_button.y = Luxe.screen.h-50;
118 | export_tsx_button.y = Luxe.screen.h-50;
119 |
120 | refresh_output();
121 | refresh_window1();
122 |
123 | // Luxe.camera.size_mode = luxe.Camera.SizeMode.cover;
124 |
125 | // Luxe.camera.viewport.x = -event.event.x + Luxe.camera.viewport.w;
126 | // Luxe.camera.viewport.y = -event.event.y + Luxe.camera.viewport.h;
127 |
128 | trace('Viewport: ${Luxe.camera.viewport.x}, ${Luxe.camera.viewport.y}');
129 | trace('Vie_size: ${Luxe.camera.viewport.w}, ${Luxe.camera.viewport.h}');
130 |
131 | }
132 |
133 | function refresh_output() {
134 |
135 | output_scroll.x = Math.floor( Luxe.screen.width/2 );
136 | output_scroll.y = 0;
137 | output_scroll.w = Math.floor( Luxe.screen.width/2 );
138 | output_scroll.h = Math.floor( Luxe.screen.height - 50 - 2 );
139 |
140 | grid_bg.pos.x = Math.floor( Luxe.screen.width/2 );
141 | grid_bg.pos.y = 0;
142 | grid_bg.size.x = Math.floor( Luxe.screen.width/2 );
143 | grid_bg.size.y = Math.floor( Luxe.screen.height - 50 - 2 );
144 |
145 | }
146 |
147 | function refresh_window1() {
148 |
149 | // output_scroll.h = Math.floor( Luxe.screen.height/2 );
150 | // output_scroll.y = Math.floor( Luxe.screen.height/2 );
151 |
152 | }
153 |
154 |
155 |
156 |
157 | function init_canvas() {
158 |
159 | rendering = new LuxeMintRender();
160 | layout = new Margins();
161 |
162 | canvas = new mint.Canvas({
163 | name:'canvas',
164 | rendering: rendering,
165 | options: { color:new Color(1,1,1,0.0) },
166 | x: 0, y:0, w: Luxe.screen.w, h: Luxe.screen.h
167 | });
168 |
169 | create_output_window();
170 |
171 | disp = new Text({
172 | name:'display.text',
173 | bounds: new luxe.Rectangle(10, Luxe.screen.h/2, Luxe.screen.w/2-20, Luxe.screen.h/2 -10),
174 | bounds_wrap: true,
175 | align: luxe.TextAlign.right,
176 | align_vertical: luxe.TextAlign.bottom,
177 | point_size: 15,
178 | text: 'usage text goes here'
179 | });
180 |
181 | create_configuration_window();
182 | create_tileset_window();
183 |
184 |
185 |
186 |
187 | // Export Bitmap button
188 | export_bitmap_button = new mint.Button({
189 | parent: canvas,
190 | name: 'export_bitmap_button',
191 | text: 'Export Bitmap',
192 | align: mint.types.Types.TextAlign.center,
193 | x: Luxe.screen.w/2, y: Luxe.screen.h-50, w: 100, h: 50,
194 | });
195 | layout.margin(export_bitmap_button, bottom, fixed, 0);
196 | export_bitmap_button.onmouseup.listen(function(e,_){
197 | export_bitmap();
198 | });
199 |
200 |
201 | // Export TSX button
202 | export_tsx_button = new mint.Button({
203 | parent: canvas,
204 | name: 'export_tsx_button',
205 | text: 'Export TSX',
206 | align: mint.types.Types.TextAlign.center,
207 | x: Luxe.screen.w/2+102, y: Luxe.screen.h-50, w: 100, h: 50,
208 | });
209 | layout.margin(export_tsx_button, bottom, fixed, 0);
210 | export_tsx_button.onmouseup.listen(function(e,_){
211 | export_tsx();
212 | });
213 | }
214 |
215 | function add_log(txt:String) {
216 |
217 | disp.text += '\n'+txt;
218 |
219 | }
220 |
221 | function init_events() {
222 |
223 | Luxe.events.listen('config_text.update', function(e:String){
224 | config_text.text = e;
225 | });
226 |
227 | Luxe.events.listen('log.add', function(e:String){
228 | add_log(e);
229 | });
230 |
231 |
232 |
233 | Luxe.events.listen('generator.done', function(_){
234 |
235 | if(output_image != null) output_image.destroy();
236 |
237 | output_image = new mint.Image({
238 | parent: output_scroll,
239 | name: 'image_output',
240 | x:0, y:0, w:generator.w * 2, h:generator.h * 2,
241 | path: 'output'
242 | });
243 | });
244 |
245 | inline function refresh_tilesets_list(){
246 |
247 | tilesets_list.clear();
248 | for(ts in tilesets){
249 | tilesets_list.add_item( create_tileset_li(ts) );
250 | }
251 |
252 | }
253 |
254 | Luxe.events.listen('tilesets_list.rename', function(o:TextEditEvent){
255 |
256 | tilesets[tilesets_list.items.indexOf(o.ctrl)].name = o.text;
257 |
258 | } );
259 |
260 | Luxe.events.listen('tilesets_list.goup', function(o:ControlEvent){
261 |
262 | var idx = tilesets_list.items.indexOf(o.ctrl);
263 | var nidx = idx-1;
264 |
265 | if(nidx < 0) return;
266 |
267 | var swapper = tilesets[nidx];
268 | tilesets.splice(nidx, 1);
269 | tilesets.insert(nidx+1, swapper);
270 |
271 | refresh_tilesets_list();
272 |
273 | generator.update_tilesets(tilesets);
274 | } );
275 |
276 | Luxe.events.listen('tilesets_list.godown', function(o:ControlEvent){
277 |
278 | var idx = tilesets_list.items.indexOf(o.ctrl);
279 | var nidx = idx+1;
280 |
281 | if(nidx > tilesets.length-1) return;
282 |
283 | var swapper = tilesets[nidx];
284 | tilesets.splice(nidx, 1);
285 | tilesets.insert(nidx-1, swapper);
286 |
287 | refresh_tilesets_list();
288 |
289 | generator.update_tilesets(tilesets);
290 | });
291 |
292 | Luxe.events.listen('tilesets_list.remove', function(o:ControlEvent){
293 |
294 | var idx = tilesets_list.items.indexOf(o.ctrl);
295 | var id = tilesets[idx].id;
296 | var tile_id:Hex = 0;
297 |
298 | tilesets.splice(idx, 1);
299 |
300 | refresh_tilesets_list();
301 |
302 | Luxe.resources.destroy( id, true );
303 |
304 | tile_id = Tile.T1;
305 | Luxe.resources.destroy( id+'_'+tile_id, true);
306 | tile_id = Tile.T2;
307 | Luxe.resources.destroy( id+'_'+tile_id, true);
308 | tile_id = Tile.T3;
309 | Luxe.resources.destroy( id+'_'+tile_id, true);
310 | tile_id = Tile.T4;
311 | Luxe.resources.destroy( id+'_'+tile_id, true);
312 | tile_id = Tile.T1 | Tile.T3;
313 | Luxe.resources.destroy( id+'_'+tile_id, true);
314 | tile_id = Tile.T2 | Tile.T4;
315 | Luxe.resources.destroy( id+'_'+tile_id, true);
316 | tile_id = Tile.T1 | Tile.T4;
317 | Luxe.resources.destroy( id+'_'+tile_id, true);
318 | tile_id = Tile.T2 | Tile.T3;
319 | Luxe.resources.destroy( id+'_'+tile_id, true);
320 | tile_id = Tile.T1 | Tile.T2;
321 | Luxe.resources.destroy( id+'_'+tile_id, true);
322 | tile_id = Tile.T3 | Tile.T4;
323 | Luxe.resources.destroy( id+'_'+tile_id, true);
324 | tile_id = Tile.T2 | Tile.T3 | Tile.T4;
325 | Luxe.resources.destroy( id+'_'+tile_id, true);
326 | tile_id = Tile.T1 | Tile.T3 | Tile.T4;
327 | Luxe.resources.destroy( id+'_'+tile_id, true);
328 | tile_id = Tile.T1 | Tile.T2 | Tile.T4;
329 | Luxe.resources.destroy( id+'_'+tile_id, true);
330 | tile_id = Tile.T1 | Tile.T2 | Tile.T3;
331 | Luxe.resources.destroy( id+'_'+tile_id, true);
332 | tile_id = Tile.T1 | Tile.T2 | Tile.T3 | Tile.T4;
333 | Luxe.resources.destroy( id+'_'+tile_id, true);
334 |
335 | generator.calculate_tiles();
336 |
337 | });
338 |
339 |
340 |
341 | }
342 |
343 | function create_configuration_window() {
344 |
345 | window1 = new mint.Window({
346 | parent: canvas,
347 | name: 'window1',
348 | title: 'Configurate',
349 | options: {
350 | color:new Color().rgb(0x121212),
351 | color_titlebar:new Color().rgb(0x191919),
352 | label: { color:new Color().rgb(0x06b4fb) },
353 | close_button: { color:new Color().rgb(0x06b4fb) },
354 | },
355 | x:10, y:10, w:400, h: 430,
356 | w_min: 256, h_min:256,
357 | collapsible:false,
358 | closable: false,
359 | });
360 |
361 | #if desktop
362 | path_input = new mint.TextEdit({
363 | parent: window1,
364 | text: 'input/',
365 | text_size: 12,
366 | name: 'path',
367 | options: { view: { color:new Color().rgb(0x19191c) } },
368 | x: 4, y: 35, w: 340, h: 28,
369 | });
370 | layout.margin(path_input, right, fixed, 58);
371 | #end
372 |
373 |
374 |
375 | load_button = new mint.Button({
376 | parent: window1,
377 | name: 'load',
378 | text: 'LOAD',
379 | options: { view: { color:new Color().rgb(0x008800) } },
380 | #if desktop
381 | x: 345, y: 35, w: 54, h: 28,
382 | #elseif web
383 | x: 4, y: 35, w: 340, h: 28,
384 | #end
385 | });
386 | layout.anchor(load_button, right, right);
387 | load_button.onmouseup.listen(function(e,_){
388 | #if desktop
389 | load_tileset( path_input.text );
390 | #elseif web
391 | fileOpener.open(function(e:Texture) {
392 | // code taken from load_tileset
393 | // TODO: abstract it out to keep things DRY
394 | var ts:TileSet = new TileSet(e);
395 | tilesets_list.add_item( create_tileset_li(ts) );
396 |
397 | tilesets.push(ts);
398 |
399 | generator.update_tilesets(tilesets);
400 | });
401 | #end
402 | });
403 |
404 |
405 | var tilesize_txt = new mint.TextEdit({
406 | parent: window1,
407 | text: '16',
408 | text_size: 16,
409 | name: 'tile_size_txt',
410 | options: { view: { color:new Color().rgb(0x19191c) } },
411 | x: 350, y: 65, w: 50, h: 28,
412 | });
413 | layout.anchor(tilesize_txt, right, right);
414 | tilesize_txt.onchange.listen(function(s:String){
415 |
416 | var i:Int = Math.floor( Std.parseFloat(s) );
417 | if(i < 1){
418 | add_log('Invalid tile size: ${s} -> ${i}');
419 | }
420 | if(i > 0){
421 | Main.tile_size = i;
422 | add_log('Tile size changed to ${Main.tile_size}');
423 | if( tilesets.length > 0 ){
424 | add_log('WARNING: tilesets that don\'t match this size can cause problems.');
425 | }
426 | }
427 | });
428 | var tilesize_label = new mint.Label({
429 | parent: window1,
430 | text: 'tile size:',
431 | text_size: 14,
432 | align: right,
433 | x:300, y:65, w:50, h: 28,
434 | });
435 | layout.anchor(tilesize_label, tilesize_txt, right, left);
436 |
437 |
438 |
439 |
440 | generate_button = new mint.Button({
441 | parent: window1,
442 | name: 'generate',
443 | text: 'GENERATE!',
444 | options: { view: { color:new Color().rgb(0x008800) } },
445 | x: 4, y: 95, w: 400, h: 28,
446 | });
447 | layout.margin(generate_button, right, fixed, 2);
448 | generate_button.onmouseup.listen(function(e,_){
449 | generator.update_tilesets(tilesets);
450 | generator.generate();
451 | });
452 |
453 |
454 | config_text = new mint.Label({
455 | parent: window1,
456 | text: 'Load the tileset first.',
457 | text_size: 14,
458 | align: left,
459 | x:4, y:65, w:150, h: 30,
460 | });
461 | layout.margin(config_text, right, fixed, 4);
462 | layout.margin(config_text, left, fixed, 4);
463 |
464 |
465 |
466 | tilesets_list = new mint.List({
467 | parent: window1,
468 | name: 'list',
469 | options: { view: { color:new Color().rgb(0x19191c) } },
470 | x: 4, y: 130, w: 248, h: 400-130-4
471 | });
472 |
473 | layout.margin(tilesets_list, right, fixed, 4);
474 | layout.margin(tilesets_list, bottom, fixed, 4);
475 |
476 | } //create_configuration_window
477 |
478 |
479 | function create_tileset_window() {
480 |
481 | window_tileset = new mint.Window({
482 | parent: canvas,
483 | name: 'window_tileset',
484 | title: 'Tileset Preview',
485 | options: {
486 | color:new Color().rgb(0x121212),
487 | color_titlebar:new Color().rgb(0x191919),
488 | label: { color:new Color().rgb(0x06b4fb) },
489 | close_button: { color:new Color().rgb(0x06b4fb) },
490 | },
491 | x:430, y:10, w:150, h: 430,
492 | w_min: 150, h_min:256,
493 | collapsible:false,
494 | closable: false,
495 | });
496 |
497 | tileset_title = new mint.Label({
498 | parent: window_tileset,
499 | name: 'tileset_title',
500 | text: 'Select tileset first',
501 | text_size: 14,
502 | align: right,
503 | x:4, y:30, w:150, h: 30,
504 | });
505 | layout.margin(tileset_title, right, fixed, 4);
506 | layout.margin(tileset_title, left, fixed, 4);
507 |
508 |
509 | tiles_list = new mint.List({
510 | parent: window_tileset,
511 | name: 'tiles_list',
512 | x: 6, y: 60, w: 150, h: 60-100-4
513 | });
514 | layout.margin(tiles_list, right, fixed, 6);
515 | layout.margin(tiles_list, bottom, fixed, 8);
516 |
517 | } // create_tileset_window
518 |
519 | function create_output_window(){
520 |
521 | // Not actually a window...
522 |
523 | output_scroll = new mint.Scroll({
524 | parent: canvas,
525 | name: 'output_scroll',
526 | options: {
527 | color_handles:new Color().rgb(0xffffff),
528 | color:new Color(0.13, 0.17, 0.2, 0.5),
529 | },
530 | x:Luxe.screen.w/2, y:0, w: Luxe.screen.w/2, h: Luxe.screen.h/2 - 50 - 2,
531 | });
532 |
533 | // Chess background
534 | grid_bg = new Sprite({
535 | name:'grid_bg',
536 | texture: Luxe.resources.texture('input/grid.gif'),
537 | uv: new Rectangle(0, 0, Luxe.screen.w/2, Luxe.screen.h - 52),
538 | centered: false,
539 | size: new Vector(Luxe.screen.w/2, Luxe.screen.h - 52),
540 | pos: new Vector(Luxe.screen.w/2, 0),
541 | depth: -1,
542 | });
543 | grid_bg.texture.filter_mag = grid_bg.texture.filter_min = nearest;
544 | grid_bg.texture.clamp_s = grid_bg.texture.clamp_t = repeat;
545 |
546 | refresh_output();
547 |
548 | } // create_output_window
549 |
550 | function create_tileset_li(tileset:TileSet) {
551 |
552 | var _panel = new mint.Panel({
553 | parent: tilesets_list,
554 | name: 'panel_${tileset.id}',
555 | x:2, y:4, w:236, h:64,
556 | });
557 |
558 | layout.margin(_panel, right, fixed, 8);
559 |
560 | var _img = new mint.Image({
561 | parent: _panel, name: 'icon_${tileset.id}',
562 | x:0, y:0, w:64, h:64,
563 | mouse_input:true,
564 | path: tileset.id
565 | });
566 | _img.onmouseup.listen(function(e,ctrl){
567 | var idx = tilesets_list.items.indexOf(ctrl.parent);
568 | tileset_preview_show(idx);
569 | });
570 |
571 | var _title = new mint.TextEdit({
572 | parent: _panel,
573 | text: tileset.name,
574 | text_size: 16,
575 | name: 'tileset_name_${tileset.id}',
576 | options: { view: { color:new Color().rgb(0x19191c) } },
577 | x:80, y:8, w:148, h:18
578 | });
579 | layout.margin(_title, right, fixed, 0);
580 | _title.onchange.listen( function(s){
581 | Luxe.events.fire('tilesets_list.rename', {text: s, ctrl: _title.parent});
582 | } );
583 |
584 | var _order_up = new mint.Button({
585 | parent: _panel, name: 'button_${tileset.id}_orderup',
586 | text: 'up ^',
587 | x:80, y:36, w:40, h:20, text_size: 16,
588 | align: TextAlign.center,
589 | });
590 | _order_up.onmouseup.listen(function(e,ctrl){
591 | Luxe.events.fire('tilesets_list.goup', {event: e, ctrl: ctrl.parent});
592 | });
593 |
594 |
595 | var _order_down = new mint.Button({
596 | parent: _panel, name: 'button_${tileset.id}_orderdown',
597 | text: 'down v',
598 | x:80+40, y:36, w:64, h:20, text_size: 16,
599 | align: TextAlign.center,
600 | });
601 | _order_down.onmouseup.listen(function(e,ctrl){
602 | Luxe.events.fire('tilesets_list.godown', {event: e, ctrl: ctrl.parent});
603 | });
604 |
605 | var _remove = new mint.Button({
606 | parent: _panel, name: 'button_${tileset.id}_orderdown',
607 | text: 'remove',
608 | x:236-64, y:36, w:64, h:20, text_size: 16,
609 | align: TextAlign.center,
610 | });
611 | _remove.onmouseup.listen(function(e,ctrl){
612 | Luxe.events.fire('tilesets_list.remove', {event: e, ctrl: ctrl.parent});
613 | });
614 | layout.anchor(_remove, right, right);
615 |
616 |
617 |
618 | return _panel;
619 |
620 | } //create_tileset_li
621 |
622 |
623 | function create_tile_li(tile:Tile) {
624 |
625 | var _panel = new mint.Panel({
626 | parent: tiles_list,
627 | name: 'panel_${tile.flag}',
628 | x:4, y:4, w:150, h:Main.tile_size*2+8,
629 | });
630 |
631 | layout.margin(_panel, right, fixed, 4);
632 |
633 | new mint.Image({
634 | parent: _panel, name: 'icon_${tile.flag}',
635 | x:4, y:4, w:Main.tile_size*2, h:Main.tile_size*2,
636 | path: tile.id,
637 | });
638 |
639 | var _title = new mint.Label({
640 | parent: _panel,
641 | name: 'label_${tile.id}',
642 | mouse_input:true, x:Main.tile_size*2+8, y:4, w:148, h:18, text_size: 14,
643 | align: TextAlign.left, align_vertical: TextAlign.top,
644 | // text: '0x${StringTools.hex(tile.flag)}',
645 | text: '${tile.flag}',
646 | });
647 |
648 | layout.margin(_title, right, fixed, 8);
649 |
650 | return _panel;
651 |
652 | } //create_tile_li
653 |
654 |
655 | function tileset_preview_show(idx:Int) {
656 |
657 | tileset_title.text = tilesets[idx].id;
658 |
659 | tiles_list.clear();
660 |
661 | for(t in tilesets[idx].tiles){
662 |
663 | tiles_list.add_item( create_tile_li(t) );
664 |
665 | }
666 |
667 | }
668 |
669 |
670 | override function onrender() {
671 |
672 | canvas.render();
673 |
674 | } //onrender
675 |
676 | override function update(dt:Float) {
677 |
678 | canvas.update(dt);
679 |
680 | } //update
681 |
682 |
683 | override function onmousemove(e) {
684 |
685 | canvas.mousemove( Convert.mouse_event(e) );
686 |
687 | }
688 |
689 | override function onmousewheel(e) {
690 | canvas.mousewheel( Convert.mouse_event(e) );
691 | }
692 |
693 | override function onmouseup(e) {
694 | canvas.mouseup( Convert.mouse_event(e) );
695 | }
696 |
697 | override function onmousedown(e) {
698 | canvas.mousedown( Convert.mouse_event(e) );
699 | }
700 |
701 | override function onkeydown(e:luxe.Input.KeyEvent) {
702 | canvas.keydown( Convert.key_event(e) );
703 | }
704 |
705 | override function ontextinput(e:luxe.Input.TextEvent) {
706 | canvas.textinput( Convert.text_event(e) );
707 | }
708 |
709 | override function onkeyup(e:luxe.Input.KeyEvent) {
710 |
711 | canvas.keyup( Convert.key_event(e) );
712 |
713 | if(e.keycode == Key.escape) {
714 | Luxe.shutdown();
715 | }
716 |
717 | } //onkeyup
718 |
719 | function load_tileset(url:String) {
720 |
721 | if(Luxe.resources.texture(url) != null){
722 | add_log('Tileset was already loaded! (${url})');
723 | return;
724 | }
725 |
726 | var load:snow.api.Promise = Luxe.resources.load_texture(url);
727 |
728 | load.then(function(e:Texture){
729 |
730 | var ts:TileSet = new TileSet(e);
731 | tilesets_list.add_item( create_tileset_li(ts) );
732 |
733 | tilesets.push(ts);
734 |
735 | generator.update_tilesets(tilesets);
736 |
737 | },
738 | function(_){
739 | Luxe.resources.remove( Luxe.resources.texture(url) );
740 | add_log('FAILED to load ${url}');
741 | });
742 |
743 |
744 | }
745 |
746 | function prepare_export(){
747 |
748 | #if !web
749 | if(!sys.FileSystem.exists(sys.FileSystem.absolutePath('output/'))){
750 | sys.FileSystem.createDirectory(sys.FileSystem.absolutePath('output/'));
751 | }
752 | #end
753 |
754 | }
755 |
756 |
757 | function export_bitmap() {
758 |
759 | prepare_export();
760 |
761 | #if desktop
762 | var data = format.png.Tools.build32BGRA( generator.w, generator.h, generator.output_pixels.toBytes() );
763 | var out = sys.io.File.write( sys.FileSystem.absolutePath('output/output.png'), true);
764 | new format.png.Writer(out).write(data);
765 | add_log('File saved in output/output.png');
766 | #elseif web
767 | var data:js.html.Uint8Array = js.BuildPNG.build(generator.w, generator.h, generator.output_pixels.toBytes());
768 | var blob:js.html.Blob = new js.html.Blob([data], {type: 'image/png'});
769 | js.html.FileSaver.saveAs(blob, "output.png");
770 | add_log("File saved as output.png");
771 | #end
772 |
773 | }
774 |
775 | function export_tsx() {
776 |
777 | prepare_export();
778 |
779 | #if desktop
780 | var out = sys.io.File.write( sys.FileSystem.absolutePath('output/output.tsx'), false);
781 | sys.io.File.saveContent("output/output.tsx", generator.tsx.toString());
782 | add_log('File saved in output/output.tsx');
783 | #elseif web
784 | var blob:js.html.Blob = new js.html.Blob([generator.tsx.toString()], {type: 'text/xml;charset=utf8'});
785 | js.html.FileSaver.saveAs(blob, "output.tsx");
786 | add_log('File saved as output.tsx');
787 | #end
788 |
789 | }
790 |
791 |
792 | } //Main
793 |
794 |
795 | typedef ControlEvent = {
796 | var event:MouseEvent;
797 | var ctrl:Control;
798 | }
799 | typedef TextEditEvent = {
800 | var text:String;
801 | var ctrl:Control;
802 | }
803 |
--------------------------------------------------------------------------------
/jslibs/pako.min.js:
--------------------------------------------------------------------------------
1 | /* pako 0.2.8 nodeca/pako */
2 | !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.pako=t()}}(function(){return function t(e,a,i){function n(s,o){if(!a[s]){if(!e[s]){var l="function"==typeof require&&require;if(!o&&l)return l(s,!0);if(r)return r(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var d=a[s]={exports:{}};e[s][0].call(d.exports,function(t){var a=e[s][1][t];return n(a?a:t)},d,d.exports,t,e,a,i)}return a[s].exports}for(var r="function"==typeof require&&require,s=0;s0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var a=s.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==c)throw new Error(h[a]);e.header&&s.deflateSetHeader(this.strm,e.header)};v.prototype.push=function(t,e){var a,i,n=this.strm,r=this.options.chunkSize;if(this.ended)return!1;i=e===~~e?e:e===!0?u:_,"string"==typeof t?n.input=l.string2buf(t):"[object ArrayBuffer]"===f.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;do{if(0===n.avail_out&&(n.output=new o.Buf8(r),n.next_out=0,n.avail_out=r),a=s.deflate(n,i),a!==b&&a!==c)return this.onEnd(a),this.ended=!0,!1;(0===n.avail_out||0===n.avail_in&&(i===u||i===g))&&this.onData("string"===this.options.to?l.buf2binstring(o.shrinkBuf(n.output,n.next_out)):o.shrinkBuf(n.output,n.next_out))}while((n.avail_in>0||0===n.avail_out)&&a!==b);return i===u?(a=s.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===c):i===g?(this.onEnd(c),n.avail_out=0,!0):!0},v.prototype.onData=function(t){this.chunks.push(t)},v.prototype.onEnd=function(t){t===c&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=v,a.deflate=i,a.deflateRaw=n,a.gzip=r},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate.js":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(t,e,a){"use strict";function i(t,e){var a=new u(e);if(a.push(t,!0),a.err)throw a.msg;return a.result}function n(t,e){return e=e||{},e.raw=!0,i(t,e)}var r=t("./zlib/inflate.js"),s=t("./utils/common"),o=t("./utils/strings"),l=t("./zlib/constants"),h=t("./zlib/messages"),d=t("./zlib/zstream"),f=t("./zlib/gzheader"),_=Object.prototype.toString,u=function(t){this.options=s.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0===(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var a=r.inflateInit2(this.strm,e.windowBits);if(a!==l.Z_OK)throw new Error(h[a]);this.header=new f,r.inflateGetHeader(this.strm,this.header)};u.prototype.push=function(t,e){var a,i,n,h,d,f=this.strm,u=this.options.chunkSize,c=!1;if(this.ended)return!1;i=e===~~e?e:e===!0?l.Z_FINISH:l.Z_NO_FLUSH,"string"==typeof t?f.input=o.binstring2buf(t):"[object ArrayBuffer]"===_.call(t)?f.input=new Uint8Array(t):f.input=t,f.next_in=0,f.avail_in=f.input.length;do{if(0===f.avail_out&&(f.output=new s.Buf8(u),f.next_out=0,f.avail_out=u),a=r.inflate(f,l.Z_NO_FLUSH),a===l.Z_BUF_ERROR&&c===!0&&(a=l.Z_OK,c=!1),a!==l.Z_STREAM_END&&a!==l.Z_OK)return this.onEnd(a),this.ended=!0,!1;f.next_out&&(0===f.avail_out||a===l.Z_STREAM_END||0===f.avail_in&&(i===l.Z_FINISH||i===l.Z_SYNC_FLUSH))&&("string"===this.options.to?(n=o.utf8border(f.output,f.next_out),h=f.next_out-n,d=o.buf2string(f.output,n),f.next_out=h,f.avail_out=u-h,h&&s.arraySet(f.output,f.output,n,h,0),this.onData(d)):this.onData(s.shrinkBuf(f.output,f.next_out))),0===f.avail_in&&0===f.avail_out&&(c=!0)}while((f.avail_in>0||0===f.avail_out)&&a!==l.Z_STREAM_END);return a===l.Z_STREAM_END&&(i=l.Z_FINISH),i===l.Z_FINISH?(a=r.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===l.Z_OK):i===l.Z_SYNC_FLUSH?(this.onEnd(l.Z_OK),f.avail_out=0,!0):!0},u.prototype.onData=function(t){this.chunks.push(t)},u.prototype.onEnd=function(t){t===l.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Inflate=u,a.inflate=i,a.inflateRaw=n,a.ungzip=i},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate.js":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(t,e,a){"use strict";var i="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var i in a)a.hasOwnProperty(i)&&(t[i]=a[i])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,a,i,n){if(e.subarray&&t.subarray)return void t.set(e.subarray(a,a+i),n);for(var r=0;i>r;r++)t[n+r]=e[a+r]},flattenChunks:function(t){var e,a,i,n,r,s;for(i=0,e=0,a=t.length;a>e;e++)i+=t[e].length;for(s=new Uint8Array(i),n=0,e=0,a=t.length;a>e;e++)r=t[e],s.set(r,n),n+=r.length;return s}},r={arraySet:function(t,e,a,i,n){for(var r=0;i>r;r++)t[n+r]=e[a+r]},flattenChunks:function(t){return[].concat.apply([],t)}};a.setTyped=function(t){t?(a.Buf8=Uint8Array,a.Buf16=Uint16Array,a.Buf32=Int32Array,a.assign(a,n)):(a.Buf8=Array,a.Buf16=Array,a.Buf32=Array,a.assign(a,r))},a.setTyped(i)},{}],4:[function(t,e,a){"use strict";function i(t,e){if(65537>e&&(t.subarray&&s||!t.subarray&&r))return String.fromCharCode.apply(null,n.shrinkBuf(t,e));for(var a="",i=0;e>i;i++)a+=String.fromCharCode(t[i]);return a}var n=t("./common"),r=!0,s=!0;try{String.fromCharCode.apply(null,[0])}catch(o){r=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(o){s=!1}for(var l=new n.Buf8(256),h=0;256>h;h++)l[h]=h>=252?6:h>=248?5:h>=240?4:h>=224?3:h>=192?2:1;l[254]=l[254]=1,a.string2buf=function(t){var e,a,i,r,s,o=t.length,l=0;for(r=0;o>r;r++)a=t.charCodeAt(r),55296===(64512&a)&&o>r+1&&(i=t.charCodeAt(r+1),56320===(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),r++)),l+=128>a?1:2048>a?2:65536>a?3:4;for(e=new n.Buf8(l),s=0,r=0;l>s;r++)a=t.charCodeAt(r),55296===(64512&a)&&o>r+1&&(i=t.charCodeAt(r+1),56320===(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),r++)),128>a?e[s++]=a:2048>a?(e[s++]=192|a>>>6,e[s++]=128|63&a):65536>a?(e[s++]=224|a>>>12,e[s++]=128|a>>>6&63,e[s++]=128|63&a):(e[s++]=240|a>>>18,e[s++]=128|a>>>12&63,e[s++]=128|a>>>6&63,e[s++]=128|63&a);return e},a.buf2binstring=function(t){return i(t,t.length)},a.binstring2buf=function(t){for(var e=new n.Buf8(t.length),a=0,i=e.length;i>a;a++)e[a]=t.charCodeAt(a);return e},a.buf2string=function(t,e){var a,n,r,s,o=e||t.length,h=new Array(2*o);for(n=0,a=0;o>a;)if(r=t[a++],128>r)h[n++]=r;else if(s=l[r],s>4)h[n++]=65533,a+=s-1;else{for(r&=2===s?31:3===s?15:7;s>1&&o>a;)r=r<<6|63&t[a++],s--;s>1?h[n++]=65533:65536>r?h[n++]=r:(r-=65536,h[n++]=55296|r>>10&1023,h[n++]=56320|1023&r)}return i(h,n)},a.utf8border=function(t,e){var a;for(e=e||t.length,e>t.length&&(e=t.length),a=e-1;a>=0&&128===(192&t[a]);)a--;return 0>a?e:0===a?e:a+l[t[a]]>e?a:e}},{"./common":3}],5:[function(t,e,a){"use strict";function i(t,e,a,i){for(var n=65535&t|0,r=t>>>16&65535|0,s=0;0!==a;){s=a>2e3?2e3:a,a-=s;do n=n+e[i++]|0,r=r+n|0;while(--s);n%=65521,r%=65521}return n|r<<16|0}e.exports=i},{}],6:[function(t,e,a){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],7:[function(t,e,a){"use strict";function i(){for(var t,e=[],a=0;256>a;a++){t=a;for(var i=0;8>i;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function n(t,e,a,i){var n=r,s=i+a;t=-1^t;for(var o=i;s>o;o++)t=t>>>8^n[255&(t^e[o])];return-1^t}var r=i();e.exports=n},{}],8:[function(t,e,a){"use strict";function i(t,e){return t.msg=N[e],e}function n(t){return(t<<1)-(t>4?9:0)}function r(t){for(var e=t.length;--e>=0;)t[e]=0}function s(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(A.arraySet(t.output,e.pending_buf,e.pending_out,a,t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function o(t,e){Z._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,s(t.strm)}function l(t,e){t.pending_buf[t.pending++]=e}function h(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function d(t,e,a,i){var n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,A.arraySet(e,t.input,t.next_in,n,a),1===t.state.wrap?t.adler=R(t.adler,e,n,a):2===t.state.wrap&&(t.adler=C(t.adler,e,n,a)),t.next_in+=n,t.total_in+=n,n)}function f(t,e){var a,i,n=t.max_chain_length,r=t.strstart,s=t.prev_length,o=t.nice_match,l=t.strstart>t.w_size-ht?t.strstart-(t.w_size-ht):0,h=t.window,d=t.w_mask,f=t.prev,_=t.strstart+lt,u=h[r+s-1],c=h[r+s];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do if(a=e,h[a+s]===c&&h[a+s-1]===u&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do;while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&_>r);if(i=lt-(_-r),r=_-lt,i>s){if(t.match_start=e,s=i,i>=o)break;u=h[r+s-1],c=h[r+s]}}while((e=f[e&d])>l&&0!==--n);return s<=t.lookahead?s:t.lookahead}function _(t){var e,a,i,n,r,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-ht)){A.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,a=t.hash_size,e=a;do i=t.head[--e],t.head[e]=i>=s?i-s:0;while(--a);a=s,e=a;do i=t.prev[--e],t.prev[e]=i>=s?i-s:0;while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=d(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=ot)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(_(t),0===t.lookahead&&e===O)return wt;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,o(t,!1),0===t.strm.avail_out))return wt;if(t.strstart-t.block_start>=t.w_size-ht&&(o(t,!1),0===t.strm.avail_out))return wt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?vt:kt):t.strstart>t.block_start&&(o(t,!1),0===t.strm.avail_out)?wt:wt}function c(t,e){for(var a,i;;){if(t.lookahead=ot&&(t.ins_h=(t.ins_h<=ot)if(i=Z._tr_tally(t,t.strstart-t.match_start,t.match_length-ot),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=ot){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=ot&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=ot-1)),t.prev_length>=ot&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-ot,i=Z._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-ot),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=ot&&t.strstart>0&&(n=t.strstart-1,i=s[n],i===s[++n]&&i===s[++n]&&i===s[++n])){r=t.strstart+lt;do;while(i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&r>n);t.match_length=lt-(r-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=ot?(a=Z._tr_tally(t,1,t.match_length-ot),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(o(t,!1),0===t.strm.avail_out))return wt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?vt:kt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?wt:pt}function m(t,e){for(var a;;){if(0===t.lookahead&&(_(t),0===t.lookahead)){if(e===O)return wt;break}if(t.match_length=0,a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(o(t,!1),0===t.strm.avail_out))return wt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?vt:kt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?wt:pt}function w(t){t.window_size=2*t.w_size,r(t.head),t.max_lazy_match=E[t.level].max_lazy,t.good_match=E[t.level].good_length,t.nice_match=E[t.level].nice_length,t.max_chain_length=E[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=ot-1,t.match_available=0,t.ins_h=0}function p(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=J,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new A.Buf16(2*rt),this.dyn_dtree=new A.Buf16(2*(2*it+1)),this.bl_tree=new A.Buf16(2*(2*nt+1)),r(this.dyn_ltree),r(this.dyn_dtree),r(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new A.Buf16(st+1),this.heap=new A.Buf16(2*at+1),r(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new A.Buf16(2*at+1),r(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function v(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=W,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?ft:gt,t.adler=2===e.wrap?0:1,e.last_flush=O,Z._tr_init(e),D):i(t,H)}function k(t){var e=v(t);return e===D&&w(t.state),e}function x(t,e){return t&&t.state?2!==t.state.wrap?H:(t.state.gzhead=e,D):H}function y(t,e,a,n,r,s){if(!t)return H;var o=1;if(e===M&&(e=6),0>n?(o=0,n=-n):n>15&&(o=2,n-=16),1>r||r>Q||a!==J||8>n||n>15||0>e||e>9||0>s||s>G)return i(t,H);8===n&&(n=9);var l=new p;return t.state=l,l.strm=t,l.wrap=o,l.gzhead=null,l.w_bits=n,l.w_size=1<>1,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=s,l.method=a,k(t)}function z(t,e){return y(t,e,J,V,$,X)}function B(t,e){var a,o,d,f;if(!t||!t.state||e>T||0>e)return t?i(t,H):H;if(o=t.state,!t.output||!t.input&&0!==t.avail_in||o.status===mt&&e!==F)return i(t,0===t.avail_out?K:H);if(o.strm=t,a=o.last_flush,o.last_flush=e,o.status===ft)if(2===o.wrap)t.adler=0,l(o,31),l(o,139),l(o,8),o.gzhead?(l(o,(o.gzhead.text?1:0)+(o.gzhead.hcrc?2:0)+(o.gzhead.extra?4:0)+(o.gzhead.name?8:0)+(o.gzhead.comment?16:0)),l(o,255&o.gzhead.time),l(o,o.gzhead.time>>8&255),l(o,o.gzhead.time>>16&255),l(o,o.gzhead.time>>24&255),l(o,9===o.level?2:o.strategy>=Y||o.level<2?4:0),l(o,255&o.gzhead.os),o.gzhead.extra&&o.gzhead.extra.length&&(l(o,255&o.gzhead.extra.length),l(o,o.gzhead.extra.length>>8&255)),o.gzhead.hcrc&&(t.adler=C(t.adler,o.pending_buf,o.pending,0)),o.gzindex=0,o.status=_t):(l(o,0),l(o,0),l(o,0),l(o,0),l(o,0),l(o,9===o.level?2:o.strategy>=Y||o.level<2?4:0),l(o,xt),o.status=gt);else{var _=J+(o.w_bits-8<<4)<<8,u=-1;u=o.strategy>=Y||o.level<2?0:o.level<6?1:6===o.level?2:3,_|=u<<6,0!==o.strstart&&(_|=dt),_+=31-_%31,o.status=gt,h(o,_),0!==o.strstart&&(h(o,t.adler>>>16),h(o,65535&t.adler)),t.adler=1}if(o.status===_t)if(o.gzhead.extra){for(d=o.pending;o.gzindex<(65535&o.gzhead.extra.length)&&(o.pending!==o.pending_buf_size||(o.gzhead.hcrc&&o.pending>d&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending!==o.pending_buf_size));)l(o,255&o.gzhead.extra[o.gzindex]),o.gzindex++;o.gzhead.hcrc&&o.pending>d&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),o.gzindex===o.gzhead.extra.length&&(o.gzindex=0,o.status=ut)}else o.status=ut;if(o.status===ut)if(o.gzhead.name){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.gzindex=0,o.status=ct)}else o.status=ct;if(o.status===ct)if(o.gzhead.comment){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=C(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.status=bt)}else o.status=bt;if(o.status===bt&&(o.gzhead.hcrc?(o.pending+2>o.pending_buf_size&&s(t),o.pending+2<=o.pending_buf_size&&(l(o,255&t.adler),l(o,t.adler>>8&255),t.adler=0,o.status=gt)):o.status=gt),0!==o.pending){if(s(t),0===t.avail_out)return o.last_flush=-1,D}else if(0===t.avail_in&&n(e)<=n(a)&&e!==F)return i(t,K);if(o.status===mt&&0!==t.avail_in)return i(t,K);if(0!==t.avail_in||0!==o.lookahead||e!==O&&o.status!==mt){var c=o.strategy===Y?m(o,e):o.strategy===q?g(o,e):E[o.level].func(o,e);if((c===vt||c===kt)&&(o.status=mt),c===wt||c===vt)return 0===t.avail_out&&(o.last_flush=-1),D;if(c===pt&&(e===I?Z._tr_align(o):e!==T&&(Z._tr_stored_block(o,0,0,!1),e===U&&(r(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),s(t),0===t.avail_out))return o.last_flush=-1,D}return e!==F?D:o.wrap<=0?L:(2===o.wrap?(l(o,255&t.adler),l(o,t.adler>>8&255),l(o,t.adler>>16&255),l(o,t.adler>>24&255),l(o,255&t.total_in),l(o,t.total_in>>8&255),l(o,t.total_in>>16&255),l(o,t.total_in>>24&255)):(h(o,t.adler>>>16),h(o,65535&t.adler)),s(t),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?D:L)}function S(t){var e;return t&&t.state?(e=t.state.status,e!==ft&&e!==_t&&e!==ut&&e!==ct&&e!==bt&&e!==gt&&e!==mt?i(t,H):(t.state=null,e===gt?i(t,j):D)):H}var E,A=t("../utils/common"),Z=t("./trees"),R=t("./adler32"),C=t("./crc32"),N=t("./messages"),O=0,I=1,U=3,F=4,T=5,D=0,L=1,H=-2,j=-3,K=-5,M=-1,P=1,Y=2,q=3,G=4,X=0,W=2,J=8,Q=9,V=15,$=8,tt=29,et=256,at=et+1+tt,it=30,nt=19,rt=2*at+1,st=15,ot=3,lt=258,ht=lt+ot+1,dt=32,ft=42,_t=69,ut=73,ct=91,bt=103,gt=113,mt=666,wt=1,pt=2,vt=3,kt=4,xt=3,yt=function(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n};E=[new yt(0,0,0,0,u),new yt(4,4,8,4,c),new yt(4,5,16,8,c),new yt(4,6,32,32,c),new yt(4,4,16,16,b),new yt(8,16,32,32,b),new yt(8,16,128,128,b),new yt(8,32,128,256,b),new yt(32,128,258,1024,b),new yt(32,258,258,4096,b)],a.deflateInit=z,a.deflateInit2=y,a.deflateReset=k,a.deflateResetKeep=v,a.deflateSetHeader=x,a.deflate=B,a.deflateEnd=S,a.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":3,"./adler32":5,"./crc32":7,"./messages":13,"./trees":14}],9:[function(t,e,a){"use strict";function i(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}e.exports=i},{}],10:[function(t,e,a){"use strict";var i=30,n=12;e.exports=function(t,e){var a,r,s,o,l,h,d,f,_,u,c,b,g,m,w,p,v,k,x,y,z,B,S,E,A;a=t.state,r=t.next_in,E=t.input,s=r+(t.avail_in-5),o=t.next_out,A=t.output,l=o-(e-t.avail_out),h=o+(t.avail_out-257),d=a.dmax,f=a.wsize,_=a.whave,u=a.wnext,c=a.window,b=a.hold,g=a.bits,m=a.lencode,w=a.distcode,p=(1<g&&(b+=E[r++]<>>24,b>>>=x,g-=x,x=k>>>16&255,0===x)A[o++]=65535&k;else{if(!(16&x)){if(0===(64&x)){k=m[(65535&k)+(b&(1<g&&(b+=E[r++]<>>=x,g-=x),15>g&&(b+=E[r++]<>>24,b>>>=x,g-=x,x=k>>>16&255,!(16&x)){if(0===(64&x)){k=w[(65535&k)+(b&(1<g&&(b+=E[r++]<g&&(b+=E[r++]<d){t.msg="invalid distance too far back",a.mode=i;break t}if(b>>>=x,g-=x,x=o-l,z>x){if(x=z-x,x>_&&a.sane){t.msg="invalid distance too far back",a.mode=i;break t}if(B=0,S=c,0===u){if(B+=f-x,y>x){y-=x;do A[o++]=c[B++];while(--x);B=o-z,S=A}}else if(x>u){if(B+=f+u-x,x-=u,y>x){y-=x;do A[o++]=c[B++];while(--x);if(B=0,y>u){x=u,y-=x;do A[o++]=c[B++];while(--x);B=o-z,S=A}}}else if(B+=u-x,y>x){y-=x;do A[o++]=c[B++];while(--x);B=o-z,S=A}for(;y>2;)A[o++]=S[B++],A[o++]=S[B++],A[o++]=S[B++],y-=3;y&&(A[o++]=S[B++],y>1&&(A[o++]=S[B++]))}else{B=o-z;do A[o++]=A[B++],A[o++]=A[B++],A[o++]=A[B++],y-=3;while(y>2);y&&(A[o++]=A[B++],y>1&&(A[o++]=A[B++]))}break}}break}}while(s>r&&h>o);y=g>>3,r-=y,g-=y<<3,b&=(1<r?5+(s-r):5-(r-s),t.avail_out=h>o?257+(h-o):257-(o-h),a.hold=b,a.bits=g}},{}],11:[function(t,e,a){"use strict";function i(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function n(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new m.Buf16(320),this.work=new m.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function r(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=F,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new m.Buf32(ct),e.distcode=e.distdyn=new m.Buf32(bt),e.sane=1,e.back=-1,A):C}function s(t){var e;return t&&t.state?(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,r(t)):C}function o(t,e){var a,i;return t&&t.state?(i=t.state,0>e?(a=0,e=-e):(a=(e>>4)+1,48>e&&(e&=15)),e&&(8>e||e>15)?C:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,s(t))):C}function l(t,e){var a,i;return t?(i=new n,t.state=i,i.window=null,a=o(t,e),a!==A&&(t.state=null),a):C}function h(t){return l(t,mt)}function d(t){if(wt){var e;for(b=new m.Buf32(512),g=new m.Buf32(32),e=0;144>e;)t.lens[e++]=8;for(;256>e;)t.lens[e++]=9;for(;280>e;)t.lens[e++]=7;for(;288>e;)t.lens[e++]=8;for(k(y,t.lens,0,288,b,0,t.work,{bits:9}),e=0;32>e;)t.lens[e++]=5;k(z,t.lens,0,32,g,0,t.work,{bits:5}),wt=!1}t.lencode=b,t.lenbits=9,t.distcode=g,t.distbits=5}function f(t,e,a,i){var n,r=t.state;return null===r.window&&(r.wsize=1<=r.wsize?(m.arraySet(r.window,e,a-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(n=r.wsize-r.wnext,n>i&&(n=i),m.arraySet(r.window,e,a-i,n,r.wnext),i-=n,i?(m.arraySet(r.window,e,a-i,i,0),r.wnext=i,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whaveu;){if(0===l)break t;l--,_+=n[s++]<>>8&255,a.check=p(a.check,Et,2,0),_=0,u=0,a.mode=T;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&_)<<8)+(_>>8))%31){t.msg="incorrect header check",a.mode=ft;break}if((15&_)!==U){t.msg="unknown compression method",a.mode=ft;break}if(_>>>=4,u-=4,xt=(15&_)+8,0===a.wbits)a.wbits=xt;else if(xt>a.wbits){t.msg="invalid window size",a.mode=ft;break}a.dmax=1<u;){if(0===l)break t;l--,_+=n[s++]<>8&1),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=p(a.check,Et,2,0)),_=0,u=0,a.mode=D;case D:for(;32>u;){if(0===l)break t;l--,_+=n[s++]<>>8&255,Et[2]=_>>>16&255,Et[3]=_>>>24&255,a.check=p(a.check,Et,4,0)),_=0,u=0,a.mode=L;case L:for(;16>u;){if(0===l)break t;l--,_+=n[s++]<>8),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=p(a.check,Et,2,0)),_=0,u=0,a.mode=H;case H:if(1024&a.flags){for(;16>u;){if(0===l)break t;l--,_+=n[s++]<>>8&255,a.check=p(a.check,Et,2,0)),_=0,u=0}else a.head&&(a.head.extra=null);a.mode=j;case j:if(1024&a.flags&&(g=a.length,g>l&&(g=l),g&&(a.head&&(xt=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Array(a.head.extra_len)),m.arraySet(a.head.extra,n,s,g,xt)),512&a.flags&&(a.check=p(a.check,n,g,s)),l-=g,s+=g,a.length-=g),a.length))break t;a.length=0,a.mode=K;case K:if(2048&a.flags){if(0===l)break t;g=0;do xt=n[s+g++],a.head&&xt&&a.length<65536&&(a.head.name+=String.fromCharCode(xt));while(xt&&l>g);if(512&a.flags&&(a.check=p(a.check,n,g,s)),l-=g,s+=g,xt)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=M;case M:if(4096&a.flags){if(0===l)break t;g=0;do xt=n[s+g++],a.head&&xt&&a.length<65536&&(a.head.comment+=String.fromCharCode(xt));while(xt&&l>g);if(512&a.flags&&(a.check=p(a.check,n,g,s)),l-=g,s+=g,xt)break t}else a.head&&(a.head.comment=null);a.mode=P;case P:if(512&a.flags){for(;16>u;){if(0===l)break t;l--,_+=n[s++]<>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=G;break;case Y:for(;32>u;){if(0===l)break t;l--,_+=n[s++]<>>=7&u,u-=7&u,a.mode=lt;break}for(;3>u;){if(0===l)break t;l--,_+=n[s++]<>>=1,u-=1,3&_){case 0:a.mode=W;break;case 1:if(d(a),a.mode=et,e===E){_>>>=2,u-=2;break t}break;case 2:a.mode=V;break;case 3:t.msg="invalid block type",a.mode=ft}_>>>=2,u-=2;break;case W:for(_>>>=7&u,u-=7&u;32>u;){if(0===l)break t;l--,_+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",a.mode=ft;break}if(a.length=65535&_,_=0,u=0,a.mode=J,e===E)break t;case J:a.mode=Q;case Q:if(g=a.length){if(g>l&&(g=l),g>h&&(g=h),0===g)break t;m.arraySet(r,n,s,g,o),l-=g,s+=g,h-=g,o+=g,a.length-=g;break}a.mode=G;break;case V:for(;14>u;){if(0===l)break t;l--,_+=n[s++]<>>=5,u-=5,a.ndist=(31&_)+1,_>>>=5,u-=5,a.ncode=(15&_)+4,_>>>=4,u-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=ft;break}a.have=0,a.mode=$;case $:for(;a.haveu;){if(0===l)break t;l--,_+=n[s++]<>>=3,u-=3}for(;a.have<19;)a.lens[At[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,zt={bits:a.lenbits},yt=k(x,a.lens,0,19,a.lencode,0,a.work,zt),a.lenbits=zt.bits,yt){t.msg="invalid code lengths set",a.mode=ft;break}a.have=0,a.mode=tt;case tt:for(;a.have>>24,mt=St>>>16&255,wt=65535&St,!(u>=gt);){if(0===l)break t;l--,_+=n[s++]<wt)_>>>=gt,u-=gt,a.lens[a.have++]=wt;else{if(16===wt){for(Bt=gt+2;Bt>u;){if(0===l)break t;l--,_+=n[s++]<>>=gt,u-=gt,0===a.have){t.msg="invalid bit length repeat",a.mode=ft;break}xt=a.lens[a.have-1],g=3+(3&_),_>>>=2,u-=2}else if(17===wt){for(Bt=gt+3;Bt>u;){if(0===l)break t;l--,_+=n[s++]<>>=gt,u-=gt,xt=0,g=3+(7&_),_>>>=3,u-=3}else{for(Bt=gt+7;Bt>u;){if(0===l)break t;l--,_+=n[s++]<>>=gt,u-=gt,xt=0,g=11+(127&_),_>>>=7,u-=7}if(a.have+g>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=ft;break}for(;g--;)a.lens[a.have++]=xt}}if(a.mode===ft)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",
3 | a.mode=ft;break}if(a.lenbits=9,zt={bits:a.lenbits},yt=k(y,a.lens,0,a.nlen,a.lencode,0,a.work,zt),a.lenbits=zt.bits,yt){t.msg="invalid literal/lengths set",a.mode=ft;break}if(a.distbits=6,a.distcode=a.distdyn,zt={bits:a.distbits},yt=k(z,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,zt),a.distbits=zt.bits,yt){t.msg="invalid distances set",a.mode=ft;break}if(a.mode=et,e===E)break t;case et:a.mode=at;case at:if(l>=6&&h>=258){t.next_out=o,t.avail_out=h,t.next_in=s,t.avail_in=l,a.hold=_,a.bits=u,v(t,b),o=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,l=t.avail_in,_=a.hold,u=a.bits,a.mode===G&&(a.back=-1);break}for(a.back=0;St=a.lencode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(u>=gt);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(u>=pt+gt);){if(0===l)break t;l--,_+=n[s++]<>>=pt,u-=pt,a.back+=pt}if(_>>>=gt,u-=gt,a.back+=gt,a.length=wt,0===mt){a.mode=ot;break}if(32&mt){a.back=-1,a.mode=G;break}if(64&mt){t.msg="invalid literal/length code",a.mode=ft;break}a.extra=15&mt,a.mode=it;case it:if(a.extra){for(Bt=a.extra;Bt>u;){if(0===l)break t;l--,_+=n[s++]<>>=a.extra,u-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=nt;case nt:for(;St=a.distcode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(u>=gt);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(u>=pt+gt);){if(0===l)break t;l--,_+=n[s++]<>>=pt,u-=pt,a.back+=pt}if(_>>>=gt,u-=gt,a.back+=gt,64&mt){t.msg="invalid distance code",a.mode=ft;break}a.offset=wt,a.extra=15&mt,a.mode=rt;case rt:if(a.extra){for(Bt=a.extra;Bt>u;){if(0===l)break t;l--,_+=n[s++]<>>=a.extra,u-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=ft;break}a.mode=st;case st:if(0===h)break t;if(g=b-h,a.offset>g){if(g=a.offset-g,g>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=ft;break}g>a.wnext?(g-=a.wnext,ct=a.wsize-g):ct=a.wnext-g,g>a.length&&(g=a.length),bt=a.window}else bt=r,ct=o-a.offset,g=a.length;g>h&&(g=h),h-=g,a.length-=g;do r[o++]=bt[ct++];while(--g);0===a.length&&(a.mode=at);break;case ot:if(0===h)break t;r[o++]=a.length,h--,a.mode=at;break;case lt:if(a.wrap){for(;32>u;){if(0===l)break t;l--,_|=n[s++]<u;){if(0===l)break t;l--,_+=n[s++]<=Z;Z++)j[Z]=0;for(R=0;c>R;R++)j[e[a+R]]++;for(O=A,N=n;N>=1&&0===j[N];N--);if(O>N&&(O=N),0===N)return b[g++]=20971520,b[g++]=20971520,w.bits=1,0;for(C=1;N>C&&0===j[C];C++);for(C>O&&(O=C),F=1,Z=1;n>=Z;Z++)if(F<<=1,F-=j[Z],0>F)return-1;if(F>0&&(t===o||1!==N))return-1;for(K[1]=0,Z=1;n>Z;Z++)K[Z+1]=K[Z]+j[Z];for(R=0;c>R;R++)0!==e[a+R]&&(m[K[e[a+R]]++]=R);if(t===o?(L=M=m,z=19):t===l?(L=d,H-=257,M=f,P-=257,z=256):(L=_,M=u,z=-1),D=0,R=0,Z=C,y=g,I=O,U=0,k=-1,T=1<r||t===h&&T>s)return 1;for(var Y=0;;){Y++,B=Z-U,m[R]z?(S=M[P+m[R]],E=L[H+m[R]]):(S=96,E=0),p=1<>U)+v]=B<<24|S<<16|E|0;while(0!==v);for(p=1<>=1;if(0!==p?(D&=p-1,D+=p):D=0,R++,0===--j[Z]){if(Z===N)break;Z=e[a+m[R]]}if(Z>O&&(D&x)!==k){for(0===U&&(U=O),y+=C,I=Z-U,F=1<I+U&&(F-=j[I+U],!(0>=F));)I++,F<<=1;if(T+=1<r||t===h&&T>s)return 1;k=D&x,b[k]=O<<24|I<<16|y-g|0}}return 0!==D&&(b[y+D]=Z-U<<24|64<<16|0),w.bits=O,0}},{"../utils/common":3}],13:[function(t,e,a){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],14:[function(t,e,a){"use strict";function i(t){for(var e=t.length;--e>=0;)t[e]=0}function n(t){return 256>t?st[t]:st[256+(t>>>7)]}function r(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function s(t,e,a){t.bi_valid>G-a?(t.bi_buf|=e<>G-t.bi_valid,t.bi_valid+=a-G):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function h(t){16===t.bi_valid?(r(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function d(t,e){var a,i,n,r,s,o,l=e.dyn_tree,h=e.max_code,d=e.stat_desc.static_tree,f=e.stat_desc.has_stree,_=e.stat_desc.extra_bits,u=e.stat_desc.extra_base,c=e.stat_desc.max_length,b=0;for(r=0;q>=r;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;Y>a;a++)i=t.heap[a],r=l[2*l[2*i+1]+1]+1,r>c&&(r=c,b++),l[2*i+1]=r,i>h||(t.bl_count[r]++,s=0,i>=u&&(s=_[i-u]),o=l[2*i],t.opt_len+=o*(r+s),f&&(t.static_len+=o*(d[2*i+1]+s)));if(0!==b){do{for(r=c-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[c]--,b-=2}while(b>0);for(r=c;0!==r;r--)for(i=t.bl_count[r];0!==i;)n=t.heap[--a],n>h||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),i--)}}function f(t,e,a){var i,n,r=new Array(q+1),s=0;for(i=1;q>=i;i++)r[i]=s=s+a[i-1]<<1;for(n=0;e>=n;n++){var o=t[2*n+1];0!==o&&(t[2*n]=l(r[o]++,o))}}function _(){var t,e,a,i,n,r=new Array(q+1);for(a=0,i=0;H-1>i;i++)for(lt[i]=a,t=0;t<1<<$[i];t++)ot[a++]=i;for(ot[a-1]=i,n=0,i=0;16>i;i++)for(ht[i]=n,t=0;t<1<>=7;M>i;i++)for(ht[i]=n<<7,t=0;t<1<=e;e++)r[e]=0;for(t=0;143>=t;)nt[2*t+1]=8,t++,r[8]++;for(;255>=t;)nt[2*t+1]=9,t++,r[9]++;for(;279>=t;)nt[2*t+1]=7,t++,r[7]++;for(;287>=t;)nt[2*t+1]=8,t++,r[8]++;for(f(nt,K+1,r),t=0;M>t;t++)rt[2*t+1]=5,rt[2*t]=l(t,5);dt=new ut(nt,$,j+1,K,q),ft=new ut(rt,tt,0,M,q),_t=new ut(new Array(0),et,0,P,X)}function u(t){var e;for(e=0;K>e;e++)t.dyn_ltree[2*e]=0;for(e=0;M>e;e++)t.dyn_dtree[2*e]=0;for(e=0;P>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*W]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function c(t){t.bi_valid>8?r(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function b(t,e,a,i){c(t),i&&(r(t,a),r(t,~a)),R.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function g(t,e,a,i){var n=2*e,r=2*a;return t[n]a;a++)0!==r[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):r[2*a+1]=0;for(;t.heap_len<2;)n=t.heap[++t.heap_len]=2>h?++h:0,r[2*n]=1,t.depth[n]=0,t.opt_len--,o&&(t.static_len-=s[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;a>=1;a--)m(t,r,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],m(t,r,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,r[2*n]=r[2*a]+r[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,r[2*a+1]=r[2*i+1]=n,t.heap[1]=n++,m(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],d(t,e),f(r,h,t.bl_count)}function v(t,e,a){var i,n,r=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;a>=i;i++)n=s,s=e[2*(i+1)+1],++oo?t.bl_tree[2*n]+=o:0!==n?(n!==r&&t.bl_tree[2*n]++,t.bl_tree[2*J]++):10>=o?t.bl_tree[2*Q]++:t.bl_tree[2*V]++,o=0,r=n,0===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))}function k(t,e,a){var i,n,r=-1,l=e[1],h=0,d=7,f=4;for(0===l&&(d=138,f=3),i=0;a>=i;i++)if(n=l,l=e[2*(i+1)+1],!(++hh){do o(t,n,t.bl_tree);while(0!==--h)}else 0!==n?(n!==r&&(o(t,n,t.bl_tree),h--),o(t,J,t.bl_tree),s(t,h-3,2)):10>=h?(o(t,Q,t.bl_tree),s(t,h-3,3)):(o(t,V,t.bl_tree),s(t,h-11,7));h=0,r=n,0===l?(d=138,f=3):n===l?(d=6,f=3):(d=7,f=4)}}function x(t){var e;for(v(t,t.dyn_ltree,t.l_desc.max_code),v(t,t.dyn_dtree,t.d_desc.max_code),p(t,t.bl_desc),e=P-1;e>=3&&0===t.bl_tree[2*at[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function y(t,e,a,i){var n;for(s(t,e-257,5),s(t,a-1,5),s(t,i-4,4),n=0;i>n;n++)s(t,t.bl_tree[2*at[n]+1],3);k(t,t.dyn_ltree,e-1),k(t,t.dyn_dtree,a-1)}function z(t){var e,a=4093624447;for(e=0;31>=e;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return N;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return O;for(e=32;j>e;e++)if(0!==t.dyn_ltree[2*e])return O;return N}function B(t){bt||(_(),bt=!0),t.l_desc=new ct(t.dyn_ltree,dt),t.d_desc=new ct(t.dyn_dtree,ft),t.bl_desc=new ct(t.bl_tree,_t),t.bi_buf=0,t.bi_valid=0,u(t)}function S(t,e,a,i){s(t,(U<<1)+(i?1:0),3),b(t,e,a,!0)}function E(t){s(t,F<<1,3),o(t,W,nt),h(t)}function A(t,e,a,i){var n,r,o=0;t.level>0?(t.strm.data_type===I&&(t.strm.data_type=z(t)),p(t,t.l_desc),p(t,t.d_desc),o=x(t),n=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,n>=r&&(n=r)):n=r=a+5,n>=a+4&&-1!==e?S(t,e,a,i):t.strategy===C||r===n?(s(t,(F<<1)+(i?1:0),3),w(t,nt,rt)):(s(t,(T<<1)+(i?1:0),3),y(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),w(t,t.dyn_ltree,t.dyn_dtree)),u(t),i&&c(t)}function Z(t,e,a){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(ot[a]+j+1)]++,t.dyn_dtree[2*n(e)]++),t.last_lit===t.lit_bufsize-1}var R=t("../utils/common"),C=4,N=0,O=1,I=2,U=0,F=1,T=2,D=3,L=258,H=29,j=256,K=j+1+H,M=30,P=19,Y=2*K+1,q=15,G=16,X=7,W=256,J=16,Q=17,V=18,$=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],tt=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],et=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],at=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],it=512,nt=new Array(2*(K+2));i(nt);var rt=new Array(2*M);i(rt);var st=new Array(it);i(st);var ot=new Array(L-D+1);i(ot);var lt=new Array(H);i(lt);var ht=new Array(M);i(ht);var dt,ft,_t,ut=function(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length},ct=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},bt=!1;a._tr_init=B,a._tr_stored_block=S,a._tr_flush_block=A,a._tr_tally=Z,a._tr_align=E},{"../utils/common":3}],15:[function(t,e,a){"use strict";function i(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}e.exports=i},{}],"/":[function(t,e,a){"use strict";var i=t("./lib/utils/common").assign,n=t("./lib/deflate"),r=t("./lib/inflate"),s=t("./lib/zlib/constants"),o={};i(o,n,r,s),e.exports=o},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")});
4 |
--------------------------------------------------------------------------------