MCPcopy Create free account
hub / github.com/JKPotato-Computer/SignMaker / Post

Class Post

js/Post.js:1–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Post {
2 /**
3 * Post that contains the panels.
4 * @param {string} polePosition - Position of the poles on which to display the panels.
5 * @param {number} [lanesWide=1] - How many lanes wide the post should appear to be.
6 */
7 constructor(polePosition, lanesWide = 1) {
8 if (this.polePositions.includes(polePosition)) {
9 this.polePosition = polePosition;
10 } else {
11 this.polePosition = this.polePositions[0];
12 }
13 if (lanesWide >= 1 && lanesWide <= 6) {
14 this.lanesWide = lanesWide;
15 } else {
16 this.lanesWide = 1;
17 }
18 this.panels = [];
19 }
20
21 /**
22 * Create a new panel for the post. Add it to the end of the list of existing panels.
23 */
24 newPanel() {
25 const newSign = new Sign();
26 newSign.newSubPanel();
27
28
29 const newPanel = new Panel(newSign, undefined);
30 const exitTab = new ExitTab();
31 newPanel.exitTabs.push(exitTab);
32
33 this.panels.push(newPanel);
34 }
35
36 /**
37 * Duplicate an existing panel. Add it immediately after the panel being duplicated.
38 * @param {number} panelIndex - Position of the panel in the array of panels on this post.
39 */
40 duplicatePanel(panelIndex) {
41 const existingPanel = this.panels[panelIndex];
42 const newSubPanels = [];
43 for (const subPanel of existingPanel.sign.subPanels) {
44 newSubPanels.push(Object.assign(new SubPanels(), subPanel));
45 }
46
47 const newExitTabs = [];
48 for (const exitTab of existingPanel.exitTabs) {
49 newExitTab.push(Object.assign(new ExitTab(), exitTab));
50 }
51
52 const newSign = new Sign({
53 shieldPosition : existingPanel.sign.shieldPosition,
54 subPanels : newSubPanels,
55 sheildBacks : existingPanel.sign.sheildBacks,
56 guideArrow : existingPanel.sign.guideArrow,
57 guideArrowLanes : existingPanel.sign.guideArrowLanes,
58 });
59 const newPanel = Object.assign(new Panel(), existingPanel);
60 newPanel.sign = newSign;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected