MCPcopy
hub / github.com/walterhiggins/ScriptCraft / convertToMenuSign

Function convertToMenuSign

src/main/js/modules/signs/menu.js:92–144  ·  view source on GitHub ↗
(/* Sign */ sign, save)

Source from the content-addressed store, hash-verified

90 The function returned by signs.menu is for use by admins/ops.
91 */
92 var convertToMenuSign = function(/* Sign */ sign, save) {
93 if (typeof save == 'undefined') {
94 save = true;
95 }
96 //
97 // per-sign variables go here
98 //
99 var cSelectedIndex = selectedIndex;
100 setLine(sign, 0, paddedLabel.bold());
101 var _updateSign = function(p_player, p_sign) {
102 cSelectedIndex = (cSelectedIndex + 1) % optLen;
103 _redrawMenuSign(p_sign, cSelectedIndex, displayOptions);
104 var signSelectionEvent = {
105 player: p_player,
106 sign: p_sign,
107 text: options[cSelectedIndex],
108 number: cSelectedIndex
109 };
110 callback(signSelectionEvent);
111 };
112
113 /*
114 get a unique ID for this particular sign instance
115 */
116 var signLoc = sign.block.location;
117 var menuSignSaveData = utils.locationToJSON(signLoc);
118 var menuSignUID = JSON.stringify(menuSignSaveData);
119 /*
120 keep a reference to the update function for use by the event handler
121 */
122 _updaters[menuSignUID] = _updateSign;
123
124 // initialize the sign
125 _redrawMenuSign(sign, cSelectedIndex, displayOptions);
126
127 /*
128 whenever a sign is placed somewhere in the world
129 (which is what this function does)
130 save its location for loading and initialization
131 when the server starts up again.
132 */
133 if (save) {
134 if (typeof store.menus == 'undefined') {
135 store.menus = {};
136 }
137 var signLocations = store.menus[label];
138 if (typeof signLocations == 'undefined') {
139 signLocations = store.menus[label] = [];
140 }
141 signLocations.push(menuSignSaveData);
142 }
143 return sign;
144 }; // end of convertToMenuSign function
145
146 /*
147 a new sign definition - need to store (in-memory only)

Callers 1

signMenuFunction · 0.85

Calls 1

_redrawMenuSignFunction · 0.85

Tested by

no test coverage detected