Skip to content

Commit 802ad3c

Browse files
committed
Add Celestials to Renderer#container
1 parent d0bf90a commit 802ad3c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

js/modules/DOMRenderer.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,26 @@ export default class DOMRenderer extends Renderer {
1717
*/
1818
constructor(model) {
1919
super(model);
20-
this.setContainer(document.createElement("div"));
20+
this.setContainer(document.createElement("gravity"));
2121
}
2222

2323
/*---- Methods -------------------------------------------------------------*/
2424
/** Render the game scene. */
2525
render() {
2626
const scene = this.model.scene;
27-
scene.forEach(
28-
(obj) => obj.element || (obj.element = document.createElement("div"))
29-
);
27+
// Make sure each Celestial has an Element
28+
scene.forEach((obj) => obj.element || this.generateElement(obj));
29+
}
30+
/**
31+
* Create a rendering Element for a Celestial and append it to the container.
32+
* @arg {Celestial} celestial
33+
*/
34+
generateElement(celestial) {
35+
const element = document.createElement("celestial"),
36+
// Clean up the name for adding into a CSS class
37+
cleanName = celestial.name.replace(/\s+/g, "-").toLowerCase();
38+
element.classList.add(`gravity__celestial_${cleanName}`);
39+
celestial.element = element;
40+
this.container.append(celestial.element);
3041
}
3142
}

0 commit comments

Comments
 (0)