This library reads and writes Open Tibia .OTB files.
The library supports multiple platforms (Browser, NodeJS and Deno).
const { OTBReader, OTBWriter } = require('@v0rt4c/ot-otb');
import { OTBReader, OTBWriter } from '@v0rt4c/ot-otb';
import { OTBReader, OTBWriter } from 'https://deno.land/x/[email protected]/mod.ts';
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 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();
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.
@Params | Optional |
---|---|
itemsMajorVersion | false |
itemsMinorVersion | false |
itemsBuildVersion | false |
Property | Getter | Setter |
---|---|---|
itemsMajorVersion | X | X |
itemsMinorVersion | X | X |
itemsBuildNumber | X | X |
children | X |
Method | Params | Description |
---|---|---|
addItem | item : Item | Adds a new item to the root node |
getItemByServerId | serverId : number | Gets a specific item by its server ID |
getItemByClientId | clientId : number | Gets a specific item by its client ID |
removeItemByServerId | serverId : number | Removes an item by providing its server ID |
removeItemByClientId | clientId : number | Removes an item by providing its client ID |
popItem | Removes an item from the end of the item list | |
shiftItem | Removes an item from the start of the item list |
The Item class holds information about an item, such as the server ID, client ID, flags & attributes.
The Item constructor takes no arguments.
Property | Getter | Setter |
---|---|---|
serverId | X | X |
clientId | X | X |
type | X | X |
group | X | X |
flags | X | |
attributes | X |
Method | Params | Description |
---|---|---|
setAttribute | attribute : string, value : any | Sets an attribute on the item |
setFlags | flags : number | Sets the item flags from the provided integer |
setFlag | flag : string, value : boolean | Sets a specific flag |
getFlagsInt | Returns the integer value for the item flags |
V0RT4C
MIT License