├── .editorconfig ├── .gitignore ├── .npmignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── dist └── h5-texture-unpacker.js ├── example ├── aliens-array.json ├── aliens-array.png ├── aliens-hash.json ├── aliens-hash.png ├── aliens-xml.png └── aliens-xml.xml ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── AtlasType.ts ├── IMatrix.ts ├── extractors │ ├── JsonArray.ts │ ├── JsonHash.ts │ ├── Xml.ts │ └── index.ts └── h5-texture-unpacker.ts ├── tools └── gh-pages-publish.js ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | #root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | max_line_length = 100 10 | indent_size = 4 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | .DS_Store 5 | *.log 6 | .vscode 7 | .idea 8 | compiled 9 | .awcache 10 | .rpt2_cache 11 | docs 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .tscache 3 | asset_source 4 | assets/ 5 | !build/assets 6 | example 7 | src 8 | test 9 | tools 10 | vendor 11 | config/* 12 | rollup.config.js 13 | tslint.json 14 | tsconfig.json 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | ## [0.1.1] - 2021-09-23 3 | ### Fixed 4 | - Security update for XMLDOM 5 | 6 | 7 | ## [0.1.0] - 2021-03-10 8 | ### Added 9 | - Split JSON support between JsonHash and JsonArray 10 | - XML support for 11 | 12 | ## [0.0.2] - 2019-11-04 13 | ### Added 14 | - Winston logging with a verbose check 15 | - check to see if img exists 16 | - Can now read img file from json config 17 | 18 | ### Fixed 19 | - error reporting image size equals zero is nog caught 20 | - cleaned up dist folder 21 | 22 | ## [0.0.1] - 2019-11-01 23 | ### Added 24 | - Initial setup and release 25 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | a.bles@azerion.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 123 | 124 | For answers to common questions about this code of conduct, see the FAQ at 125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available 126 | at [https://www.contributor-covenant.org/translations][translations]. 127 | 128 | [homepage]: https://www.contributor-covenant.org 129 | [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 130 | [Mozilla CoC]: https://github.com/mozilla/diversity 131 | [FAQ]: https://www.contributor-covenant.org/faq 132 | [translations]: https://www.contributor-covenant.org/translations 133 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md). 2 | 3 | ## Reporting issues 4 | 5 | [GitHub Issues][0] is the place to report bugs you may have found. When submitting a bug please do the following: 6 | 7 | **1. Search for existing issues.** Your bug may have already been fixed, or cannot, or will not, be fixed. So be sure to search the issues first before putting in a duplicate issue. 8 | 9 | **2. Not sure if it's a bug?.** Please ask on the Phaser's slack or discord servers, @AleBles is usually there. 10 | 11 | **3. Create an isolated and reproducible test case.** If you are reporting a bug, make sure you also have a minimal, runnable, code example that reproduces the problem you have. 12 | 13 | **4. Include a live example.** After narrowing your code down to only the problem areas please provide some basic code that show it, or a link to your live site so that we can view a live example of the problem. 14 | 15 | **5. Share as much information as possible.** Include browser version affected, your OS, version of the library, steps to reproduce, etc. "X isn't working!!!!!" will probably just be closed. 16 | 17 | ## Making Changes 18 | 19 | To take advantage of our grunt build script and tslint config it will be easiest for you if you have node.js and grunt installed locally. 20 | 21 | You can download node.js from [nodejs.org][3]. After it has been installed open a console and run `npm i -g grunt-cli` to install the global `grunt` executable. 22 | 23 | After that you can clone the repository and run `npm i` inside the cloned folder. This will install dependencies necessary for building the project. Once that is ready, make your changes and submit a Pull Request: 24 | 25 | - **Send Pull Requests to the `dev` branch.** This'll make it much easier for to keep a clear track between development and releases. 26 | 27 | - **Ensure changes are tslint validated.** Our TSlint configuration file is provided in the repository and you should check against it before submitting. 28 | 29 | - **Never commit new builds.** When making a code change you should always run `grunt dist` which will rebuild the project so you can test, *however* please do not commit these new builds or your PR will be closed. Builds by default are placed in the `build` folder. 30 | 31 | - **Only commit relevant changes.** Don't include changes that are not directly relevant to the fix you are making. The more focused a PR is, the faster it will get attention and be merged. Extra files changing only whitespace or trash files will likely get your PR closed. 32 | 33 | 34 | ## Coding style preferences are not contributions 35 | 36 | If your PR is doing little more than changing the source code into a format / coding style that you prefer then we will automatically close it. All PRs must adhere to the coding style already set-out across the code. Your personal preferences for how things should "look" or be structured do not apply here, sorry. PRs should fix bugs, fix documentation or add features. No changes for the sake of change. 37 | 38 | 39 | ## I don't really like git / node.js, but I can fix this bug 40 | 41 | That is fine too. While Pull Requests are the best thing in the world for us, they are not the only way to help. You're welcome to post fixes to our forum or even just email them to us. All we ask is that you still adhere to the guidelines presented here re: TSlint, etc. 42 | 43 | 44 | ## Code Style Guide 45 | 46 | - Use 4 spaces for tabs, never tab characters. 47 | 48 | - No trailing whitespace, blank lines should have no whitespace. 49 | 50 | - Always favor strict equals `===` unless you *need* to use type coercion. 51 | 52 | - Follow conventions already in the code, and listen to tslint. Our config is set-up for a reason. 53 | 54 | [3]: http://nodejs.org 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Azerion 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/%40azerion%2Fh5-texture-unpacker.svg)](https://badge.fury.io/js/%40azerion%2Fh5-texture-unpacker) 2 | 3 | # h5-texture-unpacker 4 | Simple CLI tool that allows you to unpack your existing Texture atlasses provided that you have the JSON file available 5 | 6 | Getting Started 7 | --------------- 8 | First you want to install a fresh copy of the plugin. 9 | ``` 10 | ale@computer:~$ npm install @azerion/h5-texture-unpacker -g 11 | ``` 12 | Now you'll be able to use the command: 13 | ``` 14 | ale@computer:~$ unpack 15 | Usage: unpack -i [imageFile] -a [atlasFile] -o [outputDir] 16 | ``` 17 | 18 | Usage 19 | ----- 20 | ``` 21 | ale@computer:~$ unpack 22 | Usage: unpack -j [jsonFile] -o [outputDir] 23 | 24 | Options: 25 | --version Show version number [boolean] 26 | --atlasFile, -i The input texture image [string] [required] 27 | --jsonFile, -j The input JSON configuration [string] [required] 28 | --outputDir, -o The output folder [string] [required] 29 | --verbose, -v Show log messages [boolean] [default: false] 30 | -h, --help Show help [boolean] 31 | 32 | copyright Azerion 2021 33 | ``` 34 | 35 | TODO 36 | ---- 37 | - [ ] Add support for XML 38 | - [ ] Format validation 39 | - [ ] parse/process trimmed/rotation from json 40 | 41 | F.A.Q. 42 | ------ 43 | ### My atlas format [json/xml/csv] is not supported! 44 | We'd love to include more format as we go, but for now will only add the ones we need, if there's anything you'd like to add or suggest feel free to add a ticker or create a Pull Request 45 | 46 | Credits 47 | ======= 48 | Created with https://github.com/alexjoverm/typescript-library-starter.git 49 | Example assets by [Kenney](https://www.kenney.nl) 50 | 51 | Disclaimer 52 | ---------- 53 | We at Azerion just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed to unpack some awesome texture for our awesome HTML5 games. Feel free to use it for enhancing your own awesome games! 54 | h5-texture-unpacker is distributed under the MIT license. All 3rd party libraries and components are distributed under their 55 | respective license terms. 56 | 57 | -------------------------------------------------------------------------------- /dist/h5-texture-unpacker.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var e=require("xpath"),r=require("@xmldom/xmldom").DOMParser;var t=require("sharp"),a=require("path"),n=require("fs"),i=require("yargs"),o=require("winston"),s=(new Date).toISOString(),f=o.format.printf((function(e){return s+"-"+e.level+": "+JSON.stringify(e.message,null,4)+"\n"})),l=o.createLogger({transports:[new o.transports.Console({format:o.format.combine(o.format.colorize(),f)})]});a.join(__dirname,"../");var m,u,p,h=i.usage("Usage: $0 -j [jsonFile] -o [outputDir]").option("imageFile",{alias:"i",demandOption:!0,default:"",describe:"The input texture image",type:"string"}).option("atlasFile",{alias:"a",demandOption:!0,describe:"The input atlas",type:"string"}).option("outputDir",{alias:"o",demandOption:!0,describe:"The output folder",type:"string"}).option("verbose",{alias:"v",default:!1,describe:"Show log messages",type:"boolean"}).help("h").alias("h","help").epilog("copyright Azerion 2021").argv,c=a.join(h.i),g=a.join(h.a),d=a.join(h.o,"/"),y=n.readFileSync(g),w=[];l.level=!0===h.verbose?"info":"warn",n.existsSync(c)||(l.error("Could not find image at specified path!"),process.exit(1)),n.existsSync(d)||n.mkdirSync(d),g.match(/\.json$/)?(m=y,u=JSON.parse(m.toString()),p=[],u.hasOwnProperty("frames")&&Array.isArray(u.frames)&&u.frames.forEach((function(e){p.push({name:e.filename,w:e.frame.w,h:e.frame.h,x:e.frame.x,y:e.frame.y})})),null===(w=p)&&(w=function(e){var r=JSON.parse(e.toString()),t=[];return r.hasOwnProperty("frames")&&!Array.isArray(r.frames)&&Object.keys(r.frames).forEach((function(e){var a=r.frames[e];t.push({name:e,w:a.frame.w,h:a.frame.h,x:a.frame.x,y:a.frame.y})})),t}(y)),null===w&&(l.error("Could not get Hash nor Array data from json file: "+g),process.exit(1))):g.match(/\.xml$/)?w=function(t){var a=(new r).parseFromString(t.toString()),n=e.select("//SubTexture",a),i=[];return n.length>0&&n.forEach((function(e){i.push({name:e.getAttribute("name"),w:parseInt(e.getAttribute("width")),h:parseInt(e.getAttribute("height")),x:parseInt(e.getAttribute("x")),y:parseInt(e.getAttribute("y"))})})),i}(y):(l.error("Unknown file format: "+g),process.exit(1));var x=0;0===w.length&&(l.error("No data found: "+g),process.exit(1)),w.forEach((function(e){0!==e.w&&0!==e.h?t(c).extract({width:e.w,height:e.h,left:e.x,top:e.y}).toFile(a.join(d,"/",e.name+".png")).then((function(r){l.info("File: "+e.name+" written"),x++})).catch((function(r){l.info("Unable to write file , "+e.name+":, "+r)})):l.warn("Unable to write file , "+e.name+": Source width/height is 0")})),console.log("Done writing "+x+" images to "+d); 4 | -------------------------------------------------------------------------------- /example/aliens-array.json: -------------------------------------------------------------------------------- 1 | {"frames": [ 2 | 3 | { 4 | "filename": "alienBeige.png", 5 | "frame": {"x":70,"y":215,"w":66,"h":92}, 6 | "rotated": false, 7 | "trimmed": false, 8 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 9 | "sourceSize": {"w":66,"h":92} 10 | }, 11 | { 12 | "filename": "alienBeige_badge1.png", 13 | "frame": {"x":329,"y":0,"w":47,"h":47}, 14 | "rotated": false, 15 | "trimmed": false, 16 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 17 | "sourceSize": {"w":47,"h":47} 18 | }, 19 | { 20 | "filename": "alienBeige_badge2.png", 21 | "frame": {"x":376,"y":0,"w":47,"h":47}, 22 | "rotated": false, 23 | "trimmed": false, 24 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 25 | "sourceSize": {"w":47,"h":47} 26 | }, 27 | { 28 | "filename": "alienBeige_climb1.png", 29 | "frame": {"x":135,"y":587,"w":66,"h":95}, 30 | "rotated": false, 31 | "trimmed": false, 32 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":95}, 33 | "sourceSize": {"w":66,"h":95} 34 | }, 35 | { 36 | "filename": "alienBeige_climb2.png", 37 | "frame": {"x":0,"y":587,"w":66,"h":95}, 38 | "rotated": false, 39 | "trimmed": false, 40 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":95}, 41 | "sourceSize": {"w":66,"h":95} 42 | }, 43 | { 44 | "filename": "alienBeige_duck.png", 45 | "frame": {"x":273,"y":47,"w":67,"h":72}, 46 | "rotated": false, 47 | "trimmed": false, 48 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":72}, 49 | "sourceSize": {"w":67,"h":72} 50 | }, 51 | { 52 | "filename": "alienBeige_hurt.png", 53 | "frame": {"x":132,"y":399,"w":67,"h":92}, 54 | "rotated": false, 55 | "trimmed": false, 56 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":92}, 57 | "sourceSize": {"w":67,"h":92} 58 | }, 59 | { 60 | "filename": "alienBeige_jump.png", 61 | "frame": {"x":331,"y":399,"w":66,"h":93}, 62 | "rotated": false, 63 | "trimmed": false, 64 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 65 | "sourceSize": {"w":66,"h":93} 66 | }, 67 | { 68 | "filename": "alienBeige_stand.png", 69 | "frame": {"x":265,"y":399,"w":66,"h":92}, 70 | "rotated": false, 71 | "trimmed": false, 72 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 73 | "sourceSize": {"w":66,"h":92} 74 | }, 75 | { 76 | "filename": "alienBeige_swim1.png", 77 | "frame": {"x":280,"y":683,"w":69,"h":98}, 78 | "rotated": false, 79 | "trimmed": false, 80 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":98}, 81 | "sourceSize": {"w":69,"h":98} 82 | }, 83 | { 84 | "filename": "alienBeige_swim2.png", 85 | "frame": {"x":349,"y":683,"w":70,"h":100}, 86 | "rotated": false, 87 | "trimmed": false, 88 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":100}, 89 | "sourceSize": {"w":70,"h":100} 90 | }, 91 | { 92 | "filename": "alienBeige_walk1.png", 93 | "frame": {"x":397,"y":399,"w":68,"h":93}, 94 | "rotated": false, 95 | "trimmed": false, 96 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 97 | "sourceSize": {"w":68,"h":93} 98 | }, 99 | { 100 | "filename": "alienBeige_walk2.png", 101 | "frame": {"x":0,"y":683,"w":70,"h":96}, 102 | "rotated": false, 103 | "trimmed": false, 104 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 105 | "sourceSize": {"w":70,"h":96} 106 | }, 107 | { 108 | "filename": "alienBlue.png", 109 | "frame": {"x":135,"y":307,"w":66,"h":92}, 110 | "rotated": false, 111 | "trimmed": false, 112 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 113 | "sourceSize": {"w":66,"h":92} 114 | }, 115 | { 116 | "filename": "alienBlue_badge1.png", 117 | "frame": {"x":94,"y":0,"w":47,"h":47}, 118 | "rotated": false, 119 | "trimmed": false, 120 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 121 | "sourceSize": {"w":47,"h":47} 122 | }, 123 | { 124 | "filename": "alienBlue_badge2.png", 125 | "frame": {"x":141,"y":0,"w":47,"h":47}, 126 | "rotated": false, 127 | "trimmed": false, 128 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 129 | "sourceSize": {"w":47,"h":47} 130 | }, 131 | { 132 | "filename": "alienBlue_climb1.png", 133 | "frame": {"x":268,"y":307,"w":66,"h":92}, 134 | "rotated": false, 135 | "trimmed": false, 136 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 137 | "sourceSize": {"w":66,"h":92} 138 | }, 139 | { 140 | "filename": "alienBlue_climb2.png", 141 | "frame": {"x":400,"y":307,"w":66,"h":92}, 142 | "rotated": false, 143 | "trimmed": false, 144 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 145 | "sourceSize": {"w":66,"h":92} 146 | }, 147 | { 148 | "filename": "alienBlue_duck.png", 149 | "frame": {"x":206,"y":47,"w":67,"h":72}, 150 | "rotated": false, 151 | "trimmed": false, 152 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":72}, 153 | "sourceSize": {"w":67,"h":72} 154 | }, 155 | { 156 | "filename": "alienBlue_hurt.png", 157 | "frame": {"x":201,"y":307,"w":67,"h":92}, 158 | "rotated": false, 159 | "trimmed": false, 160 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":92}, 161 | "sourceSize": {"w":67,"h":92} 162 | }, 163 | { 164 | "filename": "alienBlue_jump.png", 165 | "frame": {"x":336,"y":492,"w":66,"h":93}, 166 | "rotated": false, 167 | "trimmed": false, 168 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 169 | "sourceSize": {"w":66,"h":93} 170 | }, 171 | { 172 | "filename": "alienBlue_stand.png", 173 | "frame": {"x":334,"y":307,"w":66,"h":92}, 174 | "rotated": false, 175 | "trimmed": false, 176 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 177 | "sourceSize": {"w":66,"h":92} 178 | }, 179 | { 180 | "filename": "alienBlue_swim1.png", 181 | "frame": {"x":66,"y":587,"w":69,"h":95}, 182 | "rotated": false, 183 | "trimmed": false, 184 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 185 | "sourceSize": {"w":69,"h":95} 186 | }, 187 | { 188 | "filename": "alienBlue_swim2.png", 189 | "frame": {"x":140,"y":683,"w":70,"h":97}, 190 | "rotated": false, 191 | "trimmed": false, 192 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 193 | "sourceSize": {"w":70,"h":97} 194 | }, 195 | { 196 | "filename": "alienBlue_walk1.png", 197 | "frame": {"x":203,"y":492,"w":66,"h":93}, 198 | "rotated": false, 199 | "trimmed": false, 200 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 201 | "sourceSize": {"w":66,"h":93} 202 | }, 203 | { 204 | "filename": "alienBlue_walk2.png", 205 | "frame": {"x":340,"y":587,"w":67,"h":96}, 206 | "rotated": false, 207 | "trimmed": false, 208 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":96}, 209 | "sourceSize": {"w":67,"h":96} 210 | }, 211 | { 212 | "filename": "alienGreen.png", 213 | "frame": {"x":0,"y":399,"w":66,"h":92}, 214 | "rotated": false, 215 | "trimmed": false, 216 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 217 | "sourceSize": {"w":66,"h":92} 218 | }, 219 | { 220 | "filename": "alienGreen_badge1.png", 221 | "frame": {"x":282,"y":0,"w":47,"h":47}, 222 | "rotated": false, 223 | "trimmed": false, 224 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 225 | "sourceSize": {"w":47,"h":47} 226 | }, 227 | { 228 | "filename": "alienGreen_badge2.png", 229 | "frame": {"x":423,"y":0,"w":47,"h":47}, 230 | "rotated": false, 231 | "trimmed": false, 232 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 233 | "sourceSize": {"w":47,"h":47} 234 | }, 235 | { 236 | "filename": "alienGreen_climb1.png", 237 | "frame": {"x":199,"y":399,"w":66,"h":92}, 238 | "rotated": false, 239 | "trimmed": false, 240 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 241 | "sourceSize": {"w":66,"h":92} 242 | }, 243 | { 244 | "filename": "alienGreen_climb2.png", 245 | "frame": {"x":66,"y":399,"w":66,"h":92}, 246 | "rotated": false, 247 | "trimmed": false, 248 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 249 | "sourceSize": {"w":66,"h":92} 250 | }, 251 | { 252 | "filename": "alienGreen_duck.png", 253 | "frame": {"x":137,"y":47,"w":69,"h":71}, 254 | "rotated": false, 255 | "trimmed": false, 256 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":71}, 257 | "sourceSize": {"w":69,"h":71} 258 | }, 259 | { 260 | "filename": "alienGreen_hurt.png", 261 | "frame": {"x":66,"y":307,"w":69,"h":92}, 262 | "rotated": false, 263 | "trimmed": false, 264 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":92}, 265 | "sourceSize": {"w":69,"h":92} 266 | }, 267 | { 268 | "filename": "alienGreen_jump.png", 269 | "frame": {"x":68,"y":492,"w":67,"h":93}, 270 | "rotated": false, 271 | "trimmed": false, 272 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":93}, 273 | "sourceSize": {"w":67,"h":93} 274 | }, 275 | { 276 | "filename": "alienGreen_stand.png", 277 | "frame": {"x":202,"y":215,"w":66,"h":92}, 278 | "rotated": false, 279 | "trimmed": false, 280 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 281 | "sourceSize": {"w":66,"h":92} 282 | }, 283 | { 284 | "filename": "alienGreen_swim1.png", 285 | "frame": {"x":402,"y":492,"w":69,"h":95}, 286 | "rotated": false, 287 | "trimmed": false, 288 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 289 | "sourceSize": {"w":69,"h":95} 290 | }, 291 | { 292 | "filename": "alienGreen_swim2.png", 293 | "frame": {"x":210,"y":683,"w":70,"h":97}, 294 | "rotated": false, 295 | "trimmed": false, 296 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 297 | "sourceSize": {"w":70,"h":97} 298 | }, 299 | { 300 | "filename": "alienGreen_walk1.png", 301 | "frame": {"x":135,"y":492,"w":68,"h":93}, 302 | "rotated": false, 303 | "trimmed": false, 304 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 305 | "sourceSize": {"w":68,"h":93} 306 | }, 307 | { 308 | "filename": "alienGreen_walk2.png", 309 | "frame": {"x":407,"y":587,"w":70,"h":96}, 310 | "rotated": false, 311 | "trimmed": false, 312 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 313 | "sourceSize": {"w":70,"h":96} 314 | }, 315 | { 316 | "filename": "alienPink.png", 317 | "frame": {"x":0,"y":307,"w":66,"h":92}, 318 | "rotated": false, 319 | "trimmed": false, 320 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 321 | "sourceSize": {"w":66,"h":92} 322 | }, 323 | { 324 | "filename": "alienPink_badge1.png", 325 | "frame": {"x":0,"y":0,"w":47,"h":47}, 326 | "rotated": false, 327 | "trimmed": false, 328 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 329 | "sourceSize": {"w":47,"h":47} 330 | }, 331 | { 332 | "filename": "alienPink_badge2.png", 333 | "frame": {"x":188,"y":0,"w":47,"h":47}, 334 | "rotated": false, 335 | "trimmed": false, 336 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 337 | "sourceSize": {"w":47,"h":47} 338 | }, 339 | { 340 | "filename": "alienPink_climb1.png", 341 | "frame": {"x":136,"y":215,"w":66,"h":92}, 342 | "rotated": false, 343 | "trimmed": false, 344 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 345 | "sourceSize": {"w":66,"h":92} 346 | }, 347 | { 348 | "filename": "alienPink_climb2.png", 349 | "frame": {"x":403,"y":215,"w":66,"h":92}, 350 | "rotated": false, 351 | "trimmed": false, 352 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 353 | "sourceSize": {"w":66,"h":92} 354 | }, 355 | { 356 | "filename": "alienPink_duck.png", 357 | "frame": {"x":68,"y":47,"w":69,"h":71}, 358 | "rotated": false, 359 | "trimmed": false, 360 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":71}, 361 | "sourceSize": {"w":69,"h":71} 362 | }, 363 | { 364 | "filename": "alienPink_hurt.png", 365 | "frame": {"x":268,"y":215,"w":69,"h":92}, 366 | "rotated": false, 367 | "trimmed": false, 368 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":92}, 369 | "sourceSize": {"w":69,"h":92} 370 | }, 371 | { 372 | "filename": "alienPink_jump.png", 373 | "frame": {"x":269,"y":492,"w":67,"h":93}, 374 | "rotated": false, 375 | "trimmed": false, 376 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":93}, 377 | "sourceSize": {"w":67,"h":93} 378 | }, 379 | { 380 | "filename": "alienPink_stand.png", 381 | "frame": {"x":337,"y":215,"w":66,"h":92}, 382 | "rotated": false, 383 | "trimmed": false, 384 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 385 | "sourceSize": {"w":66,"h":92} 386 | }, 387 | { 388 | "filename": "alienPink_swim1.png", 389 | "frame": {"x":201,"y":587,"w":69,"h":95}, 390 | "rotated": false, 391 | "trimmed": false, 392 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 393 | "sourceSize": {"w":69,"h":95} 394 | }, 395 | { 396 | "filename": "alienPink_swim2.png", 397 | "frame": {"x":70,"y":683,"w":70,"h":97}, 398 | "rotated": false, 399 | "trimmed": false, 400 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 401 | "sourceSize": {"w":70,"h":97} 402 | }, 403 | { 404 | "filename": "alienPink_walk1.png", 405 | "frame": {"x":0,"y":492,"w":68,"h":93}, 406 | "rotated": false, 407 | "trimmed": false, 408 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 409 | "sourceSize": {"w":68,"h":93} 410 | }, 411 | { 412 | "filename": "alienPink_walk2.png", 413 | "frame": {"x":270,"y":587,"w":70,"h":96}, 414 | "rotated": false, 415 | "trimmed": false, 416 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 417 | "sourceSize": {"w":70,"h":96} 418 | }, 419 | { 420 | "filename": "alienYellow.png", 421 | "frame": {"x":132,"y":129,"w":66,"h":82}, 422 | "rotated": false, 423 | "trimmed": false, 424 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 425 | "sourceSize": {"w":66,"h":82} 426 | }, 427 | { 428 | "filename": "alienYellow_badge1.png", 429 | "frame": {"x":235,"y":0,"w":47,"h":47}, 430 | "rotated": false, 431 | "trimmed": false, 432 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 433 | "sourceSize": {"w":47,"h":47} 434 | }, 435 | { 436 | "filename": "alienYellow_badge2.png", 437 | "frame": {"x":47,"y":0,"w":47,"h":47}, 438 | "rotated": false, 439 | "trimmed": false, 440 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 441 | "sourceSize": {"w":47,"h":47} 442 | }, 443 | { 444 | "filename": "alienYellow_climb1.png", 445 | "frame": {"x":0,"y":129,"w":66,"h":82}, 446 | "rotated": false, 447 | "trimmed": false, 448 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 449 | "sourceSize": {"w":66,"h":82} 450 | }, 451 | { 452 | "filename": "alienYellow_climb2.png", 453 | "frame": {"x":66,"y":129,"w":66,"h":82}, 454 | "rotated": false, 455 | "trimmed": false, 456 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 457 | "sourceSize": {"w":66,"h":82} 458 | }, 459 | { 460 | "filename": "alienYellow_duck.png", 461 | "frame": {"x":0,"y":47,"w":68,"h":67}, 462 | "rotated": false, 463 | "trimmed": false, 464 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":67}, 465 | "sourceSize": {"w":68,"h":67} 466 | }, 467 | { 468 | "filename": "alienYellow_hurt.png", 469 | "frame": {"x":340,"y":47,"w":69,"h":81}, 470 | "rotated": false, 471 | "trimmed": false, 472 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":81}, 473 | "sourceSize": {"w":69,"h":81} 474 | }, 475 | { 476 | "filename": "alienYellow_jump.png", 477 | "frame": {"x":198,"y":129,"w":67,"h":83}, 478 | "rotated": false, 479 | "trimmed": false, 480 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":83}, 481 | "sourceSize": {"w":67,"h":83} 482 | }, 483 | { 484 | "filename": "alienYellow_stand.png", 485 | "frame": {"x":409,"y":47,"w":66,"h":82}, 486 | "rotated": false, 487 | "trimmed": false, 488 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 489 | "sourceSize": {"w":66,"h":82} 490 | }, 491 | { 492 | "filename": "alienYellow_swim1.png", 493 | "frame": {"x":333,"y":129,"w":69,"h":85}, 494 | "rotated": false, 495 | "trimmed": false, 496 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":85}, 497 | "sourceSize": {"w":69,"h":85} 498 | }, 499 | { 500 | "filename": "alienYellow_swim2.png", 501 | "frame": {"x":0,"y":215,"w":70,"h":87}, 502 | "rotated": false, 503 | "trimmed": false, 504 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":87}, 505 | "sourceSize": {"w":70,"h":87} 506 | }, 507 | { 508 | "filename": "alienYellow_walk1.png", 509 | "frame": {"x":265,"y":129,"w":68,"h":83}, 510 | "rotated": false, 511 | "trimmed": false, 512 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":83}, 513 | "sourceSize": {"w":68,"h":83} 514 | }, 515 | { 516 | "filename": "alienYellow_walk2.png", 517 | "frame": {"x":402,"y":129,"w":70,"h":86}, 518 | "rotated": false, 519 | "trimmed": false, 520 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":86}, 521 | "sourceSize": {"w":70,"h":86} 522 | }], 523 | "meta": { 524 | "app": "https://www.codeandweb.com/texturepacker", 525 | "version": "1.0", 526 | "image": "aliens-array.png", 527 | "format": "RGBA8888", 528 | "size": {"w":477,"h":783}, 529 | "scale": "1", 530 | "smartupdate": "$TexturePacker:SmartUpdate:1310adfc649039bb10a4becf56a7e6b9:4702ace1eba87cd9b883223aec5af3b2:217108129ce1f7b6ae644925cb707afe$" 531 | } 532 | } 533 | -------------------------------------------------------------------------------- /example/aliens-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/azerion/h5-texture-unpacker/4ab146c3f013bdae6313c861f4a7615aff9491e7/example/aliens-array.png -------------------------------------------------------------------------------- /example/aliens-hash.json: -------------------------------------------------------------------------------- 1 | {"frames": { 2 | 3 | "alienBeige.png": 4 | { 5 | "frame": {"x":70,"y":215,"w":66,"h":92}, 6 | "rotated": false, 7 | "trimmed": false, 8 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 9 | "sourceSize": {"w":66,"h":92} 10 | }, 11 | "alienBeige_badge1.png": 12 | { 13 | "frame": {"x":329,"y":0,"w":47,"h":47}, 14 | "rotated": false, 15 | "trimmed": false, 16 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 17 | "sourceSize": {"w":47,"h":47} 18 | }, 19 | "alienBeige_badge2.png": 20 | { 21 | "frame": {"x":376,"y":0,"w":47,"h":47}, 22 | "rotated": false, 23 | "trimmed": false, 24 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 25 | "sourceSize": {"w":47,"h":47} 26 | }, 27 | "alienBeige_climb1.png": 28 | { 29 | "frame": {"x":135,"y":587,"w":66,"h":95}, 30 | "rotated": false, 31 | "trimmed": false, 32 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":95}, 33 | "sourceSize": {"w":66,"h":95} 34 | }, 35 | "alienBeige_climb2.png": 36 | { 37 | "frame": {"x":0,"y":587,"w":66,"h":95}, 38 | "rotated": false, 39 | "trimmed": false, 40 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":95}, 41 | "sourceSize": {"w":66,"h":95} 42 | }, 43 | "alienBeige_duck.png": 44 | { 45 | "frame": {"x":273,"y":47,"w":67,"h":72}, 46 | "rotated": false, 47 | "trimmed": false, 48 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":72}, 49 | "sourceSize": {"w":67,"h":72} 50 | }, 51 | "alienBeige_hurt.png": 52 | { 53 | "frame": {"x":132,"y":399,"w":67,"h":92}, 54 | "rotated": false, 55 | "trimmed": false, 56 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":92}, 57 | "sourceSize": {"w":67,"h":92} 58 | }, 59 | "alienBeige_jump.png": 60 | { 61 | "frame": {"x":331,"y":399,"w":66,"h":93}, 62 | "rotated": false, 63 | "trimmed": false, 64 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 65 | "sourceSize": {"w":66,"h":93} 66 | }, 67 | "alienBeige_stand.png": 68 | { 69 | "frame": {"x":265,"y":399,"w":66,"h":92}, 70 | "rotated": false, 71 | "trimmed": false, 72 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 73 | "sourceSize": {"w":66,"h":92} 74 | }, 75 | "alienBeige_swim1.png": 76 | { 77 | "frame": {"x":280,"y":683,"w":69,"h":98}, 78 | "rotated": false, 79 | "trimmed": false, 80 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":98}, 81 | "sourceSize": {"w":69,"h":98} 82 | }, 83 | "alienBeige_swim2.png": 84 | { 85 | "frame": {"x":349,"y":683,"w":70,"h":100}, 86 | "rotated": false, 87 | "trimmed": false, 88 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":100}, 89 | "sourceSize": {"w":70,"h":100} 90 | }, 91 | "alienBeige_walk1.png": 92 | { 93 | "frame": {"x":397,"y":399,"w":68,"h":93}, 94 | "rotated": false, 95 | "trimmed": false, 96 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 97 | "sourceSize": {"w":68,"h":93} 98 | }, 99 | "alienBeige_walk2.png": 100 | { 101 | "frame": {"x":0,"y":683,"w":70,"h":96}, 102 | "rotated": false, 103 | "trimmed": false, 104 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 105 | "sourceSize": {"w":70,"h":96} 106 | }, 107 | "alienBlue.png": 108 | { 109 | "frame": {"x":135,"y":307,"w":66,"h":92}, 110 | "rotated": false, 111 | "trimmed": false, 112 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 113 | "sourceSize": {"w":66,"h":92} 114 | }, 115 | "alienBlue_badge1.png": 116 | { 117 | "frame": {"x":94,"y":0,"w":47,"h":47}, 118 | "rotated": false, 119 | "trimmed": false, 120 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 121 | "sourceSize": {"w":47,"h":47} 122 | }, 123 | "alienBlue_badge2.png": 124 | { 125 | "frame": {"x":141,"y":0,"w":47,"h":47}, 126 | "rotated": false, 127 | "trimmed": false, 128 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 129 | "sourceSize": {"w":47,"h":47} 130 | }, 131 | "alienBlue_climb1.png": 132 | { 133 | "frame": {"x":268,"y":307,"w":66,"h":92}, 134 | "rotated": false, 135 | "trimmed": false, 136 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 137 | "sourceSize": {"w":66,"h":92} 138 | }, 139 | "alienBlue_climb2.png": 140 | { 141 | "frame": {"x":400,"y":307,"w":66,"h":92}, 142 | "rotated": false, 143 | "trimmed": false, 144 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 145 | "sourceSize": {"w":66,"h":92} 146 | }, 147 | "alienBlue_duck.png": 148 | { 149 | "frame": {"x":206,"y":47,"w":67,"h":72}, 150 | "rotated": false, 151 | "trimmed": false, 152 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":72}, 153 | "sourceSize": {"w":67,"h":72} 154 | }, 155 | "alienBlue_hurt.png": 156 | { 157 | "frame": {"x":201,"y":307,"w":67,"h":92}, 158 | "rotated": false, 159 | "trimmed": false, 160 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":92}, 161 | "sourceSize": {"w":67,"h":92} 162 | }, 163 | "alienBlue_jump.png": 164 | { 165 | "frame": {"x":336,"y":492,"w":66,"h":93}, 166 | "rotated": false, 167 | "trimmed": false, 168 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 169 | "sourceSize": {"w":66,"h":93} 170 | }, 171 | "alienBlue_stand.png": 172 | { 173 | "frame": {"x":334,"y":307,"w":66,"h":92}, 174 | "rotated": false, 175 | "trimmed": false, 176 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 177 | "sourceSize": {"w":66,"h":92} 178 | }, 179 | "alienBlue_swim1.png": 180 | { 181 | "frame": {"x":66,"y":587,"w":69,"h":95}, 182 | "rotated": false, 183 | "trimmed": false, 184 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 185 | "sourceSize": {"w":69,"h":95} 186 | }, 187 | "alienBlue_swim2.png": 188 | { 189 | "frame": {"x":140,"y":683,"w":70,"h":97}, 190 | "rotated": false, 191 | "trimmed": false, 192 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 193 | "sourceSize": {"w":70,"h":97} 194 | }, 195 | "alienBlue_walk1.png": 196 | { 197 | "frame": {"x":203,"y":492,"w":66,"h":93}, 198 | "rotated": false, 199 | "trimmed": false, 200 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":93}, 201 | "sourceSize": {"w":66,"h":93} 202 | }, 203 | "alienBlue_walk2.png": 204 | { 205 | "frame": {"x":340,"y":587,"w":67,"h":96}, 206 | "rotated": false, 207 | "trimmed": false, 208 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":96}, 209 | "sourceSize": {"w":67,"h":96} 210 | }, 211 | "alienGreen.png": 212 | { 213 | "frame": {"x":0,"y":399,"w":66,"h":92}, 214 | "rotated": false, 215 | "trimmed": false, 216 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 217 | "sourceSize": {"w":66,"h":92} 218 | }, 219 | "alienGreen_badge1.png": 220 | { 221 | "frame": {"x":282,"y":0,"w":47,"h":47}, 222 | "rotated": false, 223 | "trimmed": false, 224 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 225 | "sourceSize": {"w":47,"h":47} 226 | }, 227 | "alienGreen_badge2.png": 228 | { 229 | "frame": {"x":423,"y":0,"w":47,"h":47}, 230 | "rotated": false, 231 | "trimmed": false, 232 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 233 | "sourceSize": {"w":47,"h":47} 234 | }, 235 | "alienGreen_climb1.png": 236 | { 237 | "frame": {"x":199,"y":399,"w":66,"h":92}, 238 | "rotated": false, 239 | "trimmed": false, 240 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 241 | "sourceSize": {"w":66,"h":92} 242 | }, 243 | "alienGreen_climb2.png": 244 | { 245 | "frame": {"x":66,"y":399,"w":66,"h":92}, 246 | "rotated": false, 247 | "trimmed": false, 248 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 249 | "sourceSize": {"w":66,"h":92} 250 | }, 251 | "alienGreen_duck.png": 252 | { 253 | "frame": {"x":137,"y":47,"w":69,"h":71}, 254 | "rotated": false, 255 | "trimmed": false, 256 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":71}, 257 | "sourceSize": {"w":69,"h":71} 258 | }, 259 | "alienGreen_hurt.png": 260 | { 261 | "frame": {"x":66,"y":307,"w":69,"h":92}, 262 | "rotated": false, 263 | "trimmed": false, 264 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":92}, 265 | "sourceSize": {"w":69,"h":92} 266 | }, 267 | "alienGreen_jump.png": 268 | { 269 | "frame": {"x":68,"y":492,"w":67,"h":93}, 270 | "rotated": false, 271 | "trimmed": false, 272 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":93}, 273 | "sourceSize": {"w":67,"h":93} 274 | }, 275 | "alienGreen_stand.png": 276 | { 277 | "frame": {"x":202,"y":215,"w":66,"h":92}, 278 | "rotated": false, 279 | "trimmed": false, 280 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 281 | "sourceSize": {"w":66,"h":92} 282 | }, 283 | "alienGreen_swim1.png": 284 | { 285 | "frame": {"x":402,"y":492,"w":69,"h":95}, 286 | "rotated": false, 287 | "trimmed": false, 288 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 289 | "sourceSize": {"w":69,"h":95} 290 | }, 291 | "alienGreen_swim2.png": 292 | { 293 | "frame": {"x":210,"y":683,"w":70,"h":97}, 294 | "rotated": false, 295 | "trimmed": false, 296 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 297 | "sourceSize": {"w":70,"h":97} 298 | }, 299 | "alienGreen_walk1.png": 300 | { 301 | "frame": {"x":135,"y":492,"w":68,"h":93}, 302 | "rotated": false, 303 | "trimmed": false, 304 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 305 | "sourceSize": {"w":68,"h":93} 306 | }, 307 | "alienGreen_walk2.png": 308 | { 309 | "frame": {"x":407,"y":587,"w":70,"h":96}, 310 | "rotated": false, 311 | "trimmed": false, 312 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 313 | "sourceSize": {"w":70,"h":96} 314 | }, 315 | "alienPink.png": 316 | { 317 | "frame": {"x":0,"y":307,"w":66,"h":92}, 318 | "rotated": false, 319 | "trimmed": false, 320 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 321 | "sourceSize": {"w":66,"h":92} 322 | }, 323 | "alienPink_badge1.png": 324 | { 325 | "frame": {"x":0,"y":0,"w":47,"h":47}, 326 | "rotated": false, 327 | "trimmed": false, 328 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 329 | "sourceSize": {"w":47,"h":47} 330 | }, 331 | "alienPink_badge2.png": 332 | { 333 | "frame": {"x":188,"y":0,"w":47,"h":47}, 334 | "rotated": false, 335 | "trimmed": false, 336 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 337 | "sourceSize": {"w":47,"h":47} 338 | }, 339 | "alienPink_climb1.png": 340 | { 341 | "frame": {"x":136,"y":215,"w":66,"h":92}, 342 | "rotated": false, 343 | "trimmed": false, 344 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 345 | "sourceSize": {"w":66,"h":92} 346 | }, 347 | "alienPink_climb2.png": 348 | { 349 | "frame": {"x":403,"y":215,"w":66,"h":92}, 350 | "rotated": false, 351 | "trimmed": false, 352 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 353 | "sourceSize": {"w":66,"h":92} 354 | }, 355 | "alienPink_duck.png": 356 | { 357 | "frame": {"x":68,"y":47,"w":69,"h":71}, 358 | "rotated": false, 359 | "trimmed": false, 360 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":71}, 361 | "sourceSize": {"w":69,"h":71} 362 | }, 363 | "alienPink_hurt.png": 364 | { 365 | "frame": {"x":268,"y":215,"w":69,"h":92}, 366 | "rotated": false, 367 | "trimmed": false, 368 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":92}, 369 | "sourceSize": {"w":69,"h":92} 370 | }, 371 | "alienPink_jump.png": 372 | { 373 | "frame": {"x":269,"y":492,"w":67,"h":93}, 374 | "rotated": false, 375 | "trimmed": false, 376 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":93}, 377 | "sourceSize": {"w":67,"h":93} 378 | }, 379 | "alienPink_stand.png": 380 | { 381 | "frame": {"x":337,"y":215,"w":66,"h":92}, 382 | "rotated": false, 383 | "trimmed": false, 384 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":92}, 385 | "sourceSize": {"w":66,"h":92} 386 | }, 387 | "alienPink_swim1.png": 388 | { 389 | "frame": {"x":201,"y":587,"w":69,"h":95}, 390 | "rotated": false, 391 | "trimmed": false, 392 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":95}, 393 | "sourceSize": {"w":69,"h":95} 394 | }, 395 | "alienPink_swim2.png": 396 | { 397 | "frame": {"x":70,"y":683,"w":70,"h":97}, 398 | "rotated": false, 399 | "trimmed": false, 400 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":97}, 401 | "sourceSize": {"w":70,"h":97} 402 | }, 403 | "alienPink_walk1.png": 404 | { 405 | "frame": {"x":0,"y":492,"w":68,"h":93}, 406 | "rotated": false, 407 | "trimmed": false, 408 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":93}, 409 | "sourceSize": {"w":68,"h":93} 410 | }, 411 | "alienPink_walk2.png": 412 | { 413 | "frame": {"x":270,"y":587,"w":70,"h":96}, 414 | "rotated": false, 415 | "trimmed": false, 416 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":96}, 417 | "sourceSize": {"w":70,"h":96} 418 | }, 419 | "alienYellow.png": 420 | { 421 | "frame": {"x":132,"y":129,"w":66,"h":82}, 422 | "rotated": false, 423 | "trimmed": false, 424 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 425 | "sourceSize": {"w":66,"h":82} 426 | }, 427 | "alienYellow_badge1.png": 428 | { 429 | "frame": {"x":235,"y":0,"w":47,"h":47}, 430 | "rotated": false, 431 | "trimmed": false, 432 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 433 | "sourceSize": {"w":47,"h":47} 434 | }, 435 | "alienYellow_badge2.png": 436 | { 437 | "frame": {"x":47,"y":0,"w":47,"h":47}, 438 | "rotated": false, 439 | "trimmed": false, 440 | "spriteSourceSize": {"x":0,"y":0,"w":47,"h":47}, 441 | "sourceSize": {"w":47,"h":47} 442 | }, 443 | "alienYellow_climb1.png": 444 | { 445 | "frame": {"x":0,"y":129,"w":66,"h":82}, 446 | "rotated": false, 447 | "trimmed": false, 448 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 449 | "sourceSize": {"w":66,"h":82} 450 | }, 451 | "alienYellow_climb2.png": 452 | { 453 | "frame": {"x":66,"y":129,"w":66,"h":82}, 454 | "rotated": false, 455 | "trimmed": false, 456 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 457 | "sourceSize": {"w":66,"h":82} 458 | }, 459 | "alienYellow_duck.png": 460 | { 461 | "frame": {"x":0,"y":47,"w":68,"h":67}, 462 | "rotated": false, 463 | "trimmed": false, 464 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":67}, 465 | "sourceSize": {"w":68,"h":67} 466 | }, 467 | "alienYellow_hurt.png": 468 | { 469 | "frame": {"x":340,"y":47,"w":69,"h":81}, 470 | "rotated": false, 471 | "trimmed": false, 472 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":81}, 473 | "sourceSize": {"w":69,"h":81} 474 | }, 475 | "alienYellow_jump.png": 476 | { 477 | "frame": {"x":198,"y":129,"w":67,"h":83}, 478 | "rotated": false, 479 | "trimmed": false, 480 | "spriteSourceSize": {"x":0,"y":0,"w":67,"h":83}, 481 | "sourceSize": {"w":67,"h":83} 482 | }, 483 | "alienYellow_stand.png": 484 | { 485 | "frame": {"x":409,"y":47,"w":66,"h":82}, 486 | "rotated": false, 487 | "trimmed": false, 488 | "spriteSourceSize": {"x":0,"y":0,"w":66,"h":82}, 489 | "sourceSize": {"w":66,"h":82} 490 | }, 491 | "alienYellow_swim1.png": 492 | { 493 | "frame": {"x":333,"y":129,"w":69,"h":85}, 494 | "rotated": false, 495 | "trimmed": false, 496 | "spriteSourceSize": {"x":0,"y":0,"w":69,"h":85}, 497 | "sourceSize": {"w":69,"h":85} 498 | }, 499 | "alienYellow_swim2.png": 500 | { 501 | "frame": {"x":0,"y":215,"w":70,"h":87}, 502 | "rotated": false, 503 | "trimmed": false, 504 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":87}, 505 | "sourceSize": {"w":70,"h":87} 506 | }, 507 | "alienYellow_walk1.png": 508 | { 509 | "frame": {"x":265,"y":129,"w":68,"h":83}, 510 | "rotated": false, 511 | "trimmed": false, 512 | "spriteSourceSize": {"x":0,"y":0,"w":68,"h":83}, 513 | "sourceSize": {"w":68,"h":83} 514 | }, 515 | "alienYellow_walk2.png": 516 | { 517 | "frame": {"x":402,"y":129,"w":70,"h":86}, 518 | "rotated": false, 519 | "trimmed": false, 520 | "spriteSourceSize": {"x":0,"y":0,"w":70,"h":86}, 521 | "sourceSize": {"w":70,"h":86} 522 | }}, 523 | "meta": { 524 | "app": "https://www.codeandweb.com/texturepacker", 525 | "version": "1.0", 526 | "image": "aliens-json.png", 527 | "format": "RGBA8888", 528 | "size": {"w":477,"h":783}, 529 | "scale": "1", 530 | "smartupdate": "$TexturePacker:SmartUpdate:dc45bc7bce280b3c8745b1091075e87f:4702ace1eba87cd9b883223aec5af3b2:bf2e8a81c4f3e347743f1175528f28cb$" 531 | } 532 | } 533 | -------------------------------------------------------------------------------- /example/aliens-hash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/azerion/h5-texture-unpacker/4ab146c3f013bdae6313c861f4a7615aff9491e7/example/aliens-hash.png -------------------------------------------------------------------------------- /example/aliens-xml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/azerion/h5-texture-unpacker/4ab146c3f013bdae6313c861f4a7615aff9491e7/example/aliens-xml.png -------------------------------------------------------------------------------- /example/aliens-xml.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@azerion/h5-texture-unpacker", 3 | "author": "Azerion", 4 | "version": "0.1.1", 5 | "description": "Simple CLI tool that allows you to unpack your existing Texture atlasses provided that you have the JSON file available", 6 | "contributors": [ 7 | { 8 | "name": "Ale Bles", 9 | "email": "a.bles@azerion.com" 10 | } 11 | ], 12 | "main": "dist/h5-texture-unpacker.js", 13 | "bin": { 14 | "unpack": "dist/h5-texture-unpacker.js" 15 | }, 16 | "files": [ 17 | "dist" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+ssh://git@gitlab.azerdev.com:fabrique/tools/h5-texture-unpacker.git" 22 | }, 23 | "license": "MIT", 24 | "engines": { 25 | "node": ">=12.0.0" 26 | }, 27 | "scripts": { 28 | "prebuild": "rimraf dist", 29 | "build": "rollup -c rollup.config.js", 30 | "typedoc": "typedoc --out docs --theme minimal ./src", 31 | "start": "rollup -c rollup.config.js -w", 32 | "test:prod": "npm run lint && npm run test -- --no-cache", 33 | "deploy-docs": "ts-node tools/gh-pages-publish", 34 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 35 | "commit": "git-cz", 36 | "precommit": "lint-staged" 37 | }, 38 | "lint-staged": { 39 | "{src,test}/**/*.ts": [ 40 | "prettier --write", 41 | "git add" 42 | ] 43 | }, 44 | "config": { 45 | "name": "h5-texture-unpacker" 46 | }, 47 | "prettier": { 48 | "semi": false, 49 | "singleQuote": true 50 | }, 51 | "commitlint": { 52 | "extends": [ 53 | "@commitlint/config-conventional" 54 | ] 55 | }, 56 | "devDependencies": { 57 | "@commitlint/cli": "^12.1.4", 58 | "@commitlint/config-conventional": "^7.6.0", 59 | "@types/node": "^10.17.60", 60 | "@types/sharp": "^0.23.1", 61 | "@types/xml2js": "^0.4.9", 62 | "@types/xmldom": "^0.1.31", 63 | "@types/yargs": "^13.0.12", 64 | "colors": "^1.4.0", 65 | "commitizen": "^4.2.4", 66 | "coveralls": "^3.1.1", 67 | "cross-env": "^5.2.1", 68 | "cz-conventional-changelog": "^2.1.0", 69 | "husky": "^1.0.1", 70 | "lint-staged": "^11.1.2", 71 | "lodash.camelcase": "^4.3.0", 72 | "prettier": "^1.19.1", 73 | "prompt": "^1.2.0", 74 | "replace-in-file": "^3.4.4", 75 | "rimraf": "^2.7.1", 76 | "rollup": "^2.57.0", 77 | "rollup-plugin-add-shebang": "^0.3.1", 78 | "rollup-plugin-commonjs": "^9.3.4", 79 | "rollup-plugin-node-resolve": "^3.4.0", 80 | "rollup-plugin-preserve-shebangs": "^0.1.2", 81 | "rollup-plugin-serve": "^1.1.0", 82 | "rollup-plugin-terser": "^5.1.2", 83 | "rollup-plugin-typescript2": "^0.30.0", 84 | "shelljs": "^0.8.3", 85 | "typedoc": "^0.22.4", 86 | "typescript": "^4.4.3" 87 | }, 88 | "dependencies": { 89 | "@xmldom/xmldom": "^0.7.5", 90 | "sharp": "^0.27.2", 91 | "winston": "^3.3.3", 92 | "xpath": "0.0.32", 93 | "yargs": "^16.2.0" 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve'; 2 | import commonjs from 'rollup-plugin-commonjs'; 3 | import typescript from 'rollup-plugin-typescript2'; 4 | import serve from 'rollup-plugin-serve'; 5 | import { terser } from 'rollup-plugin-terser' 6 | import shebang from 'rollup-plugin-add-shebang'; 7 | 8 | 9 | const pkg = require('./package.json'); 10 | 11 | const libraryName = 'h5-texture-unpacker'; 12 | 13 | const isWatching = process.argv.findIndex((element) => element === '-w') !== -1; 14 | 15 | let basePlugins = []; 16 | if (isWatching) { 17 | basePlugins.push( 18 | serve({ 19 | contentBase: ['./', './example'], 20 | port: 8080 21 | }) 22 | ); 23 | } 24 | export default { 25 | input: `src/${libraryName}.ts`, 26 | output: [ 27 | {file: pkg.main, format: 'es', sourcemap: false} 28 | ], 29 | // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') 30 | external: [], 31 | watch: { 32 | include: 'src/**', 33 | }, 34 | plugins: basePlugins.concat([ 35 | // Compile TypeScript files 36 | typescript({useTsconfigDeclarationDir: false, objectHashIgnoreUnknownHack: true}), 37 | // Allow node_modules resolution, so you can use 'external' to control 38 | // which external modules to include in the bundle 39 | // https://github.com/rollup/rollup-plugin-node-resolve#usage 40 | resolve(), 41 | // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) 42 | commonjs(), 43 | terser({ 44 | include: [/^.+\.js$/], 45 | }), 46 | shebang({ 47 | include: `dist/${libraryName}.js` 48 | }) 49 | ]) 50 | }; 51 | -------------------------------------------------------------------------------- /src/AtlasType.ts: -------------------------------------------------------------------------------- 1 | export enum AssetType { 2 | JsonHash, 3 | JsonArray, 4 | Xml 5 | } 6 | -------------------------------------------------------------------------------- /src/IMatrix.ts: -------------------------------------------------------------------------------- 1 | export declare interface IImageMatrix { 2 | name: string 3 | x: number 4 | y: number 5 | w: number 6 | h: number 7 | } 8 | -------------------------------------------------------------------------------- /src/extractors/JsonArray.ts: -------------------------------------------------------------------------------- 1 | import { IImageMatrix } from '../IMatrix' 2 | 3 | export function JsonArray(data: Buffer): IImageMatrix[] { 4 | const atlasData: any = JSON.parse(data.toString()) 5 | const imageResult: IImageMatrix[] = [] 6 | 7 | if (atlasData.hasOwnProperty('frames') && Array.isArray(atlasData.frames)) { 8 | atlasData.frames.forEach((imageData: any) => { 9 | imageResult.push({ 10 | name: imageData.filename, 11 | w: imageData.frame.w, 12 | h: imageData.frame.h, 13 | x: imageData.frame.x, 14 | y: imageData.frame.y 15 | }) 16 | }) 17 | } 18 | return imageResult 19 | } 20 | -------------------------------------------------------------------------------- /src/extractors/JsonHash.ts: -------------------------------------------------------------------------------- 1 | import { IImageMatrix } from '../IMatrix' 2 | 3 | export function JsonHash(data: Buffer): IImageMatrix[] { 4 | const atlasData: any = JSON.parse(data.toString()) 5 | const imageResult: IImageMatrix[] = [] 6 | 7 | if (atlasData.hasOwnProperty('frames') && !Array.isArray(atlasData.frames)) { 8 | const keys = Object.keys(atlasData.frames) 9 | 10 | keys.forEach((filename: string) => { 11 | let imageData: any = atlasData.frames[filename] 12 | imageResult.push({ 13 | name: filename, 14 | w: imageData.frame.w, 15 | h: imageData.frame.h, 16 | x: imageData.frame.x, 17 | y: imageData.frame.y 18 | }) 19 | }) 20 | } 21 | return imageResult 22 | } 23 | -------------------------------------------------------------------------------- /src/extractors/Xml.ts: -------------------------------------------------------------------------------- 1 | import { IImageMatrix } from '../IMatrix' 2 | 3 | const xpath = require('xpath'), 4 | dom = require('@xmldom/xmldom').DOMParser 5 | 6 | export function Xml(data: Buffer): IImageMatrix[] { 7 | const doc = new dom().parseFromString(data.toString()) 8 | const nodes = xpath.select('//SubTexture', doc) 9 | const imageResult: IImageMatrix[] = [] 10 | 11 | if (nodes.length > 0) { 12 | nodes.forEach((node: any) => { 13 | imageResult.push({ 14 | name: node.getAttribute('name'), 15 | w: parseInt(node.getAttribute('width')), 16 | h: parseInt(node.getAttribute('height')), 17 | x: parseInt(node.getAttribute('x')), 18 | y: parseInt(node.getAttribute('y')) 19 | }) 20 | }) 21 | } 22 | 23 | return imageResult 24 | } 25 | -------------------------------------------------------------------------------- /src/extractors/index.ts: -------------------------------------------------------------------------------- 1 | export { JsonArray } from './JsonArray' 2 | export { JsonHash } from './JsonHash' 3 | export { Xml } from './Xml' 4 | -------------------------------------------------------------------------------- /src/h5-texture-unpacker.ts: -------------------------------------------------------------------------------- 1 | import { OutputInfo } from 'sharp' 2 | import { AssetType } from './AtlasType' 3 | import { IImageMatrix } from './IMatrix' 4 | import { JsonArray, JsonHash, Xml } from './extractors' 5 | 6 | const Sharp = require('sharp') 7 | const path = require('path') 8 | const fs = require('fs') 9 | const yargs = require('yargs') 10 | const winston = require('winston') 11 | 12 | let date = new Date().toISOString() 13 | const logFormat = winston.format.printf(function(info: any) { 14 | return `${date}-${info.level}: ${JSON.stringify(info.message, null, 4)}\n` 15 | }) 16 | const logger = winston.createLogger({ 17 | transports: [ 18 | new winston.transports.Console({ 19 | format: winston.format.combine(winston.format.colorize(), logFormat) 20 | }) 21 | ] 22 | }) 23 | const basePath = path.join(__dirname, '../') 24 | 25 | const argv = yargs 26 | .usage('Usage: $0 -j [jsonFile] -o [outputDir]') 27 | .option('imageFile', { 28 | alias: 'i', 29 | demandOption: true, 30 | default: '', 31 | describe: 'The input texture image', 32 | type: 'string' 33 | }) 34 | .option('atlasFile', { 35 | alias: 'a', 36 | demandOption: true, 37 | describe: 'The input atlas', 38 | type: 'string' 39 | }) 40 | .option('outputDir', { 41 | alias: 'o', 42 | demandOption: true, 43 | describe: 'The output folder', 44 | type: 'string' 45 | }) 46 | .option('verbose', { 47 | alias: 'v', 48 | default: false, 49 | describe: 'Show log messages', 50 | type: 'boolean' 51 | }) 52 | .help('h') 53 | .alias('h', 'help') 54 | .epilog('copyright Azerion 2021').argv 55 | 56 | let imgPath: string = path.join(argv.i) 57 | const atlasPath: string = path.join(argv.a) 58 | const outputDir: string = path.join(argv.o, '/') 59 | const rawData: Buffer = fs.readFileSync(atlasPath) 60 | let imageMatrixData: IImageMatrix[] = [] 61 | 62 | logger.level = argv.verbose === true ? 'info' : 'warn' 63 | 64 | if (!fs.existsSync(imgPath)) { 65 | //Let's check if the image file is found 66 | logger.error('Could not find image at specified path!') 67 | process.exit(1) 68 | } 69 | 70 | if (!fs.existsSync(outputDir)) { 71 | fs.mkdirSync(outputDir) 72 | } 73 | 74 | if (atlasPath.match(/\.json$/)) { 75 | //It's a json file! 76 | imageMatrixData = JsonArray(rawData) 77 | 78 | if (null === imageMatrixData) { 79 | imageMatrixData = JsonHash(rawData) 80 | } 81 | 82 | if (null === imageMatrixData) { 83 | logger.error(`Could not get Hash nor Array data from json file: ${atlasPath}`) 84 | process.exit(1) 85 | } 86 | } else if (atlasPath.match(/\.xml$/)) { 87 | //It's an xml file! 88 | imageMatrixData = Xml(rawData) 89 | } else { 90 | logger.error(`Unknown file format: ${atlasPath}`) 91 | process.exit(1) 92 | } 93 | 94 | let count: number = 0 95 | 96 | if (imageMatrixData.length === 0) { 97 | logger.error(`No data found: ${atlasPath}`) 98 | process.exit(1) 99 | } 100 | 101 | imageMatrixData.forEach((source: IImageMatrix) => { 102 | if (source.w === 0 || source.h === 0) { 103 | logger.warn(`Unable to write file , ${source.name}: Source width/height is 0`) 104 | return 105 | } 106 | 107 | Sharp(imgPath) 108 | .extract({ 109 | width: source.w, 110 | height: source.h, 111 | left: source.x, 112 | top: source.y 113 | }) 114 | .toFile(path.join(outputDir, '/', source.name + '.png')) 115 | .then((fileInfo: OutputInfo) => { 116 | logger.info(`File: ${source.name} written`) 117 | count++ 118 | }) 119 | .catch((err: any) => { 120 | logger.info(`Unable to write file , ${source.name}:, ${err}`) 121 | }) 122 | }) 123 | 124 | console.log(`Done writing ${count} images to ${outputDir}`) 125 | -------------------------------------------------------------------------------- /tools/gh-pages-publish.js: -------------------------------------------------------------------------------- 1 | const {cd, exec, echo, touch} = require('shelljs'); 2 | const {readFileSync} = require('fs'); 3 | const url = require('url'); 4 | 5 | let repoUrl; 6 | let pkg = JSON.parse(readFileSync('package.json')); 7 | if (typeof pkg.repository === 'object') { 8 | if (!pkg.repository.hasOwnProperty('url')) { 9 | throw new Error('URL does not exist in repository section'); 10 | } 11 | repoUrl = pkg.repository.url; 12 | } else { 13 | repoUrl = pkg.repository; 14 | } 15 | 16 | echo('Deploying docs!!!'); 17 | cd('docs'); 18 | touch('.nojekyll'); 19 | exec('git init'); 20 | exec('git add .'); 21 | exec('git commit -m "docs(docs): update gh-pages"'); 22 | 23 | console.log(repoUrl); 24 | 25 | exec( 26 | `git push --force --quiet "${repoUrl}" master:gh-pages` 27 | ); 28 | echo('Docs deployed!!'); 29 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "target": "es5", 5 | "module": "es2015", 6 | "lib": [ 7 | "es2015", 8 | "es2016", 9 | "es2017", 10 | "dom" 11 | ], 12 | "allowJs": true, 13 | "strict": true, 14 | "sourceMap": false, 15 | "declaration": false, 16 | "allowSyntheticDefaultImports": true, 17 | "experimentalDecorators": true, 18 | "emitDecoratorMetadata": true, 19 | "esModuleInterop": true, 20 | "outDir": "dist/lib", 21 | "typeRoots": [ 22 | "node_modules/@types" 23 | ] 24 | }, 25 | "include": [ 26 | "src" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint-config-standard", 4 | "tslint-config-prettier" 5 | ] 6 | } --------------------------------------------------------------------------------