11import * as Pako from 'pako'
22import { Block , Blocks , Liquid , UnitCommand } from '../mindustry'
3+ import { Point2 , Vec2 } from '../arc'
4+ import { SchematicTile , SchematicTileConfig } from './tile'
35import { StreamedDataReader , StreamedDataWriter } from '../streamed_data'
46import { Item } from '../mindustry/item'
57import { MindustryVersion } from '.'
6- import { Point2 } from '../arc'
78import { Schematic } from './schematic'
8- import { SchematicTile } from './tile'
99
1010const {
1111 distribution : {
@@ -87,7 +87,7 @@ function mapConfig(block: Block, value: number, position: number) {
8787 return null
8888}
8989
90- function readConfigObject ( cData : StreamedDataReader ) {
90+ function readConfigObject ( cData : StreamedDataReader ) : SchematicTileConfig {
9191 const type = cData . getInt8 ( )
9292 switch ( type ) {
9393 case 0 :
@@ -128,11 +128,7 @@ function readConfigObject(cData: StreamedDataReader) {
128128 // return content.getByID(ContentType.all[read.b()], read.s());
129129 case 6 : {
130130 const length = cData . getInt16 ( )
131- const arr = [ ]
132- for ( let i = 0 ; i < length ; i ++ ) {
133- arr . push ( cData . getInt32 ( ) )
134- }
135- return arr
131+ return readArray ( length , ( ) => cData . getInt32 ( ) )
136132 }
137133
138134 // original code
@@ -141,20 +137,15 @@ function readConfigObject(cData: StreamedDataReader) {
141137 return new Point2 ( cData . getInt32 ( ) , cData . getInt32 ( ) )
142138 case 8 : {
143139 const len = cData . getInt8 ( )
144- const out = [ ]
145- for ( let i = 0 ; i < len ; i ++ ) {
146- out . push ( Point2 . unpack ( cData . getInt32 ( ) ) )
147- }
148- // byte len = read.b(); Point2[] out = new Point2[len]; for (int i = 0; i < len; i++) out[i] = Point2.unpack(read.i());
149- return out
140+ return readArray ( len , ( ) => Point2 . unpack ( cData . getInt32 ( ) ) )
150141 }
151142
152143 // TODO: somehow implement java code bellow
153144 case 9 :
154145 // by now just ignore the config data
155146 cData . getInt8 ( )
156147 cData . getInt16 ( )
157- break
148+ return
158149 // return TechTree.getNotNull(content.getByID(ContentType.all[read.b()], read.s()));
159150 case 10 :
160151 return cData . getBool ( )
@@ -172,19 +163,59 @@ function readConfigObject(cData: StreamedDataReader) {
172163 // return LAccess.all[read.s()];
173164 case 14 : {
174165 const blen = cData . getInt32 ( )
175- const bytes = [ ]
176- for ( let i = 0 ; i < blen ; i ++ ) bytes . push ( cData . getInt8 ( ) )
177- return bytes
166+ return readArray ( blen , ( ) => cData . getInt8 ( ) )
178167 }
179168 // int blen = read.i(); byte[] bytes = new byte[blen]; read.b(bytes); return bytes;
180169 case 15 :
181170 return UnitCommand [ cData . getInt8 ( ) ]
171+ case 16 : {
172+ const len = cData . getInt32 ( )
173+ return readArray ( len , ( ) => cData . getBool ( ) )
174+ }
175+ case 17 : {
176+ cData . getInt32 ( )
177+ return
178+ }
179+ case 18 : {
180+ const len = cData . getInt16 ( )
181+ return readArray (
182+ len ,
183+ ( ) => new Vec2 ( cData . getFloat32 ( ) , cData . getFloat32 ( ) )
184+ )
185+ }
186+ case 19 :
187+ return new Vec2 ( cData . getFloat32 ( ) , cData . getFloat32 ( ) )
188+ case 20 : {
189+ cData . getUint8 ( )
190+ return
191+ }
192+ case 21 : {
193+ const len = cData . getInt16 ( )
194+ return readArray ( len , ( ) => cData . getInt32 ( ) )
195+ }
196+ case 22 : {
197+ const len = cData . getInt32 ( )
198+ return readArray ( len , ( ) => readConfigObject ( cData ) )
199+ }
200+ case 23 : {
201+ cData . getUint16 ( )
202+ return
203+ }
182204 default :
183205 throw new Error ( 'Unknown object type: ' + type )
184206 // throw new IllegalArgumentException('Unknown object type: ' + type)
185207 }
186208}
187209
210+ function readArray < T > ( length : number , fn : ( ) => T ) {
211+ const result = new Array < T > ( length )
212+
213+ for ( let i = 0 ; i < length ; i ++ ) {
214+ result [ i ] = fn ( )
215+ }
216+ return result
217+ }
218+
188219function decodeTiles (
189220 cData : StreamedDataReader ,
190221 blocks : Block [ ] ,
0 commit comments