Skip to content

Commit

Permalink
allow interactive objects to keep the filename part in the name property
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Apr 1, 2023
1 parent f03b02a commit 156141d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ export const any = <T>(fn: (value: T) => boolean, values: T[]) => {
}
return false
}

export const last = <T>(values: T[]) => {
return values[values.length - 1]
}
53 changes: 37 additions & 16 deletions src/dlf/InteactiveObject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path'
import { Buffer } from 'node:buffer'
import { BinaryIO } from '@common/BinaryIO'
import { repeat } from '@common/helpers'
import { last, repeat } from '@common/helpers'
import { ArxRotation, ArxVector3 } from '@common/types'

/**
Expand Down Expand Up @@ -46,27 +47,47 @@ export class InteractiveObject {
}

/**
* from: \\\\ARKANESERVER\\PUBLIC\\ARX\\GRAPH\\OBJ3D\\INTERACTIVE\\ITEMS\\PROVISIONS\\PIE\\PIE.teo
* to: items/provisions/pie
* from: `\\\\ARKANESERVER\\PUBLIC\\ARX\\GRAPH\\OBJ3D\\INTERACTIVE\\ITEMS\\PROVISIONS\\PIE\\PIE.teo`
* to: `items/provisions/pie`
*
* from: C:\\ARX\\Graph\\Obj3D\\Interactive\\System\\Marker\\Marker.teo
* to: system/marker
* from: `C:\\ARX\\Graph\\Obj3D\\Interactive\\System\\Marker\\Marker.teo`
* to: `system/marker`
*
* If the last folder in the path and filename differs, like `...\\ITEMS\\PROVISIONS\\MUSHROOM\\FOOD_MUSHROOM.teo`
* then it should keep the full path, but change the extension to `.asl`
*/
static toRelativePath(name: string) {
return name
.toLowerCase()
.replace(/\\/g, '/')
.split('graph/obj3d/interactive/')[1]
.replace(/\/[^/]+$/, '')
static toRelativePath(filePath: string) {
// items/provisions/pie/pie.teo
// items/provisions/mushroom/food_mushroom.teo
filePath = filePath.toLowerCase().replace(/\\/g, '/').split('graph/obj3d/interactive/')[1]

const { dir, name } = path.parse(filePath)

if (last(dir.split('/')) !== name) {
return dir + '/' + name + '.asl'
} else {
return dir
}
}

/**
* from: items/provisions/pie
* to: c:\\arx\\graph\\obj3d\\interactive\\items\\provisions\\pie\\pie.teo
* from: `items/provisions/pie`
* to: `c:\\arx\\graph\\obj3d\\interactive\\items\\provisions\\pie\\pie.teo`
*
* If the path also has a file specified with extension, like `items/provisions/mushroom/food_mushroom.asl`
* then keep the file part too, but change the extension to `.teo`
*/
static toAbsolutePath(name: string) {
const filename = name.split('/').pop() + '.teo'
return 'c:\\arx\\graph\\obj3d\\interactive\\' + name.toLowerCase().replace(/\//g, '\\') + '\\' + filename
static toAbsolutePath(filePath: string) {
filePath = filePath.toLowerCase().replace(/\/$/, '')

if (filePath.endsWith('.asl')) {
const { dir, name } = path.parse(filePath)
return `c:\\arx\\graph\\obj3d\\interactive\\${dir.replace(/\//g, '\\')}\\${name}.teo`
} else {
const dir = filePath
const name = last(filePath.split('/'))
return `c:\\arx\\graph\\obj3d\\interactive\\${dir.replace(/\//g, '\\')}\\${name}.teo`
}
}

static sizeOf() {
Expand Down

0 comments on commit 156141d

Please sign in to comment.