@@ -2,27 +2,13 @@ import {
22 preloadWorkspaceGameAssetCatalog ,
33 resolveWorkspaceGameAssetPath
44} from "/games/shared/workspaceGameAssetCatalog.js" ;
5+ import {
6+ mapSolarSystemObjectsToLegacy ,
7+ validateSolarSystemSkinObjects
8+ } from "/games/SolarSystem/game/solarSkinContract.js" ;
59
610const SKIN_DOCUMENT_KIND = "game-skin" ;
711const BREAKOUT_BRICK_KEYS = Object . freeze ( [ "brick1" , "brick2" , "brick3" , "brick4" , "brick5" , "brick6" ] ) ;
8- const SOLAR_PLANET_IDS = Object . freeze ( [
9- "mercury" ,
10- "venus" ,
11- "earth" ,
12- "mars" ,
13- "jupiter" ,
14- "saturn" ,
15- "uranus" ,
16- "neptune"
17- ] ) ;
18- const SOLAR_MOON_IDS = Object . freeze ( [ "moon" , "io" , "europa" , "ganymede" , "titan" ] ) ;
19- const SOLAR_RING_IDS = Object . freeze ( [ "jupiter" , "saturn" , "uranus" , "neptune" ] ) ;
20- const SOLAR_RING_KEY_BY_PLANET = Object . freeze ( {
21- jupiter : "ringJupiter" ,
22- saturn : "ringSaturn" ,
23- uranus : "ringUranus" ,
24- neptune : "ringNeptune"
25- } ) ;
2612const SUPPORTED_OBJECT_SHAPES = Object . freeze ( [
2713 "circle" ,
2814 "oval" ,
@@ -177,43 +163,11 @@ function validateGameSkinObjects(gameId, objects) {
177163 }
178164
179165 if ( normalizedGameId === "solarsystem" ) {
180- const requiredPlanets = SOLAR_PLANET_IDS ;
181- const requiredMoons = SOLAR_MOON_IDS ;
182- const requiredRings = SOLAR_RING_IDS ;
183- return hasExpectedShape ( source ?. background , [ "hud-color" ] )
184- && isHexColor ( source ?. background ?. color )
185- && hasExpectedShape ( source ?. frame , [ "hud-color" ] )
186- && isHexColor ( source ?. frame ?. color )
187- && hasExpectedShape ( source ?. orbit , [ "hud-color" ] )
188- && isHexColor ( source ?. orbit ?. color )
189- && hasExpectedShape ( source ?. hudText , [ "hud-color" ] )
190- && isHexColor ( source ?. hudText ?. color )
191- && hasExpectedShape ( source ?. hudMuted , [ "hud-color" ] )
192- && isHexColor ( source ?. hudMuted ?. color )
193- && hasExpectedShape ( source ?. hudPanel , [ "hud-color" ] )
194- && isHexColor ( source ?. hudPanel ?. color )
195- && hasExpectedShape ( source ?. sun , [ "circle" ] )
196- && isHexColor ( source ?. sun ?. color )
197- && isPositiveNumber ( source ?. sun ?. radius )
198- && requiredPlanets . every ( ( id ) => (
199- hasExpectedShape ( source ?. [ id ] , [ "circle" ] )
200- && isHexColor ( source ?. [ id ] ?. color )
201- && isPositiveNumber ( source ?. [ id ] ?. radius )
202- ) )
203- && requiredMoons . every ( ( id ) => (
204- hasExpectedShape ( source ?. [ id ] , [ "circle" ] )
205- && isHexColor ( source ?. [ id ] ?. color )
206- && isPositiveNumber ( source ?. [ id ] ?. radius )
207- ) )
208- && requiredRings . every ( ( id ) => {
209- const ringObjectKey = SOLAR_RING_KEY_BY_PLANET [ id ] ;
210- const ring = source ?. [ ringObjectKey ] ;
211- return hasExpectedShape ( ring , [ "ring" ] )
212- && isHexColor ( ring ?. color )
213- && isPositiveNumber ( ring ?. innerRadius )
214- && isPositiveNumber ( ring ?. outerRadius )
215- && Number ( ring . outerRadius ) > Number ( ring . innerRadius ) ;
216- } ) ;
166+ return validateSolarSystemSkinObjects ( source , {
167+ hasExpectedShape,
168+ isHexColor,
169+ isPositiveNumber
170+ } ) ;
217171 }
218172
219173 return true ;
@@ -285,52 +239,7 @@ function mapObjectsToLegacy(gameId, objects, entities) {
285239 }
286240
287241 if ( normalizedGameId === "solarsystem" ) {
288- return {
289- colors : {
290- background : normalizeText ( source ?. background ?. color ) ,
291- frame : normalizeText ( source ?. frame ?. color ) ,
292- orbit : normalizeText ( source ?. orbit ?. color ) ,
293- text : normalizeText ( source ?. hudText ?. color ) ,
294- muted : normalizeText ( source ?. hudMuted ?. color ) ,
295- panel : normalizeText ( source ?. hudPanel ?. color )
296- } ,
297- sizing : { } ,
298- entities : {
299- sun : {
300- color : normalizeText ( source ?. sun ?. color ) ,
301- radius : Number ( source ?. sun ?. radius )
302- } ,
303- planets : Object . fromEntries (
304- SOLAR_PLANET_IDS . map ( ( id ) => {
305- const body = toObject ( source ?. [ id ] ) ;
306- return [ id , {
307- color : normalizeText ( body . color ) ,
308- radius : Number ( body . radius )
309- } ] ;
310- } )
311- ) ,
312- moons : Object . fromEntries (
313- SOLAR_MOON_IDS . map ( ( id ) => {
314- const body = toObject ( source ?. [ id ] ) ;
315- return [ id , {
316- color : normalizeText ( body . color ) ,
317- radius : Number ( body . radius )
318- } ] ;
319- } )
320- ) ,
321- rings : Object . fromEntries (
322- SOLAR_RING_IDS . map ( ( id ) => {
323- const ringObjectKey = SOLAR_RING_KEY_BY_PLANET [ id ] ;
324- const ring = toObject ( source ?. [ ringObjectKey ] ) ;
325- return [ id , {
326- color : normalizeText ( ring . color ) ,
327- innerRadius : Number ( ring . innerRadius ) ,
328- outerRadius : Number ( ring . outerRadius )
329- } ] ;
330- } )
331- )
332- }
333- } ;
242+ return mapSolarSystemObjectsToLegacy ( source , entities ) ;
334243 }
335244
336245 if ( normalizedGameId === "bouncing-ball" ) {
0 commit comments