Skip to content

Commit

Permalink
advanced usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Oct 18, 2020
1 parent 069b015 commit b9ebf1c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/advanced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { init, WzFile, WzMapleVersion, WzBinaryProperty, WzImage, WzDirectory } = require('..')

async function main () {
// Must call init() first to initialize Webassembly
// before calling other API in browser.
// In nodejs it is just return Promise.resolve()
await init()

// Construct a WzFile object
const wz = new WzFile('C:\\Nexon\\MapleStory\\Sound.wz', WzMapleVersion.BMS)

// Pass it to parseWzFile() to receive parse result
const result = WzFile.createParseResult()
const r = await wz.parseWzFile(/* out */ result, /* parse main directory only */ true)
if (!r) {
throw new Error(result.message)
}

// Access main directory
/** @type {WzDirectory} */
const mainDirectory = wz.wzDirectory // ! not null

/** @type {WzImage | null} */
const img = mainDirectory.at('Bgm50.img')
if (img === null) throw new Error('404')

// Parse the image before use it
await img.parseImage()

// Access image properties
const props = img.wzProperties // getter returns Set<WzImageProperty>

for (const prop of props) {
if (prop instanceof WzBinaryProperty) {
console.log(prop.fullPath)
// do something
// prop.saveToFile()
}
}
wz.dispose()
}

main()

0 comments on commit b9ebf1c

Please sign in to comment.