@divinevoxel/vlox 0.0.72 → 0.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -1
  2. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
  3. package/Init/StartConstructor.js +6 -4
  4. package/Init/StartWorld.d.ts +1 -1
  5. package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
  6. package/Mesher/Functions/CompactVoxelMesh.js +1 -1
  7. package/Mesher/Functions/MeshSection.js +20 -8
  8. package/Mesher/Functions/MeshTexture.d.ts +1 -1
  9. package/Mesher/Functions/MeshTexture.js +3 -4
  10. package/Mesher/Geomtry/Primitives/QuadVertexData.d.ts +12 -10
  11. package/Mesher/Geomtry/Primitives/QuadVertexData.js +49 -56
  12. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +2 -2
  13. package/Mesher/Geomtry/VoxelGeometryBuilder.js +2 -2
  14. package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
  15. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  16. package/Mesher/Geomtry/index.d.ts +0 -1
  17. package/Mesher/Geomtry/index.js +0 -1
  18. package/Mesher/InitMesher.js +1 -1
  19. package/Mesher/InitTask.js +4 -22
  20. package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -2
  21. package/Mesher/Models/Common/Calc/FaceDataCalc.js +37 -30
  22. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.d.ts +2 -2
  23. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.js +1 -1
  24. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +11 -17
  25. package/Mesher/Models/Nodes/GeometryNode.d.ts +2 -2
  26. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +1 -0
  27. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +24 -12
  28. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.d.ts +1 -1
  29. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.js +1 -1
  30. package/Mesher/Models/RenderedMaterials.d.ts +6 -0
  31. package/Mesher/{RenderedMaterials.js → Models/RenderedMaterials.js} +2 -2
  32. package/Mesher/Models/VoxelConstructor.d.ts +3 -3
  33. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +1 -3
  34. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +0 -23
  35. package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +4 -5
  36. package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +11 -7
  37. package/Models/Defaults/CubeVoxelGeometry.js +4 -0
  38. package/Models/Defaults/CubeVoxelModels.js +344 -344
  39. package/Models/Defaults/LiquidVoxelModel.js +2 -2
  40. package/Models/Defaults/PanelVoxelModels.js +432 -432
  41. package/Models/Defaults/StairVoxelModel.js +576 -576
  42. package/Models/Examples.js +469 -456
  43. package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
  44. package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
  45. package/Models/Rules/Functions/BuildRules.js +2 -2
  46. package/Models/Rules/{VoxelModelManager.d.ts → VoxelModelRuleBuilderRegister.d.ts} +1 -1
  47. package/Models/Rules/VoxelModelRuleBuilderRegister.js +178 -0
  48. package/Models/VoxelModel.types.d.ts +14 -5
  49. package/Renderer/Classes/SectorMesh.d.ts +3 -4
  50. package/Renderer/Classes/SectorMesh.js +6 -11
  51. package/Renderer/InitTasks.js +6 -7
  52. package/Renderer/MeshManager.js +2 -2
  53. package/Renderer/MeshRegister.js +2 -1
  54. package/Settings/EngineSettings.d.ts +1 -1
  55. package/Settings/EngineSettings.js +3 -5
  56. package/Settings/EngineSettings.types.d.ts +17 -18
  57. package/Settings/EngineSettings.types.js +16 -15
  58. package/Tasks/IWG/IWG.d.ts +2 -1
  59. package/Tasks/IWG/IWG.js +9 -3
  60. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +11 -0
  61. package/Tasks/IWG/Internal/Classes/BuildQueue.js +49 -0
  62. package/Tasks/IWG/Internal/Classes/Generator.d.ts +6 -1
  63. package/Tasks/IWG/Internal/Classes/Generator.js +13 -1
  64. package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
  65. package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
  66. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
  67. package/Tasks/IWG/Internal/IWGTasks.js +0 -10
  68. package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
  69. package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
  70. package/Tasks/Update/UpdateTask.d.ts +3 -1
  71. package/Tasks/Update/UpdateTask.js +28 -2
  72. package/Tasks/Update/VoxelUpdate.js +6 -0
  73. package/Tasks/WorldGeneration/WorldGenBrush.js +1 -1
  74. package/Templates/Cursor/TemplateCursor.d.ts +2 -2
  75. package/Templates/Cursor/TemplateCursor.js +1 -2
  76. package/Templates/VoxelTemplates.types.d.ts +1 -1
  77. package/Textures/Classes/CompiledTexture.d.ts +18 -0
  78. package/Textures/Classes/CompiledTexture.js +50 -0
  79. package/Textures/Classes/CompiledTextureAnimation.d.ts +12 -0
  80. package/Textures/Classes/CompiledTextureAnimation.js +27 -0
  81. package/Textures/Classes/TextureAnimationTexture.d.ts +10 -0
  82. package/Textures/Classes/TextureAnimationTexture.js +32 -0
  83. package/Textures/Functions/BuildTextureData.d.ts +10 -0
  84. package/Textures/Functions/BuildTextureData.js +205 -0
  85. package/Textures/Texture.types.d.ts +50 -64
  86. package/Textures/TextureManager.d.ts +8 -19
  87. package/Textures/TextureManager.js +28 -166
  88. package/Tools/Brush/Brush.d.ts +1 -1
  89. package/Tools/Brush/Brush.js +39 -7
  90. package/Util/Binary/BinaryArrays.d.ts +6 -0
  91. package/Util/Binary/BinaryArrays.js +25 -0
  92. package/Util/Binary/BinaryBuffer.d.ts +29 -0
  93. package/Util/Binary/BinaryBuffer.js +130 -0
  94. package/Util/Binary/{BitArray.d.ts → BinaryFunctions.d.ts} +1 -2
  95. package/Util/Binary/BinaryFunctions.js +11 -0
  96. package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
  97. package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
  98. package/Voxels/Cursor/VoxelCursor.interface.js +8 -11
  99. package/Voxels/Data/VoxelPalettesRegister.d.ts +0 -5
  100. package/Voxels/Data/VoxelPalettesRegister.js +0 -9
  101. package/Voxels/Data/VoxelTagsRegister.js +7 -7
  102. package/Voxels/Functions/BuildStateData.js +9 -9
  103. package/Voxels/Functions/BuildTagAndPaletteData.js +2 -4
  104. package/Voxels/InitVoxelData.js +12 -13
  105. package/Voxels/State/Schema/StateSchema.d.ts +1 -1
  106. package/Voxels/Types/Voxel.types.d.ts +18 -0
  107. package/Voxels/Types/Voxel.types.js +6 -2
  108. package/World/Archive/Archive.types.d.ts +38 -34
  109. package/World/Archive/Functions/ArchiveArea.js +16 -24
  110. package/World/Archive/Functions/ArchiveSector.js +477 -192
  111. package/World/Archive/Functions/ImportSector.d.ts +3 -3
  112. package/World/Archive/Functions/ImportSector.js +202 -141
  113. package/World/Archive/Functions/Shared.d.ts +6 -0
  114. package/World/Archive/Functions/Shared.js +75 -0
  115. package/World/Archive/InitTasks.js +30 -13
  116. package/World/Cursor/SectionCursor.d.ts +2 -2
  117. package/World/Cursor/SectionCursor.js +2 -3
  118. package/World/Cursor/SectorCursor.d.ts +2 -2
  119. package/World/Cursor/SectorCursor.js +1 -2
  120. package/World/Cursor/WorldCursor.d.ts +2 -2
  121. package/World/Cursor/WorldCursor.js +1 -2
  122. package/World/Cursor/WorldVoxelCursor.js +1 -0
  123. package/World/InitTasks.d.ts +1 -1
  124. package/World/Lock/WorldLock.d.ts +1 -1
  125. package/World/Section/Section.d.ts +12 -16
  126. package/World/Section/Section.js +62 -20
  127. package/World/Section/SectionState.d.ts +10 -0
  128. package/World/Section/SectionState.js +11 -0
  129. package/World/Sector/Sector.d.ts +14 -6
  130. package/World/Sector/Sector.js +67 -17
  131. package/World/Sector/SectorHeightMap.js +2 -2
  132. package/World/Sector/SectorState.d.ts +14 -6
  133. package/World/Sector/SectorState.js +28 -15
  134. package/World/Types/WorldStorage.interface.js +1 -0
  135. package/World/WorldRegister.d.ts +4 -0
  136. package/World/WorldRegister.js +15 -3
  137. package/World/WorldSpaces.d.ts +4 -0
  138. package/World/WorldSpaces.js +19 -6
  139. package/package.json +1 -1
  140. package/Mesher/Functions/CompactMesh.d.ts +0 -2
  141. package/Mesher/Functions/CompactMesh.js +0 -42
  142. package/Mesher/Geomtry/GeometryNormals.d.ts +0 -10
  143. package/Mesher/Geomtry/GeometryNormals.js +0 -52
  144. package/Mesher/Geomtry/MeshData.types.d.ts +0 -13
  145. package/Mesher/Geomtry/MeshData.types.js +0 -6
  146. package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +0 -7
  147. package/Mesher/Geomtry/Tools/MesherDataTools.js +0 -12
  148. package/Mesher/Geomtry/Tools/index.d.ts +0 -1
  149. package/Mesher/Geomtry/Tools/index.js +0 -1
  150. package/Mesher/RenderedMaterials.d.ts +0 -6
  151. package/Models/Rules/VoxelModelManager.js +0 -82
  152. package/Textures/TextureAnimations.d.ts +0 -4
  153. package/Textures/TextureAnimations.js +0 -35
  154. package/Textures/TextureArray.d.ts +0 -47
  155. package/Textures/TextureArray.js +0 -202
  156. package/Textures/TextureBuilder.d.ts +0 -13
  157. package/Textures/TextureBuilder.js +0 -120
  158. package/Textures/TextureRegister.d.ts +0 -9
  159. package/Textures/TextureRegister.js +0 -28
  160. package/Tools/DataCursor.interface.d.ts +0 -5
  161. package/Tools/DataCursor.interface.js +0 -2
  162. package/Util/Binary/BitArray.js +0 -16
  163. package/World/Structs/WorldDataStructProperties.d.ts +0 -8
  164. package/World/Structs/WorldDataStructProperties.js +0 -9
  165. /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +0 -0
  166. /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +0 -0
  167. /package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +0 -0
  168. /package/Mesher/Geomtry/{Buffers.js → VoxelMeshBuffers.js} +0 -0
  169. /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +0 -0
  170. /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +0 -0
  171. /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
  172. /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
  173. /package/{World/Storage/WorldStorage.interface.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
  174. /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
@@ -1,9 +1,9 @@
1
- import { VoxelDataArrays, SectorData } from "../../index";
1
+ import { SectionData, SectorData } from "../../index";
2
2
  import { ArchivedSectorData } from "../Archive.types";
3
3
  type RunData = {
4
4
  version?: number;
5
5
  loadColumnState?: (data: Record<string, any>, sector: SectorData) => void;
6
- loadSectionState?: (keys: string[], data: any[], section: VoxelDataArrays) => void;
6
+ loadSectionState?: (keys: string[], data: any[], section: SectionData) => void;
7
7
  };
8
- export default function ImportSector(sector: ArchivedSectorData, archiveData: RunData): SectorData;
8
+ export default function ImportSector(archivedSector: ArchivedSectorData, archiveData: RunData): SectorData;
9
9
  export {};
@@ -1,113 +1,168 @@
1
1
  import { Sector } from "../../index";
2
2
  import { NumberPalette } from "../../../Util/NumberPalette";
3
3
  import { StringPalette } from "../../../Util/StringPalette";
4
- import { getPaletteArray } from "../../../Util/Binary/Palettes";
5
4
  import { SchemaRegister } from "../../../Voxels/State/SchemaRegister";
6
5
  import { VoxelPalettesRegister } from "../../../Voxels/Data/VoxelPalettesRegister";
7
6
  import { VoxelTagsRegister } from "../../../Voxels/Data/VoxelTagsRegister";
8
- const updateSectionBuffers = (sector, section) => {
9
- if ((sector.palettes.id.length <= 15 ||
10
- (section.palettes.id && section.palettes.id.length <= 15)) &&
11
- ArrayBuffer.isView(section.buffers.id)) {
12
- section.buffers.id = getPaletteArray(Math.min(section.palettes.id?.length || Infinity, sector.palettes.id?.length || 0), section.buffers.id);
13
- }
14
- if (((section.palettes.light && section.palettes.light.length <= 15) ||
15
- (sector.palettes.light && sector.palettes.light.length <= 15)) &&
16
- ArrayBuffer.isView(section.buffers.light)) {
17
- section.buffers.light = getPaletteArray(Math.min(section.palettes.light?.length || Infinity, sector.palettes.light?.length || 0), section.buffers.light);
18
- }
19
- if (((section.palettes.state && section.palettes.state.length <= 15) ||
20
- (sector.palettes.state && sector.palettes.state.length <= 15)) &&
21
- ArrayBuffer.isView(section.buffers.state)) {
22
- section.buffers.state = getPaletteArray(Math.min(section.palettes.state?.length || Infinity, sector.palettes.state?.length || 0), section.buffers.state);
23
- }
24
- if (((section.palettes.mod && section.palettes.mod.length <= 15) ||
25
- (sector.palettes.mod && sector.palettes.mod.length <= 15)) &&
26
- ArrayBuffer.isView(section.buffers.mod)) {
27
- section.buffers.mod = getPaletteArray(Math.min(section.palettes.mod?.length || Infinity, sector.palettes.mod?.length || 0), section.buffers.mod);
28
- }
29
- if (((section.palettes.secondaryState &&
30
- section.palettes.secondaryState.length <= 15) ||
31
- (sector.palettes.secondaryState &&
32
- sector.palettes.secondaryState.length <= 15)) &&
33
- ((section.palettes.secondaryId &&
34
- section.palettes.secondaryId.length <= 15) ||
35
- (sector.palettes.secondaryId &&
36
- sector.palettes.secondaryId.length <= 15)) &&
37
- ArrayBuffer.isView(section.buffers.secondary)) {
38
- section.buffers.secondary = getPaletteArray(Math.max(Math.min(section.palettes.secondaryId?.length || Infinity, sector.palettes.secondaryId?.length || 0), Math.min(section.palettes.secondaryState?.length || Infinity, sector.palettes.secondaryState?.length || 0)), section.buffers.secondary);
39
- }
40
- };
41
- const getImportedColumnData = (sector) => {
7
+ import { BinaryBuffer } from "../../../Util/Binary/BinaryBuffer";
8
+ import { lightSegments, lightSemgnetSet } from "./Shared";
9
+ const getImportedSectorData = (sector) => {
42
10
  return {
43
11
  sector,
44
12
  idPalette: new StringPalette(sector.palettes.id),
45
- secondaryId: sector.palettes.secondaryId
46
- ? new StringPalette(sector.palettes.secondaryId)
47
- : undefined,
48
- lightPalette: sector.palettes.light
49
- ? new NumberPalette(sector.palettes.light)
50
- : undefined,
51
- statePalette: sector.palettes.state
52
- ? new NumberPalette(sector.palettes.state)
53
- : undefined,
54
- modPalette: sector.palettes.mod
55
- ? new NumberPalette(sector.palettes.mod)
56
- : undefined,
57
- secondaryState: sector.palettes.secondaryState
58
- ? new NumberPalette(sector.palettes.secondaryState)
13
+ secondaryId: new StringPalette(sector.palettes.secondaryId),
14
+ levelPalette: sector.palettes.level
15
+ ? new NumberPalette(sector.palettes.level)
59
16
  : undefined,
17
+ lightPalette: {
18
+ sun: sector.palettes.light.sun
19
+ ? new NumberPalette(sector.palettes.light.sun)
20
+ : null,
21
+ red: sector.palettes.light.red
22
+ ? new NumberPalette(sector.palettes.light.red)
23
+ : null,
24
+ green: sector.palettes.light.green
25
+ ? new NumberPalette(sector.palettes.light.green)
26
+ : null,
27
+ blue: sector.palettes.light.blue
28
+ ? new NumberPalette(sector.palettes.light.blue)
29
+ : null,
30
+ },
31
+ statePalette: new NumberPalette(sector.palettes.state),
32
+ modPalette: new NumberPalette(sector.palettes.mod),
33
+ secondaryState: new NumberPalette(sector.palettes.secondaryState),
60
34
  };
61
35
  };
62
36
  const getImportedSectionData = (section) => {
63
37
  return {
64
38
  section,
65
- idPalette: section.palettes.id
66
- ? new NumberPalette(section.palettes.id)
39
+ buffers: {
40
+ ids: !section.buffers.id
41
+ ? new BinaryBuffer({ buffer: 0 })
42
+ : typeof section.buffers.id == "number"
43
+ ? new BinaryBuffer({ buffer: section.buffers.id })
44
+ : new BinaryBuffer(section.buffers.id),
45
+ level: !section.buffers.level
46
+ ? new BinaryBuffer({ buffer: 0 })
47
+ : typeof section.buffers.level == "number"
48
+ ? new BinaryBuffer({ buffer: section.buffers.level })
49
+ : new BinaryBuffer(section.buffers.level),
50
+ light: {
51
+ sun: !section.buffers.light?.sun
52
+ ? new BinaryBuffer({ buffer: 0 })
53
+ : typeof section.buffers.light.sun == "number"
54
+ ? new BinaryBuffer({ buffer: section.buffers.light.sun })
55
+ : new BinaryBuffer(section.buffers.light.sun),
56
+ red: !section.buffers.light?.red
57
+ ? new BinaryBuffer({ buffer: 0 })
58
+ : typeof section.buffers.light.red == "number"
59
+ ? new BinaryBuffer({ buffer: section.buffers.light.red })
60
+ : new BinaryBuffer(section.buffers.light.red),
61
+ green: !section.buffers.light?.green
62
+ ? new BinaryBuffer({ buffer: 0 })
63
+ : typeof section.buffers.light.green == "number"
64
+ ? new BinaryBuffer({ buffer: section.buffers.light.green })
65
+ : new BinaryBuffer(section.buffers.light.green),
66
+ blue: !section.buffers.light?.blue
67
+ ? new BinaryBuffer({ buffer: 0 })
68
+ : typeof section.buffers.light.blue == "number"
69
+ ? new BinaryBuffer({ buffer: section.buffers.light.blue })
70
+ : new BinaryBuffer(section.buffers.light.blue),
71
+ },
72
+ state: !section.buffers.state
73
+ ? new BinaryBuffer({ buffer: 0 })
74
+ : typeof section.buffers.state == "number"
75
+ ? new BinaryBuffer({ buffer: section.buffers.state })
76
+ : new BinaryBuffer(section.buffers.state),
77
+ mod: !section.buffers.mod
78
+ ? new BinaryBuffer({ buffer: 0 })
79
+ : typeof section.buffers.mod == "number"
80
+ ? new BinaryBuffer({ buffer: section.buffers.mod })
81
+ : new BinaryBuffer(section.buffers.mod),
82
+ secondary: !section.buffers.secondary
83
+ ? new BinaryBuffer({ buffer: 0 })
84
+ : typeof section.buffers.secondary == "number"
85
+ ? new BinaryBuffer({ buffer: section.buffers.secondary })
86
+ : new BinaryBuffer(section.buffers.secondary),
87
+ },
88
+ idPalette: section.palettes?.id
89
+ ? new NumberPalette(section.palettes?.id)
67
90
  : undefined,
68
- lightPalette: section.palettes.light
69
- ? new NumberPalette(section.palettes.light)
91
+ lightPalette: {
92
+ sun: section.palettes?.light?.sun
93
+ ? new NumberPalette(section.palettes?.light?.sun)
94
+ : null,
95
+ red: section.palettes?.light?.red
96
+ ? new NumberPalette(section.palettes?.light?.red)
97
+ : null,
98
+ green: section.palettes?.light?.green
99
+ ? new NumberPalette(section.palettes?.light?.green)
100
+ : null,
101
+ blue: section.palettes?.light?.blue
102
+ ? new NumberPalette(section.palettes?.light?.blue)
103
+ : null,
104
+ },
105
+ levelPalette: section.palettes?.level
106
+ ? new NumberPalette(section.palettes?.level)
70
107
  : undefined,
71
- statePalette: section.palettes.state
72
- ? new NumberPalette(section.palettes.state)
108
+ statePalette: section.palettes?.state
109
+ ? new NumberPalette(section.palettes?.state)
73
110
  : undefined,
74
- modPalette: section.palettes.mod
75
- ? new NumberPalette(section.palettes.mod)
111
+ modPalette: section.palettes?.mod
112
+ ? new NumberPalette(section.palettes?.mod)
76
113
  : undefined,
77
- secondaryState: section.palettes.secondaryState
78
- ? new NumberPalette(section.palettes.secondaryState)
114
+ secondaryState: section.palettes?.secondaryState
115
+ ? new NumberPalette(section.palettes?.secondaryState)
79
116
  : undefined,
80
- secondaryId: section.palettes.secondaryId
81
- ? new NumberPalette(section.palettes.secondaryId)
117
+ secondaryId: section.palettes?.secondaryId
118
+ ? new NumberPalette(section.palettes?.secondaryId)
82
119
  : undefined,
83
120
  };
84
121
  };
85
- const getId = (value, importedColumn, importedSection) => {
86
- if (importedSection.section.buffers.state instanceof Uint16Array)
87
- return value;
88
- if (typeof importedSection.section.buffers.id == "number") {
89
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.sector.palettes.id[importedSection.section.buffers.id]);
122
+ const getId = (value, importedSector, importedSection) => {
123
+ if (importedSection.buffers.ids.type == "value") {
124
+ return VoxelPalettesRegister.voxels.getNumberId(importedSector.idPalette.getStringId(value));
90
125
  }
91
126
  if (importedSection.idPalette) {
92
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.idPalette.getStringId(importedSection.idPalette.getValue(value)));
127
+ return VoxelPalettesRegister.voxels.getNumberId(importedSector.idPalette.getStringId(importedSection.idPalette.getValue(value)));
93
128
  }
94
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.idPalette.getStringId(value));
129
+ return VoxelPalettesRegister.voxels.getNumberId(importedSector.idPalette.getStringId(value));
95
130
  };
96
- const getLight = (value, importedColumn, importedSection) => {
97
- if (importedSection.section.buffers.light instanceof Uint16Array)
98
- return value;
99
- if (typeof importedSection.section.buffers.light == "number") {
100
- return value;
131
+ const getLight = (index, importedSector, importedSection) => {
132
+ let finalLight = 0;
133
+ for (let l = 0; l < lightSegments.length; l++) {
134
+ const segment = lightSegments[l];
135
+ let value = 0;
136
+ if (importedSection.buffers.light[segment].type == "value") {
137
+ value = importedSection.buffers.light[segment].getValue(index);
138
+ }
139
+ else {
140
+ if (importedSection.buffers.light[segment].type == "4-bit") {
141
+ value = importedSection.buffers.light[segment].getValue(index);
142
+ }
143
+ else {
144
+ if (importedSection.lightPalette[segment]) {
145
+ value = importedSection.lightPalette[segment].getValue(importedSection.buffers.light[segment].getValue(index));
146
+ }
147
+ else if (importedSector.lightPalette[segment]) {
148
+ value = importedSector.lightPalette[segment].getValue(importedSection.buffers.light[segment].getValue(index));
149
+ }
150
+ }
151
+ }
152
+ finalLight = lightSemgnetSet[segment](value, finalLight);
101
153
  }
102
- if (importedSection.lightPalette) {
103
- return importedSection.lightPalette.getValue(value);
154
+ return finalLight;
155
+ };
156
+ const getLevel = (value, importedSector, importedSection) => {
157
+ if (importedSection.levelPalette) {
158
+ return importedSection.levelPalette.getValue(value);
104
159
  }
105
- if (importedColumn.lightPalette) {
106
- return importedColumn.lightPalette.getValue(value);
160
+ if (importedSector.levelPalette) {
161
+ return importedSector.levelPalette.getValue(value);
107
162
  }
108
163
  return value;
109
164
  };
110
- const getState = (voxelId, value, processedState, importedColumn, importedSection) => {
165
+ const getState = (voxelId, value, processedState, importedSector, importedSection) => {
111
166
  const voxelStringId = VoxelPalettesRegister.voxels.getStringId(voxelId);
112
167
  if (!SchemaRegister.hasVoxelSchema(voxelStringId))
113
168
  return value;
@@ -119,16 +174,16 @@ const getState = (voxelId, value, processedState, importedColumn, importedSectio
119
174
  if (importedSection.statePalette) {
120
175
  stateId = importedSection.statePalette.getValue(value);
121
176
  }
122
- else if (importedColumn.statePalette) {
177
+ else if (importedSector.statePalette) {
123
178
  stateId = value;
124
179
  }
125
180
  if (processedState[stateId] !== undefined)
126
181
  return processedState[stateId];
127
- value = SchemaRegister.getVoxelSchemas(voxelStringId).state.fromStateObject(importedColumn.sector.palettes.stateMap[stateId]);
182
+ value = SchemaRegister.getVoxelSchemas(voxelStringId).state.fromStateObject(importedSector.sector.palettes.stateMap[stateId]);
128
183
  processedState[stateId] = value;
129
184
  return value;
130
185
  };
131
- const getMod = (voxelId, value, processedMod, importedColumn, importedSection) => {
186
+ const getMod = (voxelId, value, processedMod, importedSector, importedSection) => {
132
187
  const voxelStringId = VoxelPalettesRegister.voxels.getStringId(voxelId);
133
188
  if (!SchemaRegister.hasVoxelSchema(voxelStringId))
134
189
  return value;
@@ -140,88 +195,94 @@ const getMod = (voxelId, value, processedMod, importedColumn, importedSection) =
140
195
  if (importedSection.modPalette) {
141
196
  modId = importedSection.modPalette.getValue(value);
142
197
  }
143
- else if (importedColumn.modPalette) {
198
+ else if (importedSector.modPalette) {
144
199
  modId = value;
145
200
  }
146
201
  if (processedMod[modId] !== undefined)
147
202
  return processedMod[modId];
148
- value = SchemaRegister.getVoxelSchemas(voxelStringId).mod.fromStateObject(importedColumn.sector.palettes.modMap[modId]);
203
+ value = SchemaRegister.getVoxelSchemas(voxelStringId).mod.fromStateObject(importedSector.sector.palettes.modMap[modId]);
149
204
  processedMod[modId] = value;
150
205
  return value;
151
206
  };
152
- const getSecondary = (voxelId, value, importedColumn, importedSection) => {
207
+ const getSecondary = (voxelId, value, importedSector, importedSection) => {
153
208
  if (VoxelTagsRegister.VoxelTags[voxelId]["dve_can_have_secondary"]) {
154
- if (typeof importedSection.section.buffers.secondary == "number") {
155
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.sector.palettes.secondaryId[importedSection.section.buffers.secondary]);
156
- }
157
209
  if (importedSection.secondaryId) {
158
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.secondaryId.getStringId(importedSection.secondaryId.getValue(value)));
210
+ return VoxelPalettesRegister.voxels.getNumberId(importedSector.secondaryId.getStringId(importedSection.secondaryId.getValue(value)));
159
211
  }
160
- return VoxelPalettesRegister.voxels.getNumberId(importedColumn.sector.palettes.secondaryId[value]);
212
+ return VoxelPalettesRegister.voxels.getNumberId(importedSector.sector.palettes.secondaryId[value]);
161
213
  }
162
214
  if (typeof importedSection.section.buffers.secondary == "number") {
163
215
  return value;
164
216
  }
165
- if (importedSection.secondaryState && importedColumn.secondaryState) {
166
- return importedColumn.secondaryState.getValue(importedSection.secondaryState.getValue(value));
217
+ if (importedSection.secondaryState && importedSector.secondaryState) {
218
+ return importedSector.secondaryState.getValue(importedSection.secondaryState.getValue(value));
167
219
  }
168
- if (importedColumn.secondaryState) {
169
- return importedColumn.secondaryState.getId(value);
220
+ if (importedSector.secondaryState) {
221
+ return importedSector.secondaryState.getId(value);
170
222
  }
171
223
  return value;
172
224
  };
173
- export default function ImportSector(sector, archiveData) {
174
- const newSector = new Sector(Sector.CreateNew());
175
- newSector.position[0] = sector.location[1];
176
- newSector.position[1] = sector.location[2];
177
- newSector.position[2] = sector.location[3];
178
- if (!archiveData.loadColumnState) {
179
- //sectorStructInstance.deserialize(sector.sectorState);
180
- }
181
- else {
182
- archiveData.loadColumnState(sector.sectorState, newSector);
183
- }
184
- const importedSector = getImportedColumnData(sector);
225
+ export default function ImportSector(archivedSector, archiveData) {
226
+ const sector = new Sector(Sector.CreateNew(), [
227
+ archivedSector.location[1],
228
+ archivedSector.location[2],
229
+ archivedSector.location[3],
230
+ ]);
231
+ sector.loadFlags(archivedSector.flags);
232
+ sector.loadTimestamps(archivedSector.timestamps);
233
+ const importedSector = getImportedSectorData(archivedSector);
185
234
  const processedState = {};
186
235
  const processedMod = {};
187
- for (let sectionIndex = 0; sectionIndex < sector.sections.length; sectionIndex++) {
236
+ for (let sectionIndex = 0; sectionIndex < archivedSector.sections.length; sectionIndex++) {
237
+ const archivedSectionValue = archivedSector.sections[sectionIndex];
238
+ const archivedSection = typeof archivedSectionValue == "string"
239
+ ? archivedSector.duplicates?.sections?.[archivedSectionValue]
240
+ : archivedSectionValue;
241
+ const importedSection = getImportedSectionData(archivedSection);
188
242
  const section = sector.sections[sectionIndex];
189
- const importedSection = getImportedSectionData(section);
190
- const newSection = newSector.sections[sectionIndex];
191
- const sectionState = {};
192
- for (let i = 0; i < sector.keys.sectionState.length; i++) {
193
- sectionState[sector.keys.sectionState[i]] = section.state[i];
243
+ archivedSection.flags && section.loadFlags(archivedSection.flags);
244
+ if (!ArrayBuffer.isView(archivedSection.buffers.buried)) {
245
+ for (let i = 0; i < section.buried.length; i++) {
246
+ section.buried[i] = archivedSection.buffers.buried || 0;
247
+ }
248
+ }
249
+ else {
250
+ for (let i = 0; i < section.buried.length; i++) {
251
+ section.buried[i] = archivedSection.buffers.buried[i];
252
+ }
253
+ }
254
+ if (!ArrayBuffer.isView(archivedSection.buffers.voxelMap)) {
255
+ for (let i = 0; i < section.voxelMap.length; i++) {
256
+ section.voxelMap[i] = archivedSection.buffers.voxelMap || 0;
257
+ }
258
+ }
259
+ else {
260
+ for (let i = 0; i < section.voxelMap.length; i++) {
261
+ section.voxelMap[i] = archivedSection.buffers.voxelMap[i];
262
+ }
263
+ }
264
+ if (!ArrayBuffer.isView(archivedSection.buffers.dirtyMap)) {
265
+ for (let i = 0; i < section.dirtyMap.length; i++) {
266
+ section.dirtyMap[i] = archivedSection.buffers.dirtyMap || 0;
267
+ }
268
+ }
269
+ else {
270
+ for (let i = 0; i < section.dirtyMap.length; i++) {
271
+ section.dirtyMap[i] = archivedSection.buffers.dirtyMap[i];
272
+ }
194
273
  }
195
- updateSectionBuffers(sector, section);
196
- /* if (!archiveData.loadSectionState) {
197
- sectionStructInstance.setData(newSection.sectionState);
198
- sectionStructInstance.deserialize(sectionState);
199
- } else {
200
- archiveData.loadSectionState(
201
- sector.keys.sectionState,
202
- section.state,
203
- newSection
204
- );
205
- } */
206
- for (let i = 0; i < newSection.ids.length; i++) {
207
- newSection.ids[i] = getId(typeof section.buffers.id == "number"
208
- ? section.buffers.id
209
- : section.buffers.id[i], importedSector, importedSection);
210
- newSection.light[i] = getLight(typeof section.buffers.light == "number"
211
- ? section.buffers.light
212
- : section.buffers.light[i], importedSector, importedSection);
213
- newSection.secondary[i] = getSecondary(newSection.ids[i], typeof section.buffers.secondary == "number"
214
- ? section.buffers.secondary
215
- : section.buffers.secondary[i], importedSector, importedSection);
216
- let secondary = VoxelTagsRegister.VoxelTags[newSection.ids[i]]["dve_can_have_secondary"] && newSection.secondary[i] > 0;
217
- newSection.state[i] = getState(secondary ? newSection.secondary[i] : newSection.ids[i], typeof section.buffers.state == "number"
218
- ? section.buffers.state
219
- : section.buffers.state[i], processedState, importedSector, importedSection);
220
- newSection.mod[i] = getMod(secondary ? newSection.secondary[i] : newSection.ids[i], typeof section.buffers.mod == "number"
221
- ? section.buffers.mod
222
- : section.buffers.mod[i], processedMod, importedSector, importedSection);
274
+ for (let i = 0; i < section.ids.length; i++) {
275
+ section.ids[i] = getId(importedSection.buffers.ids.getValue(i), importedSector, importedSection);
276
+ section.level[i] = getLevel(importedSection.buffers.level.getValue(i), importedSector, importedSection);
277
+ section.light[i] = getLight(i, importedSector, importedSection);
278
+ section.secondary[i] = getSecondary(section.ids[i], importedSection.buffers.secondary.getValue(i), importedSector, importedSection);
279
+ let secondary = VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"] &&
280
+ section.secondary[i] > 0;
281
+ section.state[i] = getState(secondary ? section.secondary[i] : section.ids[i], importedSection.buffers.state.getValue(i), processedState, importedSector, importedSection);
282
+ section.mod[i] = getMod(secondary ? section.secondary[i] : section.ids[i], importedSection.buffers.mod.getValue(i), processedMod, importedSector, importedSection);
223
283
  }
224
- newSector.sections[sectionIndex] = newSection;
284
+ sector.sections[sectionIndex] = section;
225
285
  }
226
- return newSector;
286
+ sector.setBitFlag(Sector.FlagIds.isStored, true);
287
+ return sector;
227
288
  }
@@ -0,0 +1,6 @@
1
+ import { ArchivedLightSegments, ArchivedSectionData } from "../Archive.types";
2
+ export declare const lightSegments: ArchivedLightSegments[];
3
+ export declare const lightSemgnetGet: Record<ArchivedLightSegments, (value: number) => number>;
4
+ export declare const lightSemgnetSet: Record<ArchivedLightSegments, (value: number, source: number) => number>;
5
+ export declare function uint16To4CharString(value: number): string;
6
+ export declare function compareSection(section1: ArchivedSectionData, section2: ArchivedSectionData): boolean;
@@ -0,0 +1,75 @@
1
+ import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData";
2
+ const lightData = new VoxelLightData();
3
+ export const lightSegments = [
4
+ "sun",
5
+ "red",
6
+ "green",
7
+ "blue",
8
+ ];
9
+ export const lightSemgnetGet = {
10
+ sun: (value) => lightData.getS(value),
11
+ red: (value) => lightData.getR(value),
12
+ green: (value) => lightData.getG(value),
13
+ blue: (value) => lightData.getB(value),
14
+ };
15
+ export const lightSemgnetSet = {
16
+ sun: (value, source) => lightData.setS(value, source),
17
+ red: (value, source) => lightData.setR(value, source),
18
+ green: (value, source) => lightData.setG(value, source),
19
+ blue: (value, source) => lightData.setB(value, source),
20
+ };
21
+ const charset = "0123456789ABCDEF";
22
+ export function uint16To4CharString(value) {
23
+ if (value < 0 || value > 0xffff) {
24
+ throw new RangeError("Value must be a 16-bit unsigned integer.");
25
+ }
26
+ const chars = [];
27
+ for (let i = 0; i < 4; i++) {
28
+ const charCode = (value >> (i * 4)) & 0x0f;
29
+ chars.unshift(charset[charCode]);
30
+ }
31
+ const result = chars.join("").replace(/^0+(?!$)/, "");
32
+ return result;
33
+ }
34
+ function traverseSection(source, target) {
35
+ for (const key in source) {
36
+ if (!(key in target))
37
+ return false;
38
+ const sourceValue = source[key];
39
+ const targetValue = target[key];
40
+ if (!ArrayBuffer.isView(sourceValue) &&
41
+ typeof sourceValue === "object" &&
42
+ sourceValue !== null &&
43
+ !ArrayBuffer.isView(targetValue) &&
44
+ typeof targetValue == "object" &&
45
+ targetValue !== null) {
46
+ if (!traverseSection(sourceValue, targetValue))
47
+ return false;
48
+ continue;
49
+ }
50
+ if (typeof sourceValue === "number" ||
51
+ typeof sourceValue === "string" ||
52
+ typeof targetValue === "number" ||
53
+ typeof targetValue === "string") {
54
+ if (sourceValue !== targetValue)
55
+ return false;
56
+ continue;
57
+ }
58
+ if (sourceValue instanceof Uint8Array ||
59
+ sourceValue instanceof Uint16Array) {
60
+ if (!(targetValue instanceof sourceValue.constructor))
61
+ return false;
62
+ if (sourceValue.length !== targetValue.length)
63
+ return false;
64
+ let target = targetValue;
65
+ for (let i = 0; i < target.length; i++) {
66
+ if (sourceValue[i] != target[i])
67
+ return false;
68
+ }
69
+ }
70
+ }
71
+ return true;
72
+ }
73
+ export function compareSection(section1, section2) {
74
+ return traverseSection(section1, section2);
75
+ }
@@ -11,27 +11,37 @@ function runArchiveSector(location) {
11
11
  location: location,
12
12
  });
13
13
  const transfers = [];
14
- if (archived.palettes.light)
15
- transfers.push(archived.palettes.light.buffer);
14
+ // if (archived.palettes.light) transfers.push(archived.palettes.light.buffer);
16
15
  if (archived.palettes.state)
17
16
  transfers.push(archived.palettes.state.buffer);
18
17
  if (archived.palettes.secondaryState)
19
18
  transfers.push(archived.palettes.secondaryState.buffer);
20
19
  for (const section of archived.sections) {
21
- if (typeof section.buffers.id != "number")
20
+ if (typeof section == "string")
21
+ continue;
22
+ if (ArrayBuffer.isView(section.buffers.id?.buffer))
22
23
  transfers.push(section.buffers.id.buffer);
23
- if (typeof section.buffers.light != "number")
24
- transfers.push(section.buffers.light.buffer);
25
- if (typeof section.buffers.state != "number")
24
+ if (ArrayBuffer.isView(section.buffers.state?.buffer))
26
25
  transfers.push(section.buffers.state.buffer);
27
- if (typeof section.buffers.secondary != "number")
28
- transfers.push(section.buffers.secondary.buffer);
29
- if (typeof section.buffers.mod != "number")
26
+ if (ArrayBuffer.isView(section.buffers.mod?.buffer))
30
27
  transfers.push(section.buffers.mod.buffer);
28
+ if (ArrayBuffer.isView(section.buffers.state?.buffer))
29
+ transfers.push(section.buffers.state.buffer);
30
+ if (ArrayBuffer.isView(section.buffers.light?.sun?.buffer))
31
+ transfers.push((section.buffers.light?.sun).buffer);
32
+ if (ArrayBuffer.isView(section.buffers.light?.red?.buffer))
33
+ transfers.push((section.buffers.light?.red).buffer);
34
+ if (ArrayBuffer.isView(section.buffers.light?.green?.buffer))
35
+ transfers.push((section.buffers.light?.green).buffer);
36
+ if (ArrayBuffer.isView(section.buffers.light?.blue?.buffer))
37
+ transfers.push((section.buffers.light?.blue).buffer);
38
+ if (ArrayBuffer.isView(section.buffers.secondary?.buffer))
39
+ transfers.push(section.buffers.secondary.buffer);
40
+ if (!section.palettes)
41
+ continue;
31
42
  if (section.palettes.id)
32
43
  transfers.push(section.palettes.id.buffer);
33
- if (section.palettes.light)
34
- transfers.push(section.palettes.light.buffer);
44
+ // if (section.palettes.light) transfers.push(section.palettes.light.buffer);
35
45
  if (section.palettes.state)
36
46
  transfers.push(section.palettes.state.buffer);
37
47
  if (section.palettes.mod)
@@ -49,8 +59,15 @@ export default function InitTasks(props) {
49
59
  });
50
60
  Threads.registerTask("archive-sector-binary", async (location) => {
51
61
  const [archived] = runArchiveSector(location);
52
- const compressed = await compressBinaryObject(archived);
53
- return [compressed, [compressed]];
62
+ try {
63
+ const compressed = await compressBinaryObject(archived);
64
+ return [compressed, [compressed]];
65
+ }
66
+ catch (error) {
67
+ console.log(archived);
68
+ console.error(error);
69
+ }
70
+ return [null, []];
54
71
  });
55
72
  Threads.registerTask("import-sector", async (archived) => {
56
73
  const importedSector = ImportSector(archived, {});
@@ -1,9 +1,9 @@
1
1
  import { WorldVoxelCursor } from "./WorldVoxelCursor";
2
2
  import { Vector3Like } from "@amodx/math";
3
- import { DataCursorInterface } from "../../Tools/DataCursor.interface";
3
+ import { DataCursorInterface } from "../../Voxels/Cursor/DataCursor.interface";
4
4
  import { WorldSectionCursorInterface } from "./WorldSectionCursor.interface";
5
5
  import type { Section } from "../Section/index";
6
- export declare class SectionCursor extends DataCursorInterface implements WorldSectionCursorInterface {
6
+ export declare class SectionCursor implements DataCursorInterface, WorldSectionCursorInterface {
7
7
  _section: Section | null;
8
8
  private voxel;
9
9
  _voxelIndex: number;
@@ -2,8 +2,7 @@ import { WorldRegister } from "../WorldRegister";
2
2
  import { WorldVoxelCursor } from "./WorldVoxelCursor";
3
3
  import { WorldSpaces } from "../WorldSpaces";
4
4
  import { Vector3Like } from "@amodx/math";
5
- import { DataCursorInterface } from "../../Tools/DataCursor.interface";
6
- export class SectionCursor extends DataCursorInterface {
5
+ export class SectionCursor {
7
6
  _section;
8
7
  voxel = new WorldVoxelCursor(this);
9
8
  _voxelIndex = 0;
@@ -39,7 +38,7 @@ export class SectionCursor extends DataCursorInterface {
39
38
  const sector = WorldRegister.sectors.get(sectionOrDimension, x || 0, y || 0, z || 0);
40
39
  if (!sector)
41
40
  return false;
42
- this._section = sector.getSection(y || 0);
41
+ this._section = sector.getSection(x || 0, y || 0, z || 0);
43
42
  const sectionPos = this._section.getPosition();
44
43
  this._sectionPosition.x = sectionPos[0];
45
44
  this._sectionPosition.y = sectionPos[1];
@@ -2,9 +2,9 @@ import type { Section } from "../Section/index";
2
2
  import type { Sector } from "../Sector/index";
3
3
  import { WorldVoxelCursor } from "./WorldVoxelCursor";
4
4
  import { Vector3Like } from "@amodx/math";
5
- import { DataCursorInterface } from "../../Tools/DataCursor.interface";
5
+ import { DataCursorInterface } from "../../Voxels/Cursor/DataCursor.interface";
6
6
  import { WorldSectionCursorInterface } from "./WorldSectionCursor.interface";
7
- export declare class SectorCursor extends DataCursorInterface implements WorldSectionCursorInterface {
7
+ export declare class SectorCursor implements DataCursorInterface, WorldSectionCursorInterface {
8
8
  _current: Sector | null;
9
9
  _section: Section | null;
10
10
  private voxel;
@@ -2,8 +2,7 @@ import { WorldRegister } from "../WorldRegister";
2
2
  import { WorldVoxelCursor } from "./WorldVoxelCursor";
3
3
  import { WorldSpaces } from "../WorldSpaces";
4
4
  import { Vector3Like } from "@amodx/math";
5
- import { DataCursorInterface } from "../../Tools/DataCursor.interface";
6
- export class SectorCursor extends DataCursorInterface {
5
+ export class SectorCursor {
7
6
  _current = null;
8
7
  _section;
9
8
  voxel = new WorldVoxelCursor(this);