Skip to content

Commit

Permalink
define fields as property of a task
Browse files Browse the repository at this point in the history
  • Loading branch information
customcommander committed Jan 15, 2025
1 parent 02bea30 commit ab9c081
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
Bootstrap.
0XX Game Stuff
---
001 Fields
002 Feed
1XX Actions (on the board)
---
103 Take Grain
107 Take x Wood
108 Take x Clay
Expand All @@ -20,6 +24,11 @@ Bootstrap.
118 Take Vegetable
119 Take x Wild Boar
What does each property mean?
fields:
The task will be invoked during the field phase.
*/

import {
Expand All @@ -30,7 +39,7 @@ import {
} from 'xstate';

const taskdefs = {
'001': {},
'001': {fields: true},
'002': {feeding: true},
'101': {selected: false},
'102': {selected: false},
Expand Down
10 changes: 7 additions & 3 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ const machine = src.createMachine({
*/
on_replenish: ['107', '108', '109', '110', '114', '116', '119'],
on_fields: ['001'],
}),
"initial": "init",
"states": {
Expand Down Expand Up @@ -284,8 +283,13 @@ const machine = src.createMachine({
src: 'dispatcher',
systemId: 'dispatcher',
input: ({context}) => {
const {on_fields: notify} = context;
const jobs = notify.map(task_id => ({task_id, ev: 'task.fields'}));
const entries = Object.entries(context.tasks);
const jobs = entries.reduce(
(acc, [task_id, def]) =>
def.fields === true
? acc.concat({task_id, ev: 'task.fields'})
: acc
, []);
return {jobs};
},
onDone: {
Expand Down

0 comments on commit ab9c081

Please sign in to comment.