From fdc23c1f91f81960d9dd9d7f8900361c3befe3d1 Mon Sep 17 00:00:00 2001 From: customcommander Date: Thu, 10 Oct 2024 08:02:14 +0100 Subject: [PATCH] refactor task 108 to use lib-task --- src/task-108.js | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/src/task-108.js b/src/task-108.js index 95cf728..85082cc 100644 --- a/src/task-108.js +++ b/src/task-108.js @@ -1,37 +1,21 @@ -import {base} from './task-lib.js'; +/* +@fileoverview +Take x CLay +*/ -function replenish(_, game_context) { - game_context.tasks[108].quantity += 1; - return game_context; -} +import task from './lib-task.js'; -function collect(_, game_context) { - const {quantity} = game_context.tasks[108]; - game_context.supply.clay += quantity; - game_context.tasks[108].quantity = 0; - return game_context; -} - - -export default base.createMachine({ - initial: 'idle', - states: { - idle: { - on: { - 'task.replenish': { - actions: [ - {type: 'game-update', params: {updater: replenish}}, - {type: 'ack'} - ] - }, - 'task.selected': { - actions: [ - {type: 'game-update', params: {updater: collect}}, - {type: 'task-complete'} - ] - } - } - } +export default task({ + id: '108', + replenish: (_, game) => { + game.tasks['108'].quantity += 1; + return game; + }, + execute: (_, game) => { + const {quantity} = game.tasks['108']; + game.supply.clay += quantity; + game.tasks['108'].quantity = 0; + return game; } });