From e385564e2670eaa8a7bf481fe72e2a476eb169b0 Mon Sep 17 00:00:00 2001 From: Casper Warden <216465704+casperwardensl@users.noreply.github.com> Date: Thu, 16 Nov 2023 02:56:47 +0000 Subject: [PATCH] Improve inventory parsing --- lib/classes/InventoryItem.ts | 97 ++++++++++++++++++++++++++++++++++-- package.json | 2 +- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/lib/classes/InventoryItem.ts b/lib/classes/InventoryItem.ts index 5eba570..6903e85 100644 --- a/lib/classes/InventoryItem.ts +++ b/lib/classes/InventoryItem.ts @@ -34,6 +34,7 @@ export class InventoryItem assetID: UUID = UUID.zero(); inventoryType: InventoryType; name: string; + metadata: string; salePrice: number; saleType: number; created: Date; @@ -73,9 +74,71 @@ export class InventoryItem static fromAsset(lineObj: { lines: string[], lineNum: number }, container?: GameObject | InventoryFolder, agent?: Agent): InventoryItem { const item: InventoryItem = new InventoryItem(container, agent); + let contMetadata = false; + let contName = false; + let contDesc = false; while (lineObj.lineNum < lineObj.lines.length) { - const line = lineObj.lines[lineObj.lineNum++]; + let line = lineObj.lines[lineObj.lineNum++]; + + if (contMetadata) + { + const idx = line.indexOf('|'); + if (idx !== -1) + { + item.metadata += '\n' + line.substring(0, idx); + line = line.substring(idx + 1); + contMetadata = false; + if (line.length === 0) + { + continue; + } + } + else + { + item.metadata += line; + continue; + } + } + if (contName) + { + const idx = line.indexOf('|'); + if (idx !== -1) + { + item.name += '\n' + line.substring(0, idx); + line = line.substring(idx + 1); + contName = false; + if (line.length === 0) + { + continue; + } + } + else + { + item.name += line; + continue; + } + } + if (contDesc) + { + const idx = line.indexOf('|'); + if (idx !== -1) + { + item.description += '\n' + line.substring(0, idx); + line = line.substring(idx + 1); + contDesc = false; + if (line.length === 0) + { + continue; + } + } + else + { + item.description += line; + continue; + } + } + let result = Utils.parseLine(line); if (result.key !== null) { @@ -275,16 +338,44 @@ export class InventoryItem } else if (result.key === 'name') { - item.name = result.value.substr(0, result.value.indexOf('|')); + if (result.value.indexOf('|') !== -1) + { + item.name = result.value.substr(0, result.value.indexOf('|')); + } + else + { + contName = true; + item.name = result.value; + } } else if (result.key === 'desc') { - item.description = result.value.substr(0, result.value.indexOf('|')); + if (result.value.indexOf('|') !== -1) + { + item.description = result.value.substr(0, result.value.indexOf('|')); + } + else + { + contDesc = true; + item.description = result.value; + } } else if (result.key === 'creation_date') { item.created = new Date(parseInt(result.value, 10) * 1000); } + else if (result.key === 'metadata') + { + if (result.value.indexOf('|') !== -1) + { + item.metadata = result.value.substr(0, result.value.indexOf('|')); + } + else + { + contMetadata = true; + item.metadata = result.value; + } + } else { console.log('Unrecognised key (2): ' + result.key); diff --git a/package.json b/package.json index 89898c4..9b68af4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@caspertech/node-metaverse", - "version": "0.6.7", + "version": "0.6.8", "description": "A node.js interface for Second Life.", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts",