Closed Itangalo closed 2 years ago
No. The general approach became almost as long as the explicit approach, and less readable.
Saving it here anyway, if the number of classes grow in the future.
let objectTypesToCreate = {
agents: {class: Agent},
decks: {class: Deck, args: ['deck', 'cards']},
tracks: {class: Track, args: ['track', 'spaces', 'pawns']},
markets: {class: Market, args: ['market', 'goods']},
};
for (let i in objectTypesToCreate) {
if (gameState[i]) {
delete(gameState[i]);
for (let d of gameStateSeed[i]) {
if (!objectTypesToCreate[i].args) {
new objectTypesToCreate[i].class(d);
}
else {
let args = [];
for (let a of objectTypesToCreate[i].args)
args.push(d[a]);
new objectTypesToCreate[i].class(...args);
}
}
}
}
The
simulate
function repeats a lot of code when creating agents, decks, tracks and markets. It could probably be more streamlined, with less repetition.