MCPcopy Create free account
hub / github.com/melonjs/melonJS / _buildPanel

Method _buildPanel

packages/debug-plugin/src/index.js:137–259  ·  view source on GitHub ↗

@private

()

Source from the content-addressed store, hash-verified

135
136 /** @private */
137 _buildPanel() {
138 this.panelWrap = document.createElement("div");
139 this.panelWrap.className = "dbg-wrap";
140
141 this.panel = document.createElement("div");
142 this.panel.className = "dbg";
143 this.panelWrap.appendChild(this.panel);
144 this.panelWrap.style.display = "none";
145
146 // helper to create a stat as two grid cells: label | value
147 const stat = (id, label) => {
148 const dimEl = document.createElement("span");
149 dimEl.className = "dim";
150 dimEl.textContent = label;
151 const valEl = document.createElement("span");
152 valEl.className = "val";
153 valEl.textContent = "0";
154 this.stats[id] = valEl;
155 return [dimEl, valEl];
156 };
157
158 // helper to create a checkbox label
159 const checkbox = (key, label) => {
160 const el = document.createElement("label");
161 const cb = document.createElement("input");
162 cb.type = "checkbox";
163 cb.checked = this.options[key];
164 cb.addEventListener("change", () => {
165 this.options[key] = cb.checked;
166 game.repaint();
167 });
168 el.appendChild(cb);
169 el.appendChild(document.createTextNode(label));
170 return el;
171 };
172
173 const toggleKey =
174 Object.keys(input.KEY).find((k) => {
175 return input.KEY[k] === this.debugToggle;
176 }) ?? "?";
177
178 // helper to append a stat (two grid cells) or a single element spanning 2 columns
179 const addStat = (id, label) => {
180 const [dimEl, valEl] = stat(id, label);
181 this.panel.appendChild(dimEl);
182 this.panel.appendChild(valEl);
183 };
184 const addSpan2 = (el) => {
185 el.style.gridColumn = "span 2";
186 this.panel.appendChild(el);
187 };
188
189 // row 1
190 addStat("objects", "#objects");
191 addSpan2(checkbox("hitbox", "hitbox"));
192 addSpan2(checkbox("quadtree", "quadtree"));
193 addStat("update", "Update");
194 addStat("heap", "Heap");

Callers 1

constructorMethod · 0.95

Calls 1

_syncPositionMethod · 0.95

Tested by

no test coverage detected