88import { Game_FogOfWar } from "game" ;
99import { RectCover } from "utils" ;
1010
11+ import pluginParams from "parameters" ;
12+
1113declare class JsonEx {
1214 static _encode ( value : unknown , depth : number ) : string
1315 static _decode ( value : unknown ) : unknown
1416}
1517
1618const _JsonEx_encode = JsonEx . _encode ;
1719JsonEx . _encode = function ( value , depth ) : string {
18- if ( typeof value === "object" && value != null ) {
20+ if ( typeof value === "object" && ! ( value instanceof Array ) && value != null ) {
1921 const constructor = value . constructor ;
2022 value = Object . assign ( { } , value ) ;
2123 Object . setPrototypeOf ( value , constructor . prototype ) ;
@@ -24,9 +26,11 @@ JsonEx._encode = function(value, depth): string {
2426 if ( value instanceof Game_FogOfWar ) {
2527 const width = value . width ;
2628 const height = value . height ;
27- const cover = new RectCover ( value ) ;
28- const rects = cover . minimize ( ) ;
29- return _JsonEx_encode . call ( this , { '@' : 'Game_FogOfWar' , width, height, rects } , depth + 1 ) ;
29+ const contours = pluginParams . advanced . saveRectCoverThresholds . map ( threshold => {
30+ const cover = new RectCover ( value as Game_FogOfWar , threshold ) ;
31+ return cover . minimize ( ) ;
32+ } ) ;
33+ return _JsonEx_encode . call ( this , { '@' : 'Game_FogOfWar' , width, height, contours } , depth + 1 ) ;
3034 }
3135
3236 return _JsonEx_encode . call ( this , value , depth ) ;
@@ -36,7 +40,11 @@ const _JsonEx_decode = JsonEx._decode;
3640JsonEx . _decode = function ( value ) : unknown {
3741 if ( typeof value === "object" && value != null ) {
3842 if ( value [ "@" ] === 'Game_FogOfWar' ) {
39- return Game_FogOfWar . from ( value [ 'width' ] , value [ 'height' ] , value [ 'rects' ] ) ;
43+ return Game_FogOfWar . from (
44+ value [ 'width' ] ,
45+ value [ 'height' ] ,
46+ value [ 'contours' ] ,
47+ pluginParams . advanced . saveRectCoverThresholds ) ;
4048 }
4149 }
4250 return _JsonEx_decode . call ( this , value ) ;
0 commit comments