Exclude spawn points from level duplication
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
type AnyNodeId,
|
||||
BuildingNode,
|
||||
LevelNode,
|
||||
SpawnNode,
|
||||
WallNode,
|
||||
} from '@pascal-app/core/schema'
|
||||
import { buildLevelDuplicateCreateOps } from './level-duplication'
|
||||
@@ -38,4 +39,34 @@ describe('buildLevelDuplicateCreateOps', () => {
|
||||
expect(sourceLevel.parentId).toBeNull()
|
||||
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-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']>([
|
||||
'level',
|
||||
'wall',
|
||||
@@ -24,8 +24,9 @@ const STRUCTURAL_NODE_TYPES = new Set<AnyNode['type']>([
|
||||
])
|
||||
|
||||
function shouldKeepNode(node: AnyNode, preset: LevelDuplicatePreset) {
|
||||
if (NON_DUPLICABLE_NODE_TYPES.has(node.type)) return false
|
||||
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') {
|
||||
return STRUCTURAL_NODE_TYPES.has(node.type)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user