lhaze / challenge-games

A notebook for challenge ideas & a repository for prototype implementations
0 stars 1 forks source link

Serialization #9

Open lhaze opened 7 years ago

lhaze commented 7 years ago

The whole of game (state, ruleset & settings) should be serializable. Map out its design and schema.

lhaze commented 7 years ago

Example serialization result:

{
    'types': {
        'colorResourceStack': {
            'factory': 'createResourceStack',
            'resourceNames': ['red', 'green', 'blue'],
        },
    },
    'assets': {
        'pawn_1': {
            'type': 'Token',
            'color': 'black',
        },
        'board': {
            'end_turn': {}
        }
    },
    'state': {
        'board': {
            'slot_red': {
                'value': {'ref': 'pawn_1'},
                'color': 'red',
            },
            'slot_blue': {
                'value': {
                    'type': 'colorResourceStack',
                    'value': {  // sic!
                        'red': 3,
                        'blue': 2,
                        'green': 1,
                    }
                },
                'color': 'blue',
            },
            'slot_green': {
                'color': 'green',
            }
        },
        'victory_points_counter': {
            'value': '5',
        },
    },
    'ruleset': {},
}
lhaze commented 7 years ago

The alternative is to use Dependency Injection 4 Javascript and build something like:

 di
  .register('ColorStack')
    .setFactory(createResourceStack)
      .param().val(['red', 'green', 'blue'])
  .register('pawn_1')
    .as(Token)
      .withConstructor()
        .param('color').val('black')

etc.

Here's the repo.

lhaze commented 7 years ago

I think doing both ways seems a nice exercise.