private JSONObject WriteMap(VoxelArray voxelArray, List <string> materials, List <Substance> substances) { JSONObject map = new JSONObject(); JSONArray voxels = new JSONArray(); foreach (Voxel voxel in voxelArray.IterateVoxels()) { if (voxel.CanBeDeleted()) { Debug.Log("Empty voxel found!"); voxelArray.VoxelModified(voxel); continue; } voxels[-1] = WriteVoxel(voxel, materials, substances); } map["voxels"] = voxels; return(map); }
private JSONObject WriteWorld(VoxelArray voxelArray) { JSONObject world = new JSONObject(); JSONArray materialsArray = new JSONArray(); var foundMaterials = new List <string>(); JSONArray substancesArray = new JSONArray(); var foundSubstances = new List <Substance>(); foreach (Voxel voxel in voxelArray.IterateVoxels()) { foreach (VoxelFace face in voxel.faces) { AddMaterial(face.material, foundMaterials, materialsArray); AddMaterial(face.overlay, foundMaterials, materialsArray); } if (voxel.substance != null && !foundSubstances.Contains(voxel.substance)) { foundSubstances.Add(voxel.substance); substancesArray[-1] = WriteEntity(voxel.substance, false); } } world["materials"] = materialsArray; if (foundSubstances.Count != 0) { world["substances"] = substancesArray; } world["global"] = WritePropertiesObject(voxelArray.world, false); world["map"] = WriteMap(voxelArray, foundMaterials, foundSubstances); JSONArray objectsArray = new JSONArray(); foreach (ObjectEntity obj in voxelArray.IterateObjects()) { objectsArray[-1] = WriteObjectEntity(obj, true); } if (objectsArray.Count != 0) { world["objects"] = objectsArray; } return(world); }
private static MessagePackObjectDictionary WriteWorld(Transform cameraPivot, VoxelArray voxelArray) { var world = new MessagePackObjectDictionary(); world[FileKeys.WORLD_WRITER_VERSION] = VERSION; world[FileKeys.WORLD_MIN_READER_VERSION] = FILE_MIN_READER_VERSION; world[FileKeys.WORLD_TYPE] = (int)voxelArray.type; world[FileKeys.WORLD_CAMERA] = new MessagePackObject(WriteCamera(cameraPivot)); var materialsList = new List <MessagePackObject>(); var foundMaterials = new List <string>(); var overlaysList = new List <MessagePackObject>(); var foundOverlays = new List <string>(); var substancesList = new List <MessagePackObject>(); var foundSubstances = new List <Substance>(); foreach (Voxel voxel in voxelArray.IterateVoxels()) { foreach (VoxelFace face in voxel.faces) { AddMaterial(face.material, foundMaterials, materialsList); AddMaterial(face.overlay, foundOverlays, overlaysList); } if (voxel.substance != null && !foundSubstances.Contains(voxel.substance)) { foundSubstances.Add(voxel.substance); substancesList.Add(new MessagePackObject(WriteEntity(voxel.substance, false))); } } world[FileKeys.WORLD_MATERIALS] = new MessagePackObject(materialsList); world[FileKeys.WORLD_OVERLAYS] = new MessagePackObject(overlaysList); if (foundSubstances.Count != 0) { world[FileKeys.WORLD_SUBSTANCES] = new MessagePackObject(substancesList); } world[FileKeys.WORLD_GLOBAL] = new MessagePackObject(WritePropertiesObject(voxelArray.world, false)); var voxelsList = new List <MessagePackObject>(); foreach (Voxel voxel in voxelArray.IterateVoxels()) { if (voxel.CanBeDeleted()) { Debug.Log("Empty voxel found!"); continue; } voxelsList.Add(WriteVoxel(voxel, foundMaterials, foundOverlays, foundSubstances)); } world[FileKeys.WORLD_VOXELS] = new MessagePackObject(voxelsList); var objectsList = new List <MessagePackObject>(); foreach (ObjectEntity obj in voxelArray.IterateObjects()) { objectsList.Add(new MessagePackObject(WriteObjectEntity(obj, true))); } if (objectsList.Count != 0) { world[FileKeys.WORLD_OBJECTS] = new MessagePackObject(objectsList); } return(world); }