adofai-lib
v1.2.6
Published
A TypeScript library for advanced manipulation and analysis of ADOFAI level files.
Maintainers
Readme
ADOFAI Library
A TypeScript library for working with ADOFAI level files. This library provides a simple interface for reading, modifying, and writing ADOFAI level files.
Ported from M1n3c4rt's adofaipy lib and expanded by V0W4N
Installation
npm install adofai-libUsage
import LevelDict, {LevelJSON, Action} from 'adofai-lib';
// Load an ADOFAI level file
const level = new LevelDict('path/to/level.adofai');
// Get all angles in the level
const angles = level.getAngles();
// Get relative angles (degrees between each pair of tiles)
const relativeAngles = level.getAnglesRelative();
// Get all actions in the level
const actions = level.getActions();
// Get actions with a filter condition
const twirlActions = level.getActions(action => action.eventType === 'Twirl');
// Get all floor decorations
const floorDecorations = level.getDecorations();
// Get all decorations including non-floor decorations
const allDecorations = level.getDecorations(() => true, true);
// Get decorations with a filter condition
const backgroundDecos = level.getDecorations(deco => deco.decorationType === 'Background');
// Get tiles in a range
const tilesInRange = level.getTiles(1, 4);
// Get tiles at specific indices
const specificTiles = level.getTiles([0, 2, 4]);
// Modify the level...
// Save the modified level
level.writeToFile('path/to/output.adofai');Features
- Read and write ADOFAI level files
- Get and set tile angles
- Get relative angles between tiles
- Manage actions and decorations
- Support for both angle-based and path-based level formats
- Flexible tile, action, and decoration retrieval with filtering options
API Reference
LevelDict
The main class for working with ADOFAI level files.
Constructor
new LevelDict(filename?: string, encoding?: string)filename: Path to the ADOFAI level file (optional)encoding: File encoding (default: 'utf-8')
Methods
Tile Management
getAngles(): Returns an array of all tile anglessetAngles(angles: number[]): Sets the angles for all tilesgetAnglesRelative(ignoreTwirls?: boolean, padMidspins?: boolean): Returns relative angles between tilesgetTiles(start: number, end: number): Returns tiles in the specified rangegetTiles(indices: number[]): Returns tiles at the specified indices
Action Management
getActions(condition?: (action: Action) => boolean): Returns actions matching the conditionsetActions(actions: Action[]): Sets all actions in the levelinsertAction(floor: number, action: Action): Inserts an action at the specified floorremoveAction(floor: number, actionIndex: number): Removes an action at the specified floor and indexupdateAction(floor: number, actionIndex: number, newAction: Partial<Action>): Updates an actioninsertActionAt(floor: number, actionIndex: number, action: Action): Inserts an action at a specific position
Decoration Management
getDecorations(condition?: (decoration: Decoration) => boolean, includeNonFloor?: boolean): Returns decorations matching the conditionsetDecorations(decorations: Decoration[]): Sets all decorations in the levelinsertDecoration(floor: number | undefined, decoration: Decoration): Inserts a decorationremoveDecoration(floor: number | undefined, decorationIndex: number): Removes a decorationupdateDecoration(floor: number | undefined, decorationIndex: number, newDecoration: Partial<Decoration>): Updates a decorationinsertDecorationAt(floor: number | undefined, decorationIndex: number, decoration: Decoration): Inserts a decoration at a specific position
File Operations
writeToFile(filename?: string): Saves the level to a filetoJSON(): Returns the level data as a JSON objectstatic fromJSON(json: string): Creates a LevelDict instance from JSON data
Utility Methods
copy(): Creates a deep copy of the levelcompareWith(other: LevelDict): Compares two levels and returns differences
Error Handling
The library includes comprehensive error handling for invalid operations:
- Invalid tile indices
- Invalid floor indices
- Invalid action/decoration indices
- Invalid range selections
- Invalid file operations
License
MIT
