Exclude spawn points from level duplication
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
type AnyNodeId,
|
type AnyNodeId,
|
||||||
BuildingNode,
|
BuildingNode,
|
||||||
LevelNode,
|
LevelNode,
|
||||||
|
SpawnNode,
|
||||||
WallNode,
|
WallNode,
|
||||||
} from '@pascal-app/core/schema'
|
} from '@pascal-app/core/schema'
|
||||||
import { buildLevelDuplicateCreateOps } from './level-duplication'
|
import { buildLevelDuplicateCreateOps } from './level-duplication'
|
||||||
@@ -38,4 +39,34 @@ describe('buildLevelDuplicateCreateOps', () => {
|
|||||||
expect(sourceLevel.parentId).toBeNull()
|
expect(sourceLevel.parentId).toBeNull()
|
||||||
expect(levelCreateOp?.parentId).toBe(building.id)
|
expect(levelCreateOp?.parentId).toBe(building.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('does not copy spawn points from the source level', () => {
|
||||||
|
const building = BuildingNode.parse({})
|
||||||
|
const spawn = SpawnNode.parse({ parentId: 'level_source' })
|
||||||
|
const level = LevelNode.parse({
|
||||||
|
id: 'level_source',
|
||||||
|
level: 0,
|
||||||
|
parentId: building.id,
|
||||||
|
children: [spawn.id],
|
||||||
|
})
|
||||||
|
const nodes = {
|
||||||
|
[building.id]: { ...building, children: [level.id] },
|
||||||
|
[level.id]: level,
|
||||||
|
[spawn.id]: spawn,
|
||||||
|
} as Record<AnyNodeId, AnyNode>
|
||||||
|
|
||||||
|
const { createOps, newLevelId } = buildLevelDuplicateCreateOps({
|
||||||
|
nodes,
|
||||||
|
level,
|
||||||
|
levels: [level],
|
||||||
|
preset: 'everything',
|
||||||
|
})
|
||||||
|
|
||||||
|
const copiedLevel = createOps.find((op) => op.node.id === newLevelId)?.node as
|
||||||
|
| LevelNode
|
||||||
|
| undefined
|
||||||
|
|
||||||
|
expect(createOps.some((op) => op.node.type === 'spawn')).toBe(false)
|
||||||
|
expect(copiedLevel?.children).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export type LevelDuplicatePreset =
|
|||||||
| 'structure-materials'
|
| 'structure-materials'
|
||||||
| 'structure-furniture'
|
| 'structure-furniture'
|
||||||
|
|
||||||
const REFERENCE_NODE_TYPES = new Set<AnyNode['type']>(['scan', 'guide'])
|
const NON_DUPLICABLE_NODE_TYPES = new Set<AnyNode['type']>(['scan', 'guide', 'spawn'])
|
||||||
const STRUCTURAL_NODE_TYPES = new Set<AnyNode['type']>([
|
const STRUCTURAL_NODE_TYPES = new Set<AnyNode['type']>([
|
||||||
'level',
|
'level',
|
||||||
'wall',
|
'wall',
|
||||||
@@ -24,8 +24,9 @@ const STRUCTURAL_NODE_TYPES = new Set<AnyNode['type']>([
|
|||||||
])
|
])
|
||||||
|
|
||||||
function shouldKeepNode(node: AnyNode, preset: LevelDuplicatePreset) {
|
function shouldKeepNode(node: AnyNode, preset: LevelDuplicatePreset) {
|
||||||
|
if (NON_DUPLICABLE_NODE_TYPES.has(node.type)) return false
|
||||||
if (preset === 'everything') return true
|
if (preset === 'everything') return true
|
||||||
if (preset === 'structure-furniture') return !REFERENCE_NODE_TYPES.has(node.type)
|
if (preset === 'structure-furniture') return true
|
||||||
if (preset === 'structure' || preset === 'structure-materials') {
|
if (preset === 'structure' || preset === 'structure-materials') {
|
||||||
return STRUCTURAL_NODE_TYPES.has(node.type)
|
return STRUCTURAL_NODE_TYPES.has(node.type)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user