@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,50 +1,65 @@
1
1
  import { StringPalette } from "../../../Util/StringPalette";
2
2
  import { NumberPalette } from "../../../Util/NumberPalette";
3
3
  import { WorldRegister } from "../../../World/WorldRegister";
4
- import { convertToPaletteBuffer } 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";
7
+ import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData";
8
+ import { EngineSettings } from "../../../Settings/EngineSettings";
9
+ import { setNibbleArrayIndex } from "../../../Util/Binary/BinaryArrays";
10
+ import { BinaryBuffer } from "../../../Util/Binary/BinaryBuffer";
11
+ import { compareSection, lightSegments, lightSemgnetGet, uint16To4CharString, } from "./Shared";
12
+ function getProcessedData(buffer) {
13
+ return {
14
+ buffer,
15
+ allTheSame: true,
16
+ isPaletted: false,
17
+ remapped: false,
18
+ value: 0,
19
+ };
20
+ }
8
21
  const getProcessedSection = (section) => {
9
22
  return {
10
- section,
23
+ original: section,
11
24
  palettes: getSectionPalettes(),
25
+ isBuriedAllTheSame: false,
26
+ buriedValue: 0,
27
+ isVoxelMapAllTheSame: false,
28
+ voxelMapValue: 0,
29
+ isDirtyMapAllTheSame: false,
30
+ dirtyMapValue: 0,
12
31
  // ids
13
- ids: new Uint16Array(section.ids.length),
14
- idsAllTheSame: true,
15
- remappedIds: false,
32
+ ids: getProcessedData(new Uint16Array(section.ids.length)),
16
33
  // light
17
- light: new Uint16Array(section.light.length),
18
- lightAllTheSame: true,
19
- isLightPaletted: false,
20
- remappedLight: false,
34
+ light: {
35
+ sun: getProcessedData(new Uint8Array(section.light.length)),
36
+ red: getProcessedData(new Uint8Array(section.light.length)),
37
+ green: getProcessedData(new Uint8Array(section.light.length)),
38
+ blue: getProcessedData(new Uint8Array(section.light.length)),
39
+ },
21
40
  // level
22
- level: new Uint8Array(section.level.length),
23
- levelAllTheSame: true,
24
- isLevelPaletted: false,
25
- remappedLevel: false,
41
+ level: getProcessedData(new Uint8Array(section.level.length)),
26
42
  // state
27
- state: new Uint16Array(section.state.length),
28
- stateAllTheSame: true,
29
- isStatePaletted: false,
30
- remappedState: false,
43
+ state: getProcessedData(new Uint16Array(section.level.length)),
31
44
  // mod
32
- mod: new Uint16Array(section.mod.length),
33
- modAllTheSame: true,
34
- isModPaletted: false,
35
- remappedMod: false,
45
+ mod: getProcessedData(new Uint16Array(section.mod.length)),
36
46
  // secondary
37
- secondary: new Uint16Array(section.secondary.length),
38
- isSecondaryPaletted: false,
39
- secondaryAllTheSame: true,
40
- remappedSecondary: false,
47
+ secondary: getProcessedData(new Uint16Array(section.mod.length)),
41
48
  };
42
49
  };
50
+ function getLightPalette() {
51
+ return {
52
+ sun: new NumberPalette(),
53
+ red: new NumberPalette(),
54
+ green: new NumberPalette(),
55
+ blue: new NumberPalette(),
56
+ };
57
+ }
43
58
  function getSectionPalettes() {
44
59
  return {
45
60
  ids: new NumberPalette(),
46
61
  level: new NumberPalette(),
47
- light: new NumberPalette(),
62
+ light: getLightPalette(),
48
63
  state: new NumberPalette(),
49
64
  mod: new NumberPalette(),
50
65
  secondaryId: new NumberPalette(),
@@ -55,7 +70,7 @@ function getColumnPalettes() {
55
70
  return {
56
71
  ids: new StringPalette(),
57
72
  level: new NumberPalette(),
58
- light: new NumberPalette(),
73
+ light: getLightPalette(),
59
74
  stateIdMap: [],
60
75
  state: new NumberPalette(),
61
76
  modIdMap: [],
@@ -64,69 +79,251 @@ function getColumnPalettes() {
64
79
  secondaryState: new NumberPalette(),
65
80
  };
66
81
  }
82
+ function getLightBuffer(light, buffer) {
83
+ const array = new Uint8Array(buffer.length / 2);
84
+ for (let i = 0; i < buffer.length; i++) {
85
+ let l = 0;
86
+ if (light == "sun")
87
+ l = lightData.getS(buffer[i]);
88
+ if (light == "red")
89
+ l = lightData.getR(buffer[i]);
90
+ if (light == "green")
91
+ l = lightData.getG(buffer[i]);
92
+ if (light == "blue")
93
+ l = lightData.getB(buffer[i]);
94
+ setNibbleArrayIndex(array, i, l);
95
+ }
96
+ return array;
97
+ }
67
98
  function GetArchivedSection(archiveSection, sectorPalettes) {
68
99
  const palettes = {};
69
- if (archiveSection.remappedIds)
100
+ if (archiveSection.ids.remapped)
70
101
  palettes.id = Uint16Array.from(archiveSection.palettes.ids._palette);
71
- if (archiveSection.remappedLevel)
102
+ if (archiveSection.level.remapped)
72
103
  palettes.level = Uint8Array.from(archiveSection.palettes.level._palette);
73
- if (archiveSection.remappedLight)
74
- palettes.light = Uint16Array.from(archiveSection.palettes.light._palette);
75
- if (archiveSection.remappedState)
104
+ if (archiveSection.light.sun.remapped) {
105
+ palettes.light ??= {};
106
+ palettes.light.sun = Uint8Array.from(archiveSection.palettes.light.sun._palette);
107
+ }
108
+ if (archiveSection.light.red.remapped) {
109
+ palettes.light ??= {};
110
+ palettes.light.red = Uint8Array.from(archiveSection.palettes.light.red._palette);
111
+ }
112
+ if (archiveSection.light.green.remapped) {
113
+ palettes.light ??= {};
114
+ palettes.light.green = Uint8Array.from(archiveSection.palettes.light.green._palette);
115
+ }
116
+ if (archiveSection.light.blue.remapped) {
117
+ palettes.light ??= {};
118
+ palettes.light.blue = Uint8Array.from(archiveSection.palettes.light.blue._palette);
119
+ }
120
+ if (archiveSection.state.remapped)
76
121
  palettes.state = Uint16Array.from(archiveSection.palettes.state._palette);
77
- if (archiveSection.remappedMod)
122
+ if (archiveSection.mod.remapped)
78
123
  palettes.mod = Uint16Array.from(archiveSection.palettes.mod._palette);
79
- if (archiveSection.remappedSecondary) {
124
+ if (archiveSection.secondary.remapped) {
80
125
  palettes.secondaryId = Uint16Array.from(archiveSection.palettes.secondaryId._palette);
81
126
  palettes.secondaryState = Uint16Array.from(archiveSection.palettes.secondaryState._palette);
82
127
  }
128
+ const buffers = {};
129
+ //id
130
+ if (archiveSection.ids.allTheSame) {
131
+ if (archiveSection.ids.buffer[0] !== 0) {
132
+ buffers.id = archiveSection.ids.buffer[0];
133
+ }
134
+ }
135
+ else if (archiveSection.ids.isPaletted) {
136
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.ids.remapped
137
+ ? archiveSection.palettes.ids.size
138
+ : sectorPalettes.ids.size);
139
+ buffers.id = BinaryBuffer.Create({
140
+ buffer: BinaryBuffer.Convert(archiveSection.ids.buffer, "16-bit", type),
141
+ type,
142
+ });
143
+ }
144
+ else {
145
+ buffers.id = BinaryBuffer.Create({
146
+ buffer: archiveSection.ids.buffer,
147
+ });
148
+ }
149
+ //level
150
+ if (archiveSection.level.allTheSame) {
151
+ if (archiveSection.level.buffer[0] !== 0) {
152
+ buffers.level = archiveSection.level.buffer[0];
153
+ }
154
+ }
155
+ else if (archiveSection.level.isPaletted) {
156
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.level.remapped
157
+ ? archiveSection.palettes.level.size
158
+ : sectorPalettes.level.size);
159
+ buffers.level = BinaryBuffer.Create({
160
+ buffer: BinaryBuffer.Convert(archiveSection.level.buffer, "8-bit", type),
161
+ type,
162
+ });
163
+ }
164
+ else {
165
+ buffers.level = BinaryBuffer.Create({
166
+ buffer: archiveSection.original.level.slice(),
167
+ });
168
+ }
169
+ for (const semgnet of lightSegments) {
170
+ if (archiveSection.light[semgnet].allTheSame) {
171
+ if (archiveSection.light[semgnet].value !== 0) {
172
+ buffers.light ??= {};
173
+ buffers.light[semgnet] = archiveSection.light[semgnet].value;
174
+ }
175
+ }
176
+ else if (archiveSection.light[semgnet].isPaletted) {
177
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.light[semgnet].remapped
178
+ ? archiveSection.palettes.light[semgnet].size
179
+ : sectorPalettes.light[semgnet].size);
180
+ buffers.light ??= {};
181
+ buffers.light[semgnet] = BinaryBuffer.Create({
182
+ buffer: BinaryBuffer.Convert(archiveSection.light[semgnet].buffer, "8-bit", type),
183
+ type,
184
+ });
185
+ }
186
+ else {
187
+ buffers.light ??= {};
188
+ buffers.light[semgnet] = BinaryBuffer.Create({
189
+ buffer: getLightBuffer(semgnet, archiveSection.original.light),
190
+ type: "4-bit",
191
+ });
192
+ }
193
+ }
194
+ if (archiveSection.state.allTheSame) {
195
+ if (archiveSection.state.buffer[0] !== 0) {
196
+ buffers.state = archiveSection.state.buffer[0];
197
+ }
198
+ }
199
+ else if (archiveSection.state.isPaletted) {
200
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.state.remapped
201
+ ? archiveSection.palettes.state.size
202
+ : sectorPalettes.state.size);
203
+ buffers.state = BinaryBuffer.Create({
204
+ buffer: BinaryBuffer.Convert(archiveSection.state.buffer, "16-bit", type),
205
+ type,
206
+ });
207
+ }
208
+ else {
209
+ buffers.state = BinaryBuffer.Create({
210
+ buffer: archiveSection.state.buffer,
211
+ });
212
+ }
213
+ if (archiveSection.mod.allTheSame) {
214
+ if (archiveSection.mod.buffer[0] !== 0) {
215
+ buffers.mod = archiveSection.mod.buffer[0];
216
+ }
217
+ }
218
+ else if (archiveSection.mod.isPaletted) {
219
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.mod.remapped
220
+ ? archiveSection.palettes.mod.size
221
+ : sectorPalettes.mod.size);
222
+ buffers.mod = BinaryBuffer.Create({
223
+ buffer: BinaryBuffer.Convert(archiveSection.mod.buffer, "16-bit", type),
224
+ type,
225
+ });
226
+ }
227
+ else {
228
+ buffers.mod = BinaryBuffer.Create({
229
+ buffer: archiveSection.mod.buffer,
230
+ });
231
+ }
232
+ if (archiveSection.secondary.allTheSame) {
233
+ if (archiveSection.secondary.buffer[0] !== 0) {
234
+ buffers.secondary = archiveSection.secondary.buffer[0];
235
+ }
236
+ }
237
+ else if (archiveSection.secondary.isPaletted) {
238
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.secondary.remapped
239
+ ? Math.max(archiveSection.palettes.secondaryState.size, archiveSection.palettes.secondaryId.size)
240
+ : Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size));
241
+ buffers.secondary = BinaryBuffer.Create({
242
+ buffer: BinaryBuffer.Convert(archiveSection.secondary.buffer, "16-bit", type),
243
+ type,
244
+ });
245
+ }
246
+ else {
247
+ buffers.secondary = BinaryBuffer.Create({
248
+ buffer: archiveSection.secondary.buffer,
249
+ });
250
+ }
251
+ if (archiveSection.isBuriedAllTheSame) {
252
+ if (archiveSection.buriedValue !== 0) {
253
+ buffers.buried = archiveSection.buriedValue;
254
+ }
255
+ }
256
+ else {
257
+ buffers.buried = archiveSection.original.buried.slice();
258
+ }
259
+ if (archiveSection.isVoxelMapAllTheSame) {
260
+ if (archiveSection.voxelMapValue !== 0) {
261
+ buffers.voxelMap = archiveSection.voxelMapValue;
262
+ }
263
+ }
264
+ else {
265
+ buffers.voxelMap = archiveSection.original.voxelMap.slice();
266
+ }
267
+ if (archiveSection.isDirtyMapAllTheSame) {
268
+ if (archiveSection.dirtyMapValue !== 0) {
269
+ buffers.dirtyMap = archiveSection.dirtyMapValue;
270
+ }
271
+ }
272
+ else {
273
+ buffers.dirtyMap = archiveSection.original.dirtyMap.slice();
274
+ }
275
+ const flags = archiveSection.original.storeFlags();
83
276
  return {
84
- state: {},
85
- palettes,
86
- buffers: {
87
- id: archiveSection.idsAllTheSame
88
- ? archiveSection.ids[0]
89
- : convertToPaletteBuffer(archiveSection.remappedIds
90
- ? archiveSection.palettes.ids.size
91
- : sectorPalettes.ids.size, archiveSection.ids),
92
- level: archiveSection.isLevelPaletted
93
- ? archiveSection.level[0]
94
- : archiveSection.isLevelPaletted
95
- ? convertToPaletteBuffer(archiveSection.remappedLevel
96
- ? archiveSection.palettes.level.size
97
- : sectorPalettes.level.size, archiveSection.level)
98
- : new Uint8Array(archiveSection.section.level.slice()),
99
- light: archiveSection.lightAllTheSame
100
- ? archiveSection.light[0]
101
- : archiveSection.isLightPaletted
102
- ? convertToPaletteBuffer(archiveSection.remappedLight
103
- ? archiveSection.palettes.light.size
104
- : sectorPalettes.light.size, archiveSection.light)
105
- : new Uint16Array(archiveSection.section.light.slice()),
106
- state: archiveSection.stateAllTheSame
107
- ? archiveSection.state[0]
108
- : archiveSection.isStatePaletted
109
- ? convertToPaletteBuffer(archiveSection.remappedState
110
- ? archiveSection.palettes.state.size
111
- : sectorPalettes.state.size, archiveSection.state)
112
- : new Uint16Array(archiveSection.section.state.slice()),
113
- mod: archiveSection.modAllTheSame
114
- ? archiveSection.mod[0]
115
- : archiveSection.isModPaletted
116
- ? convertToPaletteBuffer(archiveSection.remappedMod
117
- ? archiveSection.palettes.mod.size
118
- : sectorPalettes.mod.size, archiveSection.mod)
119
- : new Uint16Array(archiveSection.section.mod.slice()),
120
- secondary: archiveSection.secondaryAllTheSame
121
- ? archiveSection.secondary[0]
122
- : archiveSection.isSecondaryPaletted
123
- ? convertToPaletteBuffer(archiveSection.remappedSecondary
124
- ? Math.max(archiveSection.palettes.secondaryState.size, archiveSection.palettes.secondaryId.size)
125
- : Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size), archiveSection.secondary)
126
- : new Uint16Array(archiveSection.secondary),
127
- },
277
+ ...(Object.keys(flags).length ? { flags } : {}),
278
+ ...(Object.keys(palettes).length ? { palettes } : {}),
279
+ buffers,
280
+ };
281
+ }
282
+ function RemoveDuplicates(data) {
283
+ const duplicateSectionMap = new Map();
284
+ let duplicateSections = [];
285
+ for (let i = 0; i < data.sections.length; i++) {
286
+ for (let j = 0; j < data.sections.length; j++) {
287
+ const section1 = data.sections[i];
288
+ const section2 = data.sections[j];
289
+ if (i == j)
290
+ continue;
291
+ if (typeof section1 == "string" || typeof section2 == "string")
292
+ continue;
293
+ let index = -1;
294
+ if (compareSection(section1, section2)) {
295
+ if (duplicateSectionMap.has(section2)) {
296
+ index = duplicateSectionMap.get(section2)[1];
297
+ }
298
+ else {
299
+ let found = false;
300
+ for (let k = 0; k < duplicateSections.length; k++) {
301
+ if (compareSection(section1, duplicateSections[k])) {
302
+ index = k;
303
+ found = true;
304
+ }
305
+ }
306
+ if (!found) {
307
+ duplicateSections.push(section1);
308
+ index = duplicateSections.length - 1;
309
+ }
310
+ }
311
+ duplicateSectionMap.set(section1, [i, index]);
312
+ }
313
+ }
314
+ }
315
+ const sections = {};
316
+ for (const [object, [sectionIndex, index]] of duplicateSectionMap) {
317
+ const id = uint16To4CharString(index);
318
+ if (!sections[id])
319
+ sections[id] = object;
320
+ data.sections[sectionIndex] = id;
321
+ }
322
+ data.duplicates = {
323
+ sections,
128
324
  };
129
325
  }
326
+ const lightData = new VoxelLightData();
130
327
  export default function ArchiveSector(archiveData) {
131
328
  const sector = WorldRegister.sectors.get(archiveData.location[0], archiveData.location[1], archiveData.location[2], archiveData.location[3]);
132
329
  if (!sector)
@@ -134,23 +331,61 @@ export default function ArchiveSector(archiveData) {
134
331
  const sectorPalettes = getColumnPalettes();
135
332
  const processedSections = [];
136
333
  for (const section of sector.sections) {
137
- const length = section.ids.length;
138
- let firstId = -1;
139
- let firstLight = -1;
140
- let firstLevel = -1;
141
- let firstState = -1;
142
- let firstMod = -1;
143
- let firstSecondary = -1;
144
334
  const processedSection = getProcessedSection(section);
335
+ {
336
+ let value = section.buried[0];
337
+ processedSection.isBuriedAllTheSame = true;
338
+ for (let i = 0; i < section.buried.length; i++) {
339
+ if (value != section.buried[i]) {
340
+ processedSection.isBuriedAllTheSame = false;
341
+ break;
342
+ }
343
+ }
344
+ processedSection.buriedValue = value;
345
+ }
346
+ {
347
+ let value = section.voxelMap[0];
348
+ processedSection.isVoxelMapAllTheSame = true;
349
+ for (let i = 0; i < section.voxelMap.length; i++) {
350
+ if (value != section.voxelMap[i]) {
351
+ processedSection.isVoxelMapAllTheSame = false;
352
+ break;
353
+ }
354
+ }
355
+ processedSection.voxelMapValue = value;
356
+ }
357
+ {
358
+ let value = section.dirtyMap[0];
359
+ processedSection.isDirtyMapAllTheSame = true;
360
+ for (let i = 0; i < section.dirtyMap.length; i++) {
361
+ if (value != section.dirtyMap[i]) {
362
+ processedSection.isDirtyMapAllTheSame = false;
363
+ break;
364
+ }
365
+ }
366
+ processedSection.dirtyMapValue = value;
367
+ }
368
+ const firstId = section.ids[0];
369
+ const firstLight = section.light[0];
370
+ const firstLevel = section.level[0];
371
+ const firstState = section.state[0];
372
+ const firstMod = section.mod[0];
373
+ const firstSecondary = section.secondary[0];
374
+ const firstLightLevels = {
375
+ sun: lightData.getS(firstLight),
376
+ red: lightData.getR(firstLight),
377
+ green: lightData.getG(firstLight),
378
+ blue: lightData.getB(firstLight),
379
+ };
380
+ const length = section.ids.length;
145
381
  for (let i = 0; i < length; i++) {
146
382
  const stringId = VoxelPalettesRegister.voxels.getStringId(section.ids[i]);
147
383
  const voxelId = !sectorPalettes.ids.isRegistered(stringId)
148
384
  ? sectorPalettes.ids.register(stringId)
149
385
  : sectorPalettes.ids.getNumberId(stringId);
386
+ processedSection.ids.value = voxelId;
150
387
  if (!processedSection.palettes.ids.isRegistered(voxelId))
151
388
  processedSection.palettes.ids.register(voxelId);
152
- if (firstId == -1)
153
- firstId = voxelId;
154
389
  const secondaryId = VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"] &&
155
390
  VoxelPalettesRegister.voxels.getStringId(section.secondary[i]);
156
391
  const voxelSecondary = secondaryId
@@ -160,20 +395,19 @@ export default function ArchiveSector(archiveData) {
160
395
  : !sectorPalettes.secondaryState.isRegistered(section.secondary[i])
161
396
  ? sectorPalettes.secondaryState.register(section.secondary[i])
162
397
  : sectorPalettes.secondaryState.getId(section.secondary[i]);
163
- secondaryId
164
- ? !processedSection.palettes.secondaryId.isRegistered(voxelSecondary) &&
165
- processedSection.palettes.secondaryId.register(voxelSecondary)
166
- : !processedSection.palettes.secondaryState.isRegistered(voxelSecondary) &&
398
+ if (VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"]) {
399
+ if (!processedSection.palettes.secondaryId.isRegistered(voxelSecondary))
400
+ processedSection.palettes.secondaryId.register(voxelSecondary);
401
+ }
402
+ else {
403
+ if (!processedSection.palettes.secondaryState.isRegistered(voxelSecondary))
167
404
  processedSection.palettes.secondaryState.register(voxelSecondary);
168
- if (firstSecondary == -1)
169
- firstSecondary = section.secondary[i];
405
+ }
170
406
  const voxelLevel = !sectorPalettes.level.isRegistered(section.level[i])
171
407
  ? sectorPalettes.level.register(section.level[i])
172
408
  : sectorPalettes.level.getId(section.level[i]);
173
409
  if (!processedSection.palettes.level.isRegistered(section.level[i]))
174
410
  processedSection.palettes.level.register(section.level[i]);
175
- if (firstLevel == -1)
176
- firstLevel = voxelLevel;
177
411
  let voxelState = -1;
178
412
  if (!sectorPalettes.state.isRegistered(section.state[i])) {
179
413
  voxelState = sectorPalettes.state.register(section.state[i]);
@@ -186,12 +420,10 @@ export default function ArchiveSector(archiveData) {
186
420
  }
187
421
  if (!processedSection.palettes.state.isRegistered(voxelState))
188
422
  processedSection.palettes.state.register(voxelState);
189
- if (firstState == -1)
190
- firstState = voxelState;
191
423
  let voxelMod = -1;
192
424
  if (!sectorPalettes.mod.isRegistered(section.mod[i])) {
193
425
  voxelMod = sectorPalettes.mod.register(section.mod[i]);
194
- sectorPalettes.stateIdMap[voxelMod] = secondaryId
426
+ sectorPalettes.modIdMap[voxelMod] = secondaryId
195
427
  ? section.secondary[i]
196
428
  : section.ids[i];
197
429
  }
@@ -200,91 +432,141 @@ export default function ArchiveSector(archiveData) {
200
432
  }
201
433
  if (!processedSection.palettes.mod.isRegistered(voxelMod))
202
434
  processedSection.palettes.mod.register(voxelMod);
203
- if (firstMod == -1)
204
- firstMod = voxelMod;
205
- const voxelLight = !sectorPalettes.light.isRegistered(section.light[i])
206
- ? sectorPalettes.light.register(section.light[i])
207
- : sectorPalettes.light.getId(section.light[i]);
208
- if (!processedSection.palettes.light.isRegistered(section.light[i]))
209
- processedSection.palettes.light.register(section.light[i]);
210
- if (firstLight == -1)
211
- firstLight = voxelLight;
212
- if (voxelId != firstId)
213
- processedSection.idsAllTheSame = false;
214
- if (voxelLevel != firstLevel)
215
- processedSection.levelAllTheSame = false;
216
- if (voxelState != firstState)
217
- processedSection.stateAllTheSame = false;
218
- if (voxelMod != firstMod)
219
- processedSection.modAllTheSame = false;
220
- if (voxelLight != firstLight)
221
- processedSection.lightAllTheSame = false;
222
- if (voxelSecondary != firstSecondary)
223
- processedSection.secondaryAllTheSame = false;
224
- processedSection.ids[i] = voxelId;
225
- processedSection.level[i] = voxelLevel;
226
- processedSection.state[i] = voxelState;
227
- processedSection.mod[i] = voxelMod;
228
- processedSection.secondary[i] = voxelSecondary;
229
- processedSection.light[i] = voxelLight;
435
+ for (let l = 0; l < lightSegments.length; l++) {
436
+ const segment = lightSegments[l];
437
+ const light = lightSemgnetGet[segment](section.light[i]);
438
+ if (light != firstLightLevels[segment])
439
+ processedSection.light[segment].allTheSame = false;
440
+ processedSection.light[segment].value = light;
441
+ const voxelLight = !sectorPalettes.light[segment].isRegistered(light)
442
+ ? sectorPalettes.light[segment].register(light)
443
+ : sectorPalettes.light[segment].getId(light);
444
+ if (!processedSection.palettes.light[segment].isRegistered(light))
445
+ processedSection.palettes.light[segment].register(light);
446
+ processedSection.light[segment].buffer[i] = voxelLight;
447
+ }
448
+ if (section.ids[i] != firstId)
449
+ processedSection.ids.allTheSame = false;
450
+ if (section.level[i] != firstLevel)
451
+ processedSection.level.allTheSame = false;
452
+ if (section.state[i] != firstState)
453
+ processedSection.state.allTheSame = false;
454
+ if (section.mod[i] != firstMod)
455
+ processedSection.mod.allTheSame = false;
456
+ if (section.secondary[i] != firstSecondary)
457
+ processedSection.secondary.allTheSame = false;
458
+ processedSection.ids.buffer[i] = voxelId;
459
+ processedSection.level.buffer[i] = voxelLevel;
460
+ processedSection.state.buffer[i] = voxelState;
461
+ processedSection.mod.buffer[i] = voxelMod;
462
+ processedSection.secondary.buffer[i] = voxelSecondary;
230
463
  }
231
464
  processedSections.push(processedSection);
232
465
  }
233
- for (const section of processedSections) {
234
- const reMapIds = section.palettes.ids.size < sectorPalettes.ids.size &&
235
- section.palettes.ids.size <= 255 &&
236
- !section.idsAllTheSame;
237
- const reMapLevel = section.palettes.level.size < sectorPalettes.level.size &&
238
- section.palettes.level.size <= 255 &&
239
- !section.levelAllTheSame;
240
- const reMapState = section.palettes.state.size < sectorPalettes.state.size &&
241
- section.palettes.state.size <= 255 &&
242
- !section.stateAllTheSame;
243
- const reMapMod = section.palettes.mod.size < sectorPalettes.mod.size &&
244
- section.palettes.mod.size <= 255 &&
245
- !section.modAllTheSame;
246
- const reMapLight = section.palettes.light.size < sectorPalettes.light.size &&
247
- section.palettes.light.size <= 255 &&
248
- !section.lightAllTheSame;
249
- const reMapSecondary = Math.max(section.palettes.secondaryId.size, section.palettes.secondaryState.size) <
250
- Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size) &&
251
- Math.max(section.palettes.secondaryId.size, section.palettes.secondaryState.size) <= 255 &&
252
- !section.secondaryAllTheSame;
253
- section.isLightPaletted =
254
- sectorPalettes.light.size < 65_535 && section.palettes.light.size < 255;
255
- section.isLevelPaletted =
256
- sectorPalettes.level.size < 255 && section.palettes.level.size < 255;
257
- section.isStatePaletted =
258
- sectorPalettes.state.size < 65_535 && section.palettes.state.size < 255;
259
- section.isModPaletted =
260
- sectorPalettes.mod.size < 65_535 && section.palettes.mod.size < 255;
261
- section.isSecondaryPaletted =
262
- sectorPalettes.secondaryState.size < 65_535 &&
263
- section.palettes.secondaryState.size < 255 &&
264
- section.palettes.secondaryId.size < 255;
265
- section.remappedIds = reMapIds;
266
- section.remappedLight = reMapLight && section.isLightPaletted;
267
- section.remappedState = reMapState && section.isStatePaletted;
268
- section.remappedMod = reMapMod && section.isModPaletted;
269
- section.remappedSecondary = reMapSecondary && section.isSecondaryPaletted;
270
- if (!reMapIds && !reMapLight && !reMapSecondary && !reMapState)
466
+ let neededPalettes = {
467
+ level: false,
468
+ light: {
469
+ sun: false,
470
+ red: false,
471
+ green: false,
472
+ blue: false,
473
+ },
474
+ };
475
+ for (const archivedSection of processedSections) {
476
+ //ids
477
+ archivedSection.ids.isPaletted =
478
+ sectorPalettes.ids.size <= BinaryBuffer.BytePaletteMax ||
479
+ archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax;
480
+ archivedSection.ids.remapped =
481
+ sectorPalettes.ids.size > BinaryBuffer.BytePaletteMax &&
482
+ archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax &&
483
+ !archivedSection.ids.allTheSame;
484
+ //level
485
+ archivedSection.level.isPaletted =
486
+ sectorPalettes.level.size <= BinaryBuffer.NibblePaletteMax &&
487
+ archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax;
488
+ archivedSection.level.remapped =
489
+ sectorPalettes.level.size > BinaryBuffer.NibblePaletteMax &&
490
+ archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax &&
491
+ !archivedSection.level.allTheSame;
492
+ if (archivedSection.level.isPaletted && !archivedSection.level.remapped) {
493
+ neededPalettes.level = true;
494
+ }
495
+ //state
496
+ archivedSection.state.isPaletted =
497
+ sectorPalettes.state.size <= BinaryBuffer.BytePaletteMax ||
498
+ archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax;
499
+ archivedSection.state.remapped =
500
+ sectorPalettes.state.size > BinaryBuffer.BytePaletteMax &&
501
+ archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax &&
502
+ !archivedSection.state.allTheSame;
503
+ //mod
504
+ archivedSection.mod.isPaletted =
505
+ sectorPalettes.mod.size <= BinaryBuffer.BytePaletteMax ||
506
+ archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax;
507
+ archivedSection.mod.remapped =
508
+ sectorPalettes.mod.size > BinaryBuffer.BytePaletteMax &&
509
+ archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax &&
510
+ !archivedSection.mod.allTheSame;
511
+ for (const semgnet of lightSegments) {
512
+ archivedSection.light[semgnet].isPaletted =
513
+ sectorPalettes.light[semgnet].size <=
514
+ BinaryBuffer.HalfNibblePaletteMax ||
515
+ archivedSection.palettes.light[semgnet].size <=
516
+ BinaryBuffer.HalfNibblePaletteMax;
517
+ archivedSection.light[semgnet].remapped =
518
+ sectorPalettes.light[semgnet].size >
519
+ BinaryBuffer.HalfNibblePaletteMax &&
520
+ archivedSection.palettes.light[semgnet].size <=
521
+ BinaryBuffer.HalfNibblePaletteMax &&
522
+ !archivedSection.light[semgnet].allTheSame;
523
+ if (archivedSection.light[semgnet].isPaletted &&
524
+ !archivedSection.light[semgnet].remapped) {
525
+ neededPalettes.light[semgnet] = true;
526
+ }
527
+ }
528
+ //secondary
529
+ archivedSection.secondary.isPaletted =
530
+ (sectorPalettes.secondaryState.size <= BinaryBuffer.BytePaletteMax &&
531
+ sectorPalettes.secondaryId.size <= BinaryBuffer.BytePaletteMax) ||
532
+ (archivedSection.palettes.secondaryState.size <=
533
+ BinaryBuffer.BytePaletteMax &&
534
+ archivedSection.palettes.secondaryId.size <=
535
+ BinaryBuffer.BytePaletteMax);
536
+ archivedSection.secondary.remapped =
537
+ Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size) > BinaryBuffer.BytePaletteMax &&
538
+ Math.max(archivedSection.palettes.secondaryId.size, archivedSection.palettes.secondaryState.size) <= BinaryBuffer.BytePaletteMax &&
539
+ !archivedSection.secondary.allTheSame;
540
+ if (!archivedSection.ids.remapped &&
541
+ !archivedSection.light.sun.remapped &&
542
+ !archivedSection.light.red.remapped &&
543
+ !archivedSection.light.green.remapped &&
544
+ !archivedSection.light.blue.remapped &&
545
+ !archivedSection.secondary.remapped &&
546
+ !archivedSection.mod.remapped &&
547
+ !archivedSection.level.remapped)
271
548
  continue;
272
- const length = section.section.ids.length;
549
+ const length = archivedSection.original.ids.length;
273
550
  for (let i = 0; i < length; i++) {
274
- if (reMapIds)
275
- section.ids[i] = section.palettes.ids.getId(section.ids[i]);
276
- if (reMapLight)
277
- section.light[i] = section.palettes.light.getId(section.section.light[i]);
278
- if (reMapLevel)
279
- section.level[i] = section.palettes.level.getId(section.section.level[i]);
280
- if (reMapState)
281
- section.state[i] = section.palettes.state.getId(sectorPalettes.state.getId(section.section.state[i]));
282
- if (reMapMod)
283
- section.mod[i] = section.palettes.mod.getId(sectorPalettes.mod.getId(section.section.mod[i]));
284
- if (reMapSecondary)
285
- section.secondary[i] = VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"]
286
- ? section.palettes.secondaryId.getId(section.secondary[i])
287
- : section.palettes.secondaryState.getId(section.secondary[i]);
551
+ if (archivedSection.ids.remapped)
552
+ archivedSection.ids.buffer[i] = archivedSection.palettes.ids.getId(archivedSection.ids.buffer[i]);
553
+ for (let l = 0; l < lightSegments.length; l++) {
554
+ const segment = lightSegments[l];
555
+ if (archivedSection.light[segment].remapped) {
556
+ archivedSection.light[segment].buffer[i] =
557
+ archivedSection.palettes.light[segment].getId(lightSemgnetGet[segment](archivedSection.original.light[i]));
558
+ }
559
+ }
560
+ if (archivedSection.level.remapped)
561
+ archivedSection.level.buffer[i] = archivedSection.palettes.level.getId(archivedSection.original.level[i]);
562
+ if (archivedSection.state.remapped)
563
+ archivedSection.state.buffer[i] = archivedSection.palettes.state.getId(sectorPalettes.state.getId(archivedSection.state.buffer[i]));
564
+ if (archivedSection.mod.remapped)
565
+ archivedSection.mod.buffer[i] = archivedSection.palettes.mod.getId(sectorPalettes.mod.getId(archivedSection.mod.buffer[i]));
566
+ if (archivedSection.secondary.remapped)
567
+ archivedSection.secondary.buffer[i] = VoxelTagsRegister.VoxelTags[archivedSection.original.ids[i]]["dve_can_have_secondary"]
568
+ ? archivedSection.palettes.secondaryId.getId(archivedSection.secondary.buffer[i])
569
+ : archivedSection.palettes.secondaryState.getId(archivedSection.secondary.buffer[i]);
288
570
  }
289
571
  }
290
572
  const stateMap = {};
@@ -315,26 +597,29 @@ export default function ArchiveSector(archiveData) {
315
597
  modMap,
316
598
  state: new Uint16Array(sectorPalettes.state._palette),
317
599
  mod: new Uint16Array(sectorPalettes.mod._palette),
600
+ light: {},
601
+ secondaryId: sectorPalettes.secondaryId._palette,
602
+ secondaryState: new Uint16Array(sectorPalettes.secondaryState._palette),
318
603
  };
319
- if (sectorPalettes.light.size < 255)
320
- palettes.light = new Uint16Array(sectorPalettes.light._palette);
321
- if (sectorPalettes.level.size < 255)
604
+ if (neededPalettes.level) {
322
605
  palettes.level = new Uint8Array(sectorPalettes.level._palette);
323
- if (sectorPalettes.light.size < 255)
324
- palettes.light = new Uint16Array(sectorPalettes.light._palette);
325
- if (sectorPalettes.secondaryId.size > 0)
326
- palettes.secondaryId = sectorPalettes.secondaryId._palette;
327
- if (sectorPalettes.secondaryState.size < 255)
328
- palettes.secondaryState = new Uint16Array(sectorPalettes.secondaryState._palette);
329
- return {
606
+ }
607
+ for (const segment of lightSegments) {
608
+ if (neededPalettes.light[segment]) {
609
+ palettes.light[segment] = new Uint8Array(sectorPalettes.light[segment]._palette);
610
+ }
611
+ }
612
+ const archivedSector = {
330
613
  version: "",
614
+ vloxVersion: EngineSettings.version,
331
615
  location: [...archiveData.location],
332
- sectorState: {},
616
+ flags: sector.storeFlags(),
617
+ timestamps: sector.storeTimestamps(),
333
618
  buffers: {},
334
- keys: {
335
- sectionState: [],
336
- },
337
619
  palettes,
620
+ duplicates: {},
338
621
  sections,
339
622
  };
623
+ RemoveDuplicates(archivedSector);
624
+ return archivedSector;
340
625
  }