File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,26 @@ export default class DOMRenderer extends Renderer {
17
17
*/
18
18
constructor ( model ) {
19
19
super ( model ) ;
20
- this . setContainer ( document . createElement ( "div " ) ) ;
20
+ this . setContainer ( document . createElement ( "gravity " ) ) ;
21
21
}
22
22
23
23
/*---- Methods -------------------------------------------------------------*/
24
24
/** Render the game scene. */
25
25
render ( ) {
26
26
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 ) ;
30
41
}
31
42
}
You can’t perform that action at this time.
0 commit comments