@logic-pad/core 0.14.0 → 0.15.0

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.
@@ -1231,6 +1231,7 @@ declare global {
1231
1231
  Orientation = 'orientation',
1232
1232
  OrientationToggle = 'orientationToggle',
1233
1233
  Tile = 'tile',
1234
+ Shape = 'shape',
1234
1235
  Grid = 'grid',
1235
1236
  NullableGrid = 'nullableGrid',
1236
1237
  Icon = 'icon',
@@ -1295,6 +1296,10 @@ declare global {
1295
1296
  readonly type: ConfigType.Tile;
1296
1297
  readonly resizable: boolean;
1297
1298
  }
1299
+ export interface ShapeConfig extends Config<GridData> {
1300
+ readonly type: ConfigType.Shape;
1301
+ readonly resizable: boolean;
1302
+ }
1298
1303
  export interface GridConfig extends Config<GridData> {
1299
1304
  readonly type: ConfigType.Grid;
1300
1305
  }
@@ -1328,6 +1333,7 @@ declare global {
1328
1333
  | OrientationConfig
1329
1334
  | OrientationToggleConfig
1330
1335
  | TileConfig
1336
+ | ShapeConfig
1331
1337
  | GridConfig
1332
1338
  | NullableGridConfig
1333
1339
  | IconConfig
@@ -15,6 +15,7 @@ export declare enum ConfigType {
15
15
  Orientation = "orientation",
16
16
  OrientationToggle = "orientationToggle",
17
17
  Tile = "tile",
18
+ Shape = "shape",
18
19
  Grid = "grid",
19
20
  NullableGrid = "nullableGrid",
20
21
  Icon = "icon",
@@ -79,6 +80,10 @@ export interface TileConfig extends Config<GridData> {
79
80
  readonly type: ConfigType.Tile;
80
81
  readonly resizable: boolean;
81
82
  }
83
+ export interface ShapeConfig extends Config<GridData> {
84
+ readonly type: ConfigType.Shape;
85
+ readonly resizable: boolean;
86
+ }
82
87
  export interface GridConfig extends Config<GridData> {
83
88
  readonly type: ConfigType.Grid;
84
89
  }
@@ -98,7 +103,7 @@ export interface NullableNoteConfig extends Config<string | null> {
98
103
  export interface SolvePathConfig extends Config<Position[]> {
99
104
  readonly type: ConfigType.SolvePath;
100
105
  }
101
- export type AnyConfig = BooleanConfig | NullableBooleanConfig | NumberConfig | NullableNumberConfig | StringConfig | ColorConfig | ComparisonConfig | WrappingConfig | DirectionConfig | DirectionToggleConfig | OrientationConfig | OrientationToggleConfig | TileConfig | GridConfig | NullableGridConfig | IconConfig | ControlLinesConfig | NullableNoteConfig | SolvePathConfig;
106
+ export type AnyConfig = BooleanConfig | NullableBooleanConfig | NumberConfig | NullableNumberConfig | StringConfig | ColorConfig | ComparisonConfig | WrappingConfig | DirectionConfig | DirectionToggleConfig | OrientationConfig | OrientationToggleConfig | TileConfig | ShapeConfig | GridConfig | NullableGridConfig | IconConfig | ControlLinesConfig | NullableNoteConfig | SolvePathConfig;
102
107
  /**
103
108
  * Compare two config values for equality, using an appropriate method for the config type.
104
109
  *
@@ -1,4 +1,5 @@
1
1
  import { DIRECTIONS, ORIENTATIONS, } from './primitives.js';
2
+ import { normalizeShape, shapeEquals, tilesToShape } from './shapes.js';
2
3
  export var ConfigType;
3
4
  (function (ConfigType) {
4
5
  ConfigType["Boolean"] = "boolean";
@@ -14,6 +15,7 @@ export var ConfigType;
14
15
  ConfigType["Orientation"] = "orientation";
15
16
  ConfigType["OrientationToggle"] = "orientationToggle";
16
17
  ConfigType["Tile"] = "tile";
18
+ ConfigType["Shape"] = "shape";
17
19
  ConfigType["Grid"] = "grid";
18
20
  ConfigType["NullableGrid"] = "nullableGrid";
19
21
  ConfigType["Icon"] = "icon";
@@ -40,6 +42,11 @@ export function configEquals(type, a, b) {
40
42
  if (type === ConfigType.Tile || type === ConfigType.Grid) {
41
43
  return a.equals(b);
42
44
  }
45
+ if (type === ConfigType.Shape) {
46
+ const aShape = normalizeShape(tilesToShape(a.tiles));
47
+ const bShape = normalizeShape(tilesToShape(b.tiles));
48
+ return shapeEquals(aShape, bShape);
49
+ }
43
50
  if (type === ConfigType.NullableGrid) {
44
51
  if (a === null && b === null)
45
52
  return true;
@@ -134,7 +134,7 @@ Object.defineProperty(BanPatternRule, "CONFIGS", {
134
134
  writable: true,
135
135
  value: Object.freeze([
136
136
  {
137
- type: ConfigType.Tile,
137
+ type: ConfigType.Shape,
138
138
  default: BanPatternRule.EXAMPLE_GRID,
139
139
  resizable: true,
140
140
  field: 'pattern',
@@ -138,7 +138,7 @@ Object.defineProperty(ContainsShapeRule, "CONFIGS", {
138
138
  configurable: true,
139
139
  },
140
140
  {
141
- type: ConfigType.Tile,
141
+ type: ConfigType.Shape,
142
142
  default: ContainsShapeRule.EXAMPLE_GRID_LIGHT,
143
143
  resizable: true,
144
144
  field: 'pattern',
@@ -2,6 +2,7 @@ import { ConfigType, } from '../config.js';
2
2
  import SerializerV0, { orientationChars } from './serializer_v0.js';
3
3
  import { DIRECTIONS, ORIENTATIONS, } from '../primitives.js';
4
4
  import { escape } from '../dataHelper.js';
5
+ import { normalizeShape, tilesToShape } from '../shapes.js';
5
6
  export default class SerializerChecksum extends SerializerV0 {
6
7
  constructor() {
7
8
  super(...arguments);
@@ -9,7 +10,7 @@ export default class SerializerChecksum extends SerializerV0 {
9
10
  enumerable: true,
10
11
  configurable: true,
11
12
  writable: true,
12
- value: 2
13
+ value: 3
13
14
  });
14
15
  }
15
16
  parseTile(_str) {
@@ -91,6 +92,13 @@ export default class SerializerChecksum extends SerializerV0 {
91
92
  return (config.field +
92
93
  '=' +
93
94
  escape(this.stringifyGrid(instruction[config.field])));
95
+ case ConfigType.Shape:
96
+ return (config.field +
97
+ '=' +
98
+ escape(normalizeShape(tilesToShape(instruction[config.field].tiles))
99
+ .elements.map(elm => `${elm.x}-${elm.y}-${elm.color}`)
100
+ .sort()
101
+ .join('/')));
94
102
  case ConfigType.NullableGrid:
95
103
  return (config.field +
96
104
  '=' +
@@ -137,6 +145,7 @@ export default class SerializerChecksum extends SerializerV0 {
137
145
  }
138
146
  stringifyRules(rules) {
139
147
  return `R${rules
148
+ .filter(rule => rule.necessaryForCompletion)
140
149
  .map(rule => this.stringifyRule(rule))
141
150
  .sort()
142
151
  .join(':')}`;
@@ -147,6 +156,7 @@ export default class SerializerChecksum extends SerializerV0 {
147
156
  stringifySymbols(symbols) {
148
157
  return `S${Array.from(symbols.values())
149
158
  .flat()
159
+ .filter(symbol => symbol.necessaryForCompletion)
150
160
  .map(symbol => this.stringifySymbol(symbol))
151
161
  .sort()
152
162
  .join(':')}`;
@@ -147,6 +147,7 @@ export default class SerializerV0 extends SerializerBase {
147
147
  ? ''
148
148
  : escape(String(instruction[config.field]))));
149
149
  case ConfigType.Tile:
150
+ case ConfigType.Shape:
150
151
  case ConfigType.Grid:
151
152
  return (config.field +
152
153
  '=' +
@@ -215,6 +216,7 @@ export default class SerializerV0 extends SerializerBase {
215
216
  case ConfigType.Icon:
216
217
  return [config.field, unescape(value)];
217
218
  case ConfigType.Tile:
219
+ case ConfigType.Shape:
218
220
  case ConfigType.Grid:
219
221
  return [config.field, this.parseGrid(unescape(value))];
220
222
  case ConfigType.NullableGrid:
@@ -1,3 +1,5 @@
1
+ import GridConnections from './gridConnections.js';
2
+ import GridZones from './gridZones.js';
1
3
  import { Color } from './primitives.js';
2
4
  const colorIndex = {
3
5
  [Color.Dark]: 2,
@@ -129,5 +131,7 @@ export function sanitizePatternGrid(pattern, tileMapper = t => t) {
129
131
  : t.copyWith({ exists: true, color: Color.Gray, fixed: false })))))
130
132
  // strip all symbols and rules
131
133
  .withRules([])
132
- .withSymbols(new Map()));
134
+ .withSymbols(new Map())
135
+ .withConnections(new GridConnections())
136
+ .withZones(new GridZones()));
133
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logic-pad/core",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",