Act Parser
Library for parsing and writing Act files in NodeJS.
Getting started
Prerequisites
- Install Node.js which includes Node Package Manager
Installation
Install act-parser directly from NPM
npm install @csnvrag/act-parser
Or from Github
npm install https://github.com/csnv/act-parser.git
API Reference
-
-
fromFile(filepath)
static async function
-
fromBuffer(buffer)
static function
-
toFile(filepath)
async function
-
toBuffer()
function
-
header
string
-
version
number
-
events
array
-
actions
array
-
intervals
array
-
fromFile(filepath)
-
-
frames :
array
-
frames :
-
-
getEvent() :
function
-
setEvent(eventName) :
function
-
range1 :
array
-
range2 :
array
-
eventId :
number
-
layers :
array
-
anchorPoints :
array
-
getEvent() :
class
ActFile ActFile is the top level class of this library. Along with the file information, actions, frames, events, etc can be accesed through this class.
static async function
fromFile(filepath) Reads file specified in filepath
and returns an ActFile instance. This is the most straightforward method for reading act files.
Example:
import { ActFile } from "@csnvrag/act-parser";
const monsterFile = await ActFile.fromFile('./monster.act');
static function
fromBuffer(buffer) Parses a Buffer
with the contents of an .act file into an ActFile instance. In contrast to fromFile
, this method does not read files directly.
Example:
import { ActFile } from "@csnvrag/act-parser";
import { readFile } from "fs/promises";
const fileBuffer = await readFile('./monster.act');
const monsterFile = ActFile.fromBuffer(fileBuffer);
async function
toFile(filepath) Writes current act file into a file, specified in filepath.
Example:
await monsterFile.toFile('./monster-copy.act');
function
toBuffer() Writes current act file into a buffer and returns the buffer for further processing. Example:
const buffer = monsterFile.toBuffer();
await writeFile('./monster-copy.act', buffer);
string
header Header information of the file. Must be AC
.
number
version Version of the file. Currently, this library supports from 0x200
to 0x205
.
Note: Act-parser saves files in version 0x205
.
array
events Dynamic list of events. Each event is a string of max 40 characters.
array
actions Dynamic list of Actions.
array
intervals Dynamic list of intervals, equal to the number of actions (one interval per action). Time in milliseconds after a certain action.
class
Action Action represents each direction in a sequence of frames.
array
frames Dynamic list of Frames
class
Frame Frame object in a sequence of frames. Tightly linked with sprites.
function
getEvent() Returns the name of the current frame event. Undefined
if none associated.
function
setEvent(eventName) Assigns the label in eventName
to the frame. If such label does not exist in ActFile.events
, it's added automatically.
array
range1
array
range2
array
layers Dynamic array of Layers
number
eventId 0-based index of the assigned event of frame in ActFile.events
. -1
if no event is assigned.
array
anchorPoints Dynamic array of AnchorPoints
class
Layer Layer representation of a sprite's bitmap.
number
x Horizontal position in frame.
number
y Vertical position in frame.
number
sprId ID of sprite bitmap used in layer.
number
flags Bitflags of layer. Currently, only used for mirroring the layer on the y-axis.
array
color Tint of the layer in RGBA form: [0, 0, 0, 0] to [255, 255, 255, 255]
number
xScale Scale factor for width
number
yScale Scale factor for height
number
rotation Rotation of the layer around its center, in angle degrees.
number
sprType The type of the sprite used from SPR. 0 == Palette sprite, 1 == RGBA sprite.
number
width Width of the layer.
number
height Height of the layer.
class
AnchorPoint Anchor points of current frame.
number
x Horizontal position in frame.
number
y Vertical position in frame.
number
attr Attribute reference info