@packtrack/layout 1.2.0 → 1.3.1
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.
- package/.built/index.d.ts +20 -20
- package/.built/index.js +20 -20
- package/.built/source/device/channel.d.ts +2 -2
- package/.built/source/device/channel.js +4 -8
- package/.built/{device → source/device}/index.d.ts +0 -1
- package/.built/source/device/index.js +8 -0
- package/.built/source/district.d.ts +3 -7
- package/.built/source/district.js +4 -70
- package/.built/source/layout.d.ts +9 -6
- package/.built/source/layout.js +85 -86
- package/.built/{monitor.d.ts → source/monitor.d.ts} +1 -2
- package/.built/source/monitor.js +8 -0
- package/.built/source/position.d.ts +3 -1
- package/.built/source/position.js +17 -5
- package/.built/{positioner → source/positioner}/point.d.ts +2 -3
- package/.built/{positioner → source/positioner}/point.js +1 -7
- package/.built/{positioner → source/positioner}/responder-type.d.ts +0 -1
- package/.built/{positioner → source/positioner}/responder-type.js +0 -3
- package/.built/{power-district → source/power-district}/index.d.ts +0 -1
- package/.built/{power-district → source/power-district}/index.js +0 -3
- package/.built/source/route.d.ts +0 -1
- package/.built/source/route.js +1 -8
- package/.built/source/router.d.ts +0 -4
- package/.built/source/router.js +1 -28
- package/.built/source/section.d.ts +1 -10
- package/.built/source/section.js +8 -57
- package/.built/{throttle.d.ts → source/throttle.d.ts} +1 -2
- package/.built/source/throttle.js +8 -0
- package/.built/source/tile.js +2 -7
- package/.built/source/track.d.ts +1 -2
- package/.built/source/track.js +3 -10
- package/index.ts +23 -0
- package/package.json +2 -2
- package/source/device/channel.ts +4 -4
- package/source/device/index.ts +2 -19
- package/source/district.ts +1 -80
- package/source/layout.ts +1 -63
- package/source/monitor.ts +1 -10
- package/source/positioner/point.ts +2 -11
- package/source/positioner/responder-type.ts +1 -5
- package/source/power-district/index.ts +0 -5
- package/source/route.ts +2 -6
- package/source/router.ts +2 -31
- package/source/section.ts +10 -65
- package/source/throttle.ts +1 -10
- package/source/track.ts +3 -7
- package/tsconfig.json +7 -8
- package/.built/device/channel.d.ts +0 -8
- package/.built/device/channel.js +0 -12
- package/.built/device/device.d.ts +0 -11
- package/.built/device/device.js +0 -20
- package/.built/device/index.js +0 -20
- package/.built/district.d.ts +0 -22
- package/.built/district.js +0 -83
- package/.built/layout.d.ts +0 -35
- package/.built/layout.js +0 -331
- package/.built/monitor.js +0 -15
- package/.built/position.d.ts +0 -12
- package/.built/position.js +0 -45
- package/.built/power-district.d.ts +0 -8
- package/.built/power-district.js +0 -14
- package/.built/route.d.ts +0 -10
- package/.built/route.js +0 -13
- package/.built/router.d.ts +0 -14
- package/.built/router.js +0 -36
- package/.built/section.d.ts +0 -40
- package/.built/section.js +0 -213
- package/.built/source/device/device.d.ts +0 -11
- package/.built/source/device/device.js +0 -24
- package/.built/source/power-district.d.ts +0 -8
- package/.built/source/power-district.js +0 -18
- package/.built/throttle.js +0 -15
- package/.built/tile.d.ts +0 -57
- package/.built/tile.js +0 -73
- package/.built/track.d.ts +0 -12
- package/.built/track.js +0 -25
- package/source/index.ts +0 -23
- /package/.built/{positioner → source/positioner}/index.d.ts +0 -0
- /package/.built/{positioner → source/positioner}/index.js +0 -0
- /package/.built/{power-district → source/power-district}/activator.d.ts +0 -0
- /package/.built/{power-district → source/power-district}/activator.js +0 -0
- /package/.built/{power-district → source/power-district}/monitor.d.ts +0 -0
- /package/.built/{power-district → source/power-district}/monitor.js +0 -0
- /package/.built/{power-district → source/power-district}/reverser.d.ts +0 -0
- /package/.built/{power-district → source/power-district}/reverser.js +0 -0
- /package/.built/{span.d.ts → source/span.d.ts} +0 -0
- /package/.built/{span.js → source/span.js} +0 -0
package/.built/layout.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { District } from "./district";
|
|
2
|
-
import { PowerDistrict } from "./power-district";
|
|
3
|
-
import { Route } from "./route";
|
|
4
|
-
import { Router } from "./router";
|
|
5
|
-
import { Section } from "./section";
|
|
6
|
-
import { TilePattern, Tile } from "./tile";
|
|
7
|
-
import { Track } from "./track";
|
|
8
|
-
import { Device } from "./device/index";
|
|
9
|
-
import { ResponderType } from "./positioner/responder-type";
|
|
10
|
-
import { Channel } from "./device/channel";
|
|
11
|
-
import { PointPositioner } from "./positioner/point";
|
|
12
|
-
import { PowerDistrictActivator } from "./power-district/activator";
|
|
13
|
-
import { PowerDistrictReverser } from "./power-district/reverser";
|
|
14
|
-
import { PowerDistrictMonitor } from "./power-district/monitor";
|
|
15
|
-
import { Monitor } from "./monitor";
|
|
16
|
-
import { Throttle } from "./throttle";
|
|
17
|
-
export class Layout {
|
|
18
|
-
name;
|
|
19
|
-
districts = [];
|
|
20
|
-
devices = [];
|
|
21
|
-
responderType = [];
|
|
22
|
-
monitors = [];
|
|
23
|
-
throttles = [];
|
|
24
|
-
get allDistricts() {
|
|
25
|
-
const districts = [];
|
|
26
|
-
function walkDistrict(district) {
|
|
27
|
-
districts.push(district);
|
|
28
|
-
for (let child of district.children) {
|
|
29
|
-
walkDistrict(child);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (let district of this.districts) {
|
|
33
|
-
walkDistrict(district);
|
|
34
|
-
}
|
|
35
|
-
return districts;
|
|
36
|
-
}
|
|
37
|
-
static from(document) {
|
|
38
|
-
const layout = new Layout();
|
|
39
|
-
const railway = document.firstChild;
|
|
40
|
-
layout.name = railway.getAttribute('name');
|
|
41
|
-
const version = railway.getAttribute('version');
|
|
42
|
-
if (version == '1') {
|
|
43
|
-
let child = railway.firstChild;
|
|
44
|
-
while (child) {
|
|
45
|
-
if (child.tagName == 'district') {
|
|
46
|
-
layout.districts.push(layout.loadDistrict(child, layout));
|
|
47
|
-
}
|
|
48
|
-
if (child.tagName == 'monitor') {
|
|
49
|
-
layout.monitors.push(layout.loadMonitor(child, layout));
|
|
50
|
-
}
|
|
51
|
-
if (child.tagName == 'throttle') {
|
|
52
|
-
layout.throttles.push(layout.loadThrottle(child, layout));
|
|
53
|
-
}
|
|
54
|
-
child = child.nextSibling;
|
|
55
|
-
}
|
|
56
|
-
child = railway.firstChild;
|
|
57
|
-
let index = 0;
|
|
58
|
-
while (child) {
|
|
59
|
-
if (child.tagName == 'district') {
|
|
60
|
-
layout.linkDistrict(child, layout.districts[index]);
|
|
61
|
-
index++;
|
|
62
|
-
}
|
|
63
|
-
child = child.nextSibling;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new Error(`Unsupported railway definition file version '${version}'`);
|
|
68
|
-
}
|
|
69
|
-
return layout;
|
|
70
|
-
}
|
|
71
|
-
loadMonitor(source, parent) {
|
|
72
|
-
const montior = new Monitor(this.findDevice(source.getAttribute('device')), parent);
|
|
73
|
-
return montior;
|
|
74
|
-
}
|
|
75
|
-
loadThrottle(source, parent) {
|
|
76
|
-
const throttle = new Throttle(this.findDevice(source.getAttribute('device')), parent);
|
|
77
|
-
return throttle;
|
|
78
|
-
}
|
|
79
|
-
loadDistrict(source, parent) {
|
|
80
|
-
const district = new District(source.getAttribute('name'), parent);
|
|
81
|
-
let child = source.firstChild;
|
|
82
|
-
while (child) {
|
|
83
|
-
if (child.tagName == 'power-districts') {
|
|
84
|
-
let powerDistrict = child.firstChild;
|
|
85
|
-
while (powerDistrict) {
|
|
86
|
-
if (powerDistrict.tagName == 'power-district') {
|
|
87
|
-
district.powerDistricts.push(this.loadPowerDistrict(powerDistrict, district));
|
|
88
|
-
}
|
|
89
|
-
powerDistrict = powerDistrict.nextSibling;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (child.tagName == 'section') {
|
|
93
|
-
this.loadSection(child, district);
|
|
94
|
-
}
|
|
95
|
-
if (child.tagName == 'router') {
|
|
96
|
-
district.routers.push(this.loadRouter(child, district));
|
|
97
|
-
}
|
|
98
|
-
if (child.tagName == 'district') {
|
|
99
|
-
district.children.push(this.loadDistrict(child, district));
|
|
100
|
-
}
|
|
101
|
-
if (child.tagName == 'monitor') {
|
|
102
|
-
district.monitors.push(this.loadMonitor(child, district));
|
|
103
|
-
}
|
|
104
|
-
child = child.nextSibling;
|
|
105
|
-
}
|
|
106
|
-
return district;
|
|
107
|
-
}
|
|
108
|
-
linkDistrict(source, district) {
|
|
109
|
-
let child = source.firstChild;
|
|
110
|
-
let sectionIndex = 0;
|
|
111
|
-
let childIndex = 0;
|
|
112
|
-
while (child) {
|
|
113
|
-
if (child.tagName == 'section') {
|
|
114
|
-
this.linkSection(child, district.sections[sectionIndex]);
|
|
115
|
-
sectionIndex++;
|
|
116
|
-
}
|
|
117
|
-
if (child.tagName == 'router') {
|
|
118
|
-
this.linkRouter(child, district.routers.find(router => router.name == child.getAttribute('name')));
|
|
119
|
-
}
|
|
120
|
-
if (child.tagName == 'district') {
|
|
121
|
-
this.linkDistrict(child, district.children[childIndex]);
|
|
122
|
-
childIndex++;
|
|
123
|
-
}
|
|
124
|
-
child = child.nextSibling;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
loadSection(source, district) {
|
|
128
|
-
const section = new Section(source.getAttribute('name'), district);
|
|
129
|
-
district.sections.push(section);
|
|
130
|
-
let child = source.firstChild;
|
|
131
|
-
while (child) {
|
|
132
|
-
if (child.tagName == 'tracks') {
|
|
133
|
-
let trackNode = child.firstChild;
|
|
134
|
-
while (trackNode) {
|
|
135
|
-
if (trackNode.tagName == 'track') {
|
|
136
|
-
const track = new Track(section, +trackNode.getAttribute('length'), trackNode.getAttribute('path'));
|
|
137
|
-
section.tracks.push(track);
|
|
138
|
-
let trackChild = trackNode.firstChild;
|
|
139
|
-
while (trackChild) {
|
|
140
|
-
if (trackChild.tagName == 'positioners') {
|
|
141
|
-
let positioner = trackChild.firstChild;
|
|
142
|
-
while (positioner) {
|
|
143
|
-
if (positioner.tagName == 'point') {
|
|
144
|
-
const device = this.findDevice(positioner.getAttribute('device'));
|
|
145
|
-
const channel = this.findChannel(device, positioner.getAttribute('channel'));
|
|
146
|
-
const responderType = this.findResponderType(positioner.getAttribute('responder'));
|
|
147
|
-
track.positioners.push(new PointPositioner(track, +positioner.getAttribute('offset'), channel, responderType));
|
|
148
|
-
}
|
|
149
|
-
positioner = positioner.nextSibling;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
trackChild = trackChild.nextSibling;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
trackNode = trackNode.nextSibling;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (child.tagName == 'tile') {
|
|
159
|
-
const pattern = child.getAttribute('pattern');
|
|
160
|
-
if (!(pattern in TilePattern.patterns)) {
|
|
161
|
-
throw new Error(`Unknown tile pattern '${pattern}' in tile ${section.tiles.length + 1} in ${section.domainName}`);
|
|
162
|
-
}
|
|
163
|
-
section.tiles.push(new Tile(section, +child.getAttribute('x'), +child.getAttribute('y'), TilePattern.patterns[pattern]));
|
|
164
|
-
}
|
|
165
|
-
child = child.nextSibling;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
findDevice(identifier) {
|
|
169
|
-
let device = this.devices.find(device => device.identifier == identifier);
|
|
170
|
-
if (device) {
|
|
171
|
-
return device;
|
|
172
|
-
}
|
|
173
|
-
device = new Device(identifier);
|
|
174
|
-
this.devices.push(device);
|
|
175
|
-
return device;
|
|
176
|
-
}
|
|
177
|
-
findChannel(device, name) {
|
|
178
|
-
let channel = device.channels.find(channel => channel.name == name);
|
|
179
|
-
if (channel) {
|
|
180
|
-
return channel;
|
|
181
|
-
}
|
|
182
|
-
channel = new Channel(device, name);
|
|
183
|
-
device.channels.push(channel);
|
|
184
|
-
return channel;
|
|
185
|
-
}
|
|
186
|
-
findResponderType(name) {
|
|
187
|
-
let type = this.responderType.find(type => type.name == name);
|
|
188
|
-
if (type) {
|
|
189
|
-
return type;
|
|
190
|
-
}
|
|
191
|
-
type = new ResponderType(name);
|
|
192
|
-
this.responderType.push(type);
|
|
193
|
-
return type;
|
|
194
|
-
}
|
|
195
|
-
linkSection(source, section) {
|
|
196
|
-
let child = source.firstChild;
|
|
197
|
-
while (child) {
|
|
198
|
-
if (child.tagName == 'out') {
|
|
199
|
-
const out = this.findSection(child.getAttribute('section'), section.district);
|
|
200
|
-
section.out = out;
|
|
201
|
-
out.in = section;
|
|
202
|
-
}
|
|
203
|
-
child = child.nextSibling;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
findSection(path, base, source = base) {
|
|
207
|
-
const parts = path.split('.');
|
|
208
|
-
if (parts.length == 0) {
|
|
209
|
-
throw `section '${path}' not found from '${source.name}': invalid name`;
|
|
210
|
-
}
|
|
211
|
-
if (parts.length == 1) {
|
|
212
|
-
const localSection = base.sections.find(section => section.name == parts[0]);
|
|
213
|
-
if (!localSection) {
|
|
214
|
-
throw new Error(`Section '${path}' not found from '${source.name}': section does not exist in '${base.name}'`);
|
|
215
|
-
}
|
|
216
|
-
return localSection;
|
|
217
|
-
}
|
|
218
|
-
const sectionName = parts.pop();
|
|
219
|
-
let pool = base;
|
|
220
|
-
for (let index = 0; index < parts.length; index++) {
|
|
221
|
-
if (pool instanceof Layout || !pool.parent) {
|
|
222
|
-
throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a parent`);
|
|
223
|
-
}
|
|
224
|
-
pool = pool.parent;
|
|
225
|
-
}
|
|
226
|
-
for (let part of parts) {
|
|
227
|
-
const child = (pool instanceof District ? pool.children : pool.districts).find(child => child.name == part);
|
|
228
|
-
if (!child) {
|
|
229
|
-
throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
|
|
230
|
-
}
|
|
231
|
-
pool = child;
|
|
232
|
-
}
|
|
233
|
-
if (pool instanceof Layout) {
|
|
234
|
-
throw new Error(`Section '${path}' could not be found from '${source.name}': a layout cannot directly include a section`);
|
|
235
|
-
}
|
|
236
|
-
return this.findSection(sectionName, pool, source);
|
|
237
|
-
}
|
|
238
|
-
loadRouter(source, district) {
|
|
239
|
-
const router = new Router(source.getAttribute('name'), district);
|
|
240
|
-
return router;
|
|
241
|
-
}
|
|
242
|
-
linkRouter(source, router) {
|
|
243
|
-
let child = source.firstChild;
|
|
244
|
-
let active;
|
|
245
|
-
while (child) {
|
|
246
|
-
if (child.tagName == 'route') {
|
|
247
|
-
const route = new Route(child.getAttribute('name'), router);
|
|
248
|
-
route.in = this.findSection(child.getAttribute('in'), router.district);
|
|
249
|
-
route.in.out = router;
|
|
250
|
-
route.out = this.findSection(child.getAttribute('out'), router.district);
|
|
251
|
-
route.out.in = router;
|
|
252
|
-
if (child.hasAttribute('active')) {
|
|
253
|
-
if (active) {
|
|
254
|
-
throw new Error(`Router '${router.domainName}' has multiple active routes (${active.name}, ${route.name}).`);
|
|
255
|
-
}
|
|
256
|
-
active = route;
|
|
257
|
-
}
|
|
258
|
-
router.routes.push(route);
|
|
259
|
-
}
|
|
260
|
-
child = child.nextSibling;
|
|
261
|
-
}
|
|
262
|
-
router.activeRoute = active;
|
|
263
|
-
}
|
|
264
|
-
loadPowerDistrict(source, district) {
|
|
265
|
-
const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
|
|
266
|
-
let actor = source.firstChild;
|
|
267
|
-
while (actor) {
|
|
268
|
-
if (actor.tagName == 'activator' || actor.tagName == 'reverser' || actor.tagName == 'monitor') {
|
|
269
|
-
const device = this.findDevice(actor.getAttribute('device'));
|
|
270
|
-
const channel = this.findChannel(device, actor.getAttribute('channel'));
|
|
271
|
-
if (actor.tagName == 'activator') {
|
|
272
|
-
powerDistrict.activator = new PowerDistrictActivator(device, channel);
|
|
273
|
-
}
|
|
274
|
-
if (actor.tagName == 'reverser') {
|
|
275
|
-
powerDistrict.reverser = new PowerDistrictReverser(device, channel);
|
|
276
|
-
}
|
|
277
|
-
if (actor.tagName == 'monitor') {
|
|
278
|
-
powerDistrict.monitor = new PowerDistrictMonitor(device, channel);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
actor = actor.nextSibling;
|
|
282
|
-
}
|
|
283
|
-
return powerDistrict;
|
|
284
|
-
}
|
|
285
|
-
toDot() {
|
|
286
|
-
let dot = 'digraph G {';
|
|
287
|
-
for (let district of this.districts) {
|
|
288
|
-
dot += district.toDotDefinition();
|
|
289
|
-
}
|
|
290
|
-
for (let district of this.districts) {
|
|
291
|
-
dot += district.toDotConnection();
|
|
292
|
-
}
|
|
293
|
-
return `${dot}}`;
|
|
294
|
-
}
|
|
295
|
-
toSVG(inject = '') {
|
|
296
|
-
const positons = this.districts.map(district => district.findSVGPositions()).flat(Infinity);
|
|
297
|
-
const width = Math.max(...positons.map(position => position.x));
|
|
298
|
-
const height = Math.max(...positons.map(position => position.y));
|
|
299
|
-
let svg = `<svg width="100vw" height="100vh" viewBox="0 0 ${width + 1} ${height + 1}" xmlns="http://www.w3.org/2000/svg">
|
|
300
|
-
<style>
|
|
301
|
-
|
|
302
|
-
path {
|
|
303
|
-
fill: none;
|
|
304
|
-
stroke: #000;
|
|
305
|
-
stroke-width: 0.2;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
</style>
|
|
309
|
-
`;
|
|
310
|
-
for (let district of this.districts) {
|
|
311
|
-
svg += district.toSVG();
|
|
312
|
-
}
|
|
313
|
-
return `${svg}${inject}</svg>`;
|
|
314
|
-
}
|
|
315
|
-
dump() {
|
|
316
|
-
console.group(`Layout ${this.name}`);
|
|
317
|
-
console.log('devices');
|
|
318
|
-
for (let device of this.devices) {
|
|
319
|
-
device.dump();
|
|
320
|
-
}
|
|
321
|
-
console.log('responder types');
|
|
322
|
-
for (let type of this.responderType) {
|
|
323
|
-
type.dump();
|
|
324
|
-
}
|
|
325
|
-
console.log('districts');
|
|
326
|
-
for (let district of this.districts) {
|
|
327
|
-
district.dump();
|
|
328
|
-
}
|
|
329
|
-
console.groupEnd();
|
|
330
|
-
}
|
|
331
|
-
}
|
package/.built/monitor.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Layout } from "./layout";
|
|
2
|
-
export class Monitor {
|
|
3
|
-
device;
|
|
4
|
-
scope;
|
|
5
|
-
constructor(device, scope) {
|
|
6
|
-
this.device = device;
|
|
7
|
-
this.scope = scope;
|
|
8
|
-
}
|
|
9
|
-
dump() {
|
|
10
|
-
console.group('Monitor');
|
|
11
|
-
console.log('scope:', this.scope instanceof Layout ? '*' : this.scope.domainName);
|
|
12
|
-
this.device.dump();
|
|
13
|
-
console.groupEnd();
|
|
14
|
-
}
|
|
15
|
-
}
|
package/.built/position.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Section } from './section.js';
|
|
2
|
-
export declare class SectionPosition {
|
|
3
|
-
section: Section;
|
|
4
|
-
offset: number;
|
|
5
|
-
reversed: boolean;
|
|
6
|
-
constructor(section: Section, offset: number, reversed: boolean);
|
|
7
|
-
get absolutePosition(): number;
|
|
8
|
-
advance(distance: number): SectionPosition;
|
|
9
|
-
private invert;
|
|
10
|
-
toString(): string;
|
|
11
|
-
toPackTrackValue(): string;
|
|
12
|
-
}
|
package/.built/position.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export class SectionPosition {
|
|
2
|
-
section;
|
|
3
|
-
offset;
|
|
4
|
-
reversed;
|
|
5
|
-
constructor(section, offset, reversed) {
|
|
6
|
-
this.section = section;
|
|
7
|
-
this.offset = offset;
|
|
8
|
-
this.reversed = reversed;
|
|
9
|
-
if (offset > section.length || offset < 0) {
|
|
10
|
-
throw new Error(`Offset ${offset} out of range for section '${section.domainName}' (0 - ${section.length})`);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
// returns the absolute position of the point inside the section
|
|
14
|
-
// regardless of direction
|
|
15
|
-
get absolutePosition() {
|
|
16
|
-
if (this.reversed) {
|
|
17
|
-
return this.section.length - this.offset;
|
|
18
|
-
}
|
|
19
|
-
return this.offset;
|
|
20
|
-
}
|
|
21
|
-
// TODO verify reverse
|
|
22
|
-
advance(distance) {
|
|
23
|
-
if (distance < 0) {
|
|
24
|
-
return this.invert().advance(-distance).invert();
|
|
25
|
-
}
|
|
26
|
-
if (this.offset + distance > this.section.length) {
|
|
27
|
-
const next = this.section.next(this.reversed);
|
|
28
|
-
if (!next) {
|
|
29
|
-
throw new Error(`Illegal advancement ${this} + ${distance}`);
|
|
30
|
-
}
|
|
31
|
-
return new SectionPosition(next, 0, this.reversed).advance(this.offset + distance - this.section.length);
|
|
32
|
-
}
|
|
33
|
-
return new SectionPosition(this.section, this.offset + distance, this.reversed);
|
|
34
|
-
}
|
|
35
|
-
// reverse direction
|
|
36
|
-
invert() {
|
|
37
|
-
return new SectionPosition(this.section, this.section.length - this.offset, !this.reversed);
|
|
38
|
-
}
|
|
39
|
-
toString() {
|
|
40
|
-
return `${this.section.name} @ ${this.offset.toFixed(1)} ${this.reversed ? 'backward' : 'forward'}`;
|
|
41
|
-
}
|
|
42
|
-
toPackTrackValue() {
|
|
43
|
-
return `${this.section.domainName}@${this.offset}${this.reversed ? 'R' : 'F'}`;
|
|
44
|
-
}
|
|
45
|
-
}
|
package/.built/power-district.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export class PowerDistrict {
|
|
2
|
-
name;
|
|
3
|
-
district;
|
|
4
|
-
constructor(name, district) {
|
|
5
|
-
this.name = name;
|
|
6
|
-
this.district = district;
|
|
7
|
-
}
|
|
8
|
-
get domainName() {
|
|
9
|
-
return `${this.name}.${this.district.domainName}`;
|
|
10
|
-
}
|
|
11
|
-
dump() {
|
|
12
|
-
console.log(this.name);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/.built/route.d.ts
DELETED
package/.built/route.js
DELETED
package/.built/router.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { District } from "./district";
|
|
2
|
-
import { Route } from "./route";
|
|
3
|
-
export declare class Router {
|
|
4
|
-
name: string;
|
|
5
|
-
district: District;
|
|
6
|
-
activeRoute?: Route;
|
|
7
|
-
routes: Route[];
|
|
8
|
-
constructor(name: string, district: District);
|
|
9
|
-
get domainName(): string;
|
|
10
|
-
dump(): void;
|
|
11
|
-
toDotReference(): string;
|
|
12
|
-
toDotDefinition(): string;
|
|
13
|
-
toDotConnection(): string;
|
|
14
|
-
}
|
package/.built/router.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export class Router {
|
|
2
|
-
name;
|
|
3
|
-
district;
|
|
4
|
-
activeRoute;
|
|
5
|
-
routes = [];
|
|
6
|
-
constructor(name, district) {
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.district = district;
|
|
9
|
-
}
|
|
10
|
-
get domainName() {
|
|
11
|
-
return `${this.name}.${this.district.domainName}`;
|
|
12
|
-
}
|
|
13
|
-
dump() {
|
|
14
|
-
console.group(`Router ${this.domainName}`);
|
|
15
|
-
for (let route of this.routes) {
|
|
16
|
-
route.dump();
|
|
17
|
-
}
|
|
18
|
-
console.groupEnd();
|
|
19
|
-
}
|
|
20
|
-
toDotReference() {
|
|
21
|
-
return `router_${this.name.replace(/-/g, '_')}_${this.district.toDotReference()}`;
|
|
22
|
-
}
|
|
23
|
-
toDotDefinition() {
|
|
24
|
-
return `
|
|
25
|
-
${this.toDotReference()} [ label = ${JSON.stringify(this.name)}, shape = diamond ]
|
|
26
|
-
`;
|
|
27
|
-
}
|
|
28
|
-
toDotConnection() {
|
|
29
|
-
return `
|
|
30
|
-
${this.routes.map(route => `
|
|
31
|
-
${route.in.toDotReference()} -> ${this.toDotReference()} [ headlabel = ${JSON.stringify(route.name)} ]
|
|
32
|
-
${this.toDotReference()} -> ${route.out.toDotReference()} [ taillabel = ${JSON.stringify(route.name)} ]
|
|
33
|
-
`).join('')}
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
}
|
package/.built/section.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { District } from "./district";
|
|
2
|
-
import { SectionPosition } from "./position";
|
|
3
|
-
import { PowerDistrict } from "./power-district";
|
|
4
|
-
import { Router } from "./router";
|
|
5
|
-
import { Tile } from "./tile";
|
|
6
|
-
import { Track } from "./track";
|
|
7
|
-
export declare class Section {
|
|
8
|
-
name: string;
|
|
9
|
-
district: District;
|
|
10
|
-
powerDistrict: PowerDistrict;
|
|
11
|
-
tracks: Track[];
|
|
12
|
-
tiles: Tile[];
|
|
13
|
-
in?: Router | Section;
|
|
14
|
-
out?: Router | Section;
|
|
15
|
-
constructor(name: string, district: District);
|
|
16
|
-
get domainName(): string;
|
|
17
|
-
next(reverse: boolean): Section;
|
|
18
|
-
getTilesInRange(startPosition: SectionPosition, endPosition: SectionPosition): {
|
|
19
|
-
offset: {
|
|
20
|
-
start: number;
|
|
21
|
-
end: number;
|
|
22
|
-
};
|
|
23
|
-
tiles: Tile[];
|
|
24
|
-
};
|
|
25
|
-
dump(): void;
|
|
26
|
-
get length(): number;
|
|
27
|
-
get tileLength(): number;
|
|
28
|
-
trail(offset: number, reversed: boolean, length: number): {
|
|
29
|
-
sections: Section[];
|
|
30
|
-
tip: SectionPosition;
|
|
31
|
-
};
|
|
32
|
-
toDotReference(): string;
|
|
33
|
-
toDotDefinition(): string;
|
|
34
|
-
toDotConnection(): string;
|
|
35
|
-
toSVG(): string;
|
|
36
|
-
findSVGPositions(): {
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
}[];
|
|
40
|
-
}
|