Skip to content

Commit

Permalink
Merge pull request #23 from TheCyberRonin/develop
Browse files Browse the repository at this point in the history
feat: Add support for translating layer flags
  • Loading branch information
TheCyberRonin authored Oct 9, 2023
2 parents c0d4216 + e5b6065 commit 45a2f2f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
40 changes: 39 additions & 1 deletion Aseprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ class Aseprite {
this.tilesets = [];
}

//#region Static Constants

/**
* Map of the possible flag values for a Layer
*/
static LAYER_FLAG_MAP = {
visible: 0b1,
editable: 0b10,
lockMovement: 0b100,
background: 0b1000,
preferLinkedCels: 0b10000,
collapsedGroup: 0b100000,
reference: 0b1000000
};

//#endregion Static Constants

/**
* Reads the next byte (8-bit unsigned) value in the buffer
*
Expand Down Expand Up @@ -212,6 +229,27 @@ class Aseprite {
this._offset += numBytes;
}

/**
* Translates the listed flags for a layer into true/false values
* dictating whether or not that flag is "on"(true) or "off"(false)
*
* @private
* @param {object} flagMap Object of flags and their binary value
* @param {number} flagValue Value of the layer flags
* @returns {object} Map of the flags and if they are true or false
*/
#translateFlags(flagValue) {
// Create an object to put the flags and their "toggle" (true/false)
const translatedFlagMap = {};
// Iterate through the flags and their binary value, use bitwise op
// to see if the flag is present in the "layer flags" and add the
// flag to the map with the accompanying "toggle"
for( const flag in Aseprite.LAYER_FLAG_MAP) {
translatedFlagMap[flag] = (flagValue & Aseprite.LAYER_FLAG_MAP[flag]) == Aseprite.LAYER_FLAG_MAP[flag];
}
return translatedFlagMap;
}

/**
* Reads the 128-byte header of an Aseprite file and stores the information
*
Expand Down Expand Up @@ -501,7 +539,7 @@ class Aseprite {
*/
readLayerChunk() {
const layer = {}
layer.flags = this.readNextWord();
layer.flags = this.#translateFlags(this.readNextWord());
layer.type = this.readNextWord();
layer.layerChildLevel = this.readNextWord();
this.skipBytes(4);
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![npm](https://img.shields.io/npm/v/ase-parser.svg)](https://www.npmjs.com/package/ase-parser)
[![npm](https://img.shields.io/npm/dt/ase-parser.svg?maxAge=3600)](https://www.npmjs.com/package/ase-parser)
[![install size](https://packagephobia.now.sh/badge?p=ase-parser)](https://packagephobia.now.sh/result?p=ase-parser)

# ase-parser
Parse Aseprite files with Node.js, no external dependencies.

Expand Down Expand Up @@ -151,7 +155,7 @@ aseFile.parse();
## Layer Object
| Field | Type | Description |
|-----------------|---------|-------------------------------|
| flags | integer | flags for the layer |
| flags | [layer flags](#layer-flags-object) | flags for the layer translated into a map |
| type | integer | type |
| layerChildLevel | integer | layer child level |
| opacity | integer | opacity (0-255) |
Expand Down Expand Up @@ -267,6 +271,19 @@ aseFile.parse();
| x | integer | X position of the pivot |
| y | integer | Y position of the pivot |

## Layer Flags Object

This object is a utility object that will have ***ALL*** fields present. If a field is "on" it will be `true`, if the field is "off" it will be `false`.

| Field | Description |
|-------|---------|
| visible | Whether or not the layer is visible |
| editable | Whether or not the layer is editable |
| lockMovement | Whether or not the layer is a background layer |
| preferLinkedCels | Whether or not the layer prefers linked cels |
| collapsedGroup | Whether or not the layer group should be displayed collapsed |
| reference | Whether or not the layer is a reference layer |

# Further Info

If you would like to read up on the Aseprite file spec: [Spec](https://github.com/aseprite/aseprite/blob/master/docs/ase-file-specs.md)
17 changes: 17 additions & 0 deletions docs/gitflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Gitflow

We'll be using the gitflow organization for the repo. I'll describe a TLDR version, but provide links to documents that explain it in further detail.

### Organization

The branches listed below will be used for the project.

* `master` - Contains "production ready" code. i.e. The code that gets pushed to NPM.
* `develop` - Contains code that's currently in progress. This is the branch that should be targeted for PRs.
* `feature/*` - Contains a `feature`. This should be the current work for a single feature/addition to the codebase. It should have a sensible name. Let's say I want to comment all of the code, the feature branch name would be something like `feature/comment-js-files`.
* `release` - This is branched from `develop` when a release is ready and holds the code for a release. It will be used to test to make sure there are no bugs before it gets pushed to `master`.
* `hotfix` - If there is a bug in `master`, a hotfix branch is created with the fix to be merged DIRECTLY into master and then will be merged back into `develop` so that the fix is present in future code.

### Resources
* [GitKraken](https://www.gitkraken.com/learn/git/git-flow)
* [Atlassian](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)
23 changes: 0 additions & 23 deletions main.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ase-parser",
"version": "0.0.17",
"version": "0.0.18",
"description": "Parser for Aseprite files",
"main": "Aseprite.js",
"typings": "./typings/Aseprite.d.ts",
Expand Down
13 changes: 11 additions & 2 deletions typings/Aseprite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ declare namespace Aseprite {
color: string;
}
export interface Layer {
flags: number;
flags: Aseprite.LayerFlags;
type: number;
layerChildLevel: number;
blendMode: number;
Expand Down Expand Up @@ -125,4 +125,13 @@ declare namespace Aseprite {
fGamma: number;
icc?: Buffer;
}
}
export interface LayerFlags {
visible: boolean;
editable: boolean;
lockMovement: boolean;
background: boolean;
preferLinkedCels: boolean;
collapsedGroup: boolean;
reference: boolean;
}
}

0 comments on commit 45a2f2f

Please sign in to comment.