0.1.0 • Published 2 years ago

@v0rt4c/otb v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@v0rt4c/ot-otb

This library reads and writes Open Tibia .OTB files.

Table of contents

Getting Started

The library supports multiple platforms (Browser, NodeJS and Deno).

NodeJS

CommonJS

const { OTBReader, OTBWriter } = require('@v0rt4c/ot-otb');

ES6

import { OTBReader, OTBWriter } from '@v0rt4c/ot-otb';

Deno

import { OTBReader, OTBWriter } from 'https://deno.land/x/v0rt4c_otb@0.1.0/mod.ts';

Usage

Reading .OTB

Reading the .OTB file is really easy. Simply create a new instance of the OTBReader and provide it with the .OTB file buffer. The buffer param must be a Uint8Array. Then call the parse method to get the RootNode.

const reader = new OTBReader(otbBuffer);
const rootNode = reader.parse();

console.log(rootNode);

Output

RootNode {
  _itemsMajorVersion: 1,
  _itemsMinorVersion: 3,
  _itemsBuildNumber: 17,
  _children: [Item, Item, Item, Item, ..., ...]
  }

Writing .OTB

Writing the .OTB file back to its original form is also really easy. Simply create a new instance of the OTBWriter and provide it with the RootNode. Then call the writeBuffer method. This will give you the .OTB buffer back as the return value.

const writer = new OTBWriter(rootNode);
const buffer = writer.writeBuffer();

API

RootNode

The RootNode class holds information about the .OTB file such as the versions & buildnumber. It also holds all the items in the .OTB file in an array.

Constructor

@ParamsOptional
itemsMajorVersionfalse
itemsMinorVersionfalse
itemsBuildVersionfalse

Properties

PropertyGetterSetter
itemsMajorVersionXX
itemsMinorVersionXX
itemsBuildNumberXX
childrenX

Methods

MethodParamsDescription
addItemitem : ItemAdds a new item to the root node
getItemByServerIdserverId : numberGets a specific item by its server ID
getItemByClientIdclientId : numberGets a specific item by its client ID
removeItemByServerIdserverId : numberRemoves an item by providing its server ID
removeItemByClientIdclientId : numberRemoves an item by providing its client ID
popItemRemoves an item from the end of the item list
shiftItemRemoves an item from the start of the item list

Item

The Item class holds information about an item, such as the server ID, client ID, flags & attributes.

Constructor

The Item constructor takes no arguments.

Properties

PropertyGetterSetter
serverIdXX
clientIdXX
typeXX
groupXX
flagsX
attributesX

Methods

MethodParamsDescription
setAttributeattribute : string, value : anySets an attribute on the item
setFlagsflags : numberSets the item flags from the provided integer
setFlagflag : string, value : booleanSets a specific flag
getFlagsIntReturns the integer value for the item flags

Authors

V0RT4C

License

MIT License