From 70409f69466db52ec71a7435913061daa5a604cf Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Sun, 22 Dec 2024 20:41:17 +0100 Subject: [PATCH] refactor(InteractiveObject): replace path.parse() with in-house solution for browser compatibility --- src/dlf/InteactiveObject.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/dlf/InteactiveObject.ts b/src/dlf/InteactiveObject.ts index c3af536..ec18a4a 100644 --- a/src/dlf/InteactiveObject.ts +++ b/src/dlf/InteactiveObject.ts @@ -1,4 +1,3 @@ -import path from 'node:path' import { BinaryIO } from '@common/BinaryIO.js' import { repeat } from '@common/helpers.js' import { type ArxRotation, type ArxVector3 } from '@common/types.js' @@ -60,7 +59,16 @@ export class InteractiveObject { // items/provisions/mushroom/food_mushroom.teo filePath = filePath.toLowerCase().replaceAll('\\', '/').split('graph/obj3d/interactive/')[1] - const { dir, name } = path.parse(filePath) + // browser compatible version of `const { dir, name } = path.parse(filePath)` + const filePathParts = filePath.split('/') + const fileName = filePathParts.pop() as string + const fileNameParts = fileName.split('.') + if (fileNameParts.length > 1) { + fileNameParts.pop() + } + + const dir = filePathParts.join('/') + const name = fileNameParts.join('.') if (dir.split('/').at(-1) !== name) { return dir + '/' + name + '.asl' @@ -80,7 +88,17 @@ export class InteractiveObject { filePath = filePath.toLowerCase().replace(/\/$/, '') if (filePath.endsWith('.asl')) { - const { dir, name } = path.parse(filePath) + // browser compatible version of `const { dir, name } = path.parse(filePath)` + const filePathParts = filePath.split('/') + const fileName = filePathParts.pop() as string + const fileNameParts = fileName.split('.') + if (fileNameParts.length > 1) { + fileNameParts.pop() + } + + const dir = filePathParts.join('/') + const name = fileNameParts.join('.') + return `c:\\arx\\graph\\obj3d\\interactive\\${dir.replaceAll('/', '\\')}\\${name}.teo` }