Skip to content

Commit

Permalink
refactor(InteractiveObject): replace path.parse() with in-house solut…
Browse files Browse the repository at this point in the history
…ion for browser compatibility
  • Loading branch information
meszaros-lajos-gyorgy committed Dec 22, 2024
1 parent da51c78 commit 70409f6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/dlf/InteactiveObject.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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`
}

Expand Down

0 comments on commit 70409f6

Please sign in to comment.