@@ -4,6 +4,7 @@ import assert from "node:assert/strict";
44
55// Import Internal Dependencies
66import { VoxelWorld } from "../../src/world/VoxelWorld.ts" ;
7+ import { VoxelLayer } from "../../src/world/VoxelLayer.ts" ;
78import { FACE } from "../../src/utils/math.ts" ;
89
910function makeEntry ( blockId = 1 , transform = 0 ) {
@@ -298,3 +299,36 @@ describe("VoxelWorld chunkSize", () => {
298299 assert . equal ( world . chunkSize , 8 ) ;
299300 } ) ;
300301} ) ;
302+
303+ describe ( "VoxelWorld clone" , ( ) => {
304+ it ( "shouldn't clone a layer that doesn't exist" , ( ) => {
305+ const world = new VoxelWorld ( 8 ) ;
306+ assert . equal ( world . cloneLayer ( "A" , { name : "A_1" } ) , undefined ) ;
307+ assert . equal ( world . getLayer ( "A" ) , undefined ) ;
308+ } ) ;
309+ it ( "should clone a layer" , ( ) => {
310+ const world = new VoxelWorld ( 8 ) ;
311+ world . addLayer ( "A" ) ;
312+ const layer = removeId ( world . getLayer ( "A" ) ! ) ;
313+ const expected = { ...layer , name : "A_1" } ;
314+ const clone = removeId ( world . cloneLayer ( "A" , { name : "A_1" } ) ! ) ;
315+ assert . deepEqual ( clone , expected ) ;
316+ assert . deepEqual ( removeId ( world . getLayer ( "A_1" ) ! ) , expected ) ;
317+ } ) ;
318+
319+ it ( "should be able to override or add properties" , ( ) => {
320+ const world = new VoxelWorld ( 8 ) ;
321+ world . addLayer ( "A" ) ;
322+ const layer = removeId ( world . getLayer ( "A" ) ! ) ;
323+ const expected = { ...layer , name : "A_1" , visible : false } ;
324+ const clone = removeId ( world . cloneLayer ( "A" , { name : "A_1" , visible : false } ) ! ) ;
325+ assert . deepEqual ( clone , expected ) ;
326+ assert . deepEqual ( removeId ( world . getLayer ( "A_1" ) ! ) , expected ) ;
327+ } ) ;
328+
329+ function removeId ( layer : VoxelLayer ) {
330+ const { id, ...rest } = layer . toJSON ( ) ;
331+
332+ return rest ;
333+ }
334+ } ) ;
0 commit comments