diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx
index 3f5ce79..9d1eadb 100644
--- a/src/components/farm/Board.jsx
+++ b/src/components/farm/Board.jsx
@@ -40,7 +40,7 @@ import Tractor from '../tractor/Tractor.jsx'
import { GAME_STATES, ALERTS } from '../../constants.js'
import { itemCard, itemCardShort, fateCard, ridgeNames } from 'game.js'
import { setSelectedCard, setMessagePanelSpace, setMPDims, movePlayer,
- nextUIAction, alert, alertHandled } from './actions.js'
+ nextUIAction, alert, alertHandled, setCardError } from './actions.js'
import { buy, roll, endTurn, loan, trade, submitTradeAccept,
submitTradeDeny, submitTradeCancel, audit,
buyUncleBert, skip } from './interface.js'
@@ -1673,20 +1673,23 @@ class BoardApp extends React.Component {
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -1730,7 +1733,7 @@ class BoardApp extends React.Component {
export default connect(
state => state.farm,
- { setMessagePanelSpace, setMPDims, nextUIAction, movePlayer, alert, alertHandled }
+ { setMessagePanelSpace, setMPDims, nextUIAction, movePlayer, alert, alertHandled, setCardError }
)(BoardApp)
class Card extends React.Component {
@@ -1755,6 +1758,7 @@ class Card extends React.Component {
parseInt(target.value)), this.props.max);
if (isNaN(value)) { value = this.props.min; }
this.setState({ cash: value });
+ this.props.setCardError(false);
}
handleSubmit = e => {
@@ -1799,6 +1803,13 @@ class Card extends React.Component {
+ {this.props.ui.cardError ? (
+
+
+ {this.props.ui.cardError}
+
+
+ ) : (<>>)}
); break;
@@ -1831,9 +1842,9 @@ class CardListComp extends React.Component {
cards = ui.cards,
cardOps = cards.map((c, i) =>
( this.props.setCard(c)}>
- {c.summary}
- ));
+ onClick={() => { this.props.setCard(c); this.props.setCardError(false); }}>
+ {c.summary}
+ ));
return (
@@ -1847,5 +1858,5 @@ class CardListComp extends React.Component {
const CardList = connect(
null,
- { setSelectedCard }
+ { setSelectedCard, setCardError }
)(CardListComp)
diff --git a/src/components/farm/actionTypes.js b/src/components/farm/actionTypes.js
index 3a13924..b31c71c 100644
--- a/src/components/farm/actionTypes.js
+++ b/src/components/farm/actionTypes.js
@@ -21,6 +21,7 @@ export const UPDATE_PLAYER = 'update-player';
export const GAME_STATE = 'game-state';
export const SET_SELECTED_CARD = 'set-selected-card';
export const SET_CARDS = 'set-cards';
+export const SET_CARD_ERROR = 'set-card-error';
export const SPACE_PUSH_PLAYER = 'space-push-player';
export const SPACE_CLEAR_PLAYERS = 'space-clear-players';
export const SET_OLD_MESSAGES = 'set-old-messages';
diff --git a/src/components/farm/actions.js b/src/components/farm/actions.js
index 803c34a..2af7f2b 100644
--- a/src/components/farm/actions.js
+++ b/src/components/farm/actions.js
@@ -20,13 +20,13 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
SPACE_PUSH_PLAYER, SPACE_CLEAR_PLAYERS, SET_OLD_MESSAGES, MESSAGE_PANEL_SPACE,
MP_MOUSE, SET_MP_DIMS, MARK_ACTION_CHANGE_HANDLED, SET_NEXT_ACTION,
MOVE_PLAYER, NEXT_UI_ACTION, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
- AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE } from './actionTypes.js'
+ AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR } from './actionTypes.js'
export { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
spacePushPlayer, spaceClearPlayers, setOldMessages, setMessagePanelSpace,
mpMouse, setMPDims, movePlayer, setNextAction, nextUIAction,
markActionChangeHandled, nextUIActionSilent, alert, alertHandled,
- autoSkip, message, setHarvestTable }
+ autoSkip, message, setHarvestTable, setCardError }
function updateGame(update) {
return { type: UPDATE_GAME,
@@ -54,6 +54,10 @@ function setCards(cards) {
cards };
}
+function setCardError(error) {
+ return { type: SET_CARD_ERROR, error };
+}
+
function spacePushPlayer(id, player) {
return { type: SPACE_PUSH_PLAYER,
id,
diff --git a/src/components/farm/interface.js b/src/components/farm/interface.js
index c95e97d..f3c904c 100644
--- a/src/components/farm/interface.js
+++ b/src/components/farm/interface.js
@@ -24,7 +24,7 @@ import * as websocket from '../../websocket.js'
import { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
movePlayer, setOldMessages, markActionChangeHandled,
mpMouse, rolled, setNextAction, nextUIAction, nextUIActionSilent, alert,
- autoSkip, message, alertHandled, setHarvestTable } from './actions.js'
+ autoSkip, message, alertHandled, setHarvestTable, setCardError } from './actions.js'
import { itemCard, fateCard } from 'game.js'
export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept,
@@ -63,6 +63,9 @@ function handleMessage(evt) {
store.dispatch(setNextAction(false, false));
store.dispatch(nextUIAction());
}
+ if (data.event === 'buy' && data.error) {
+ store.dispatch(setCardError(data.error));
+ }
store.dispatch(updatePlayer(data.player));
if (data.event === 'init') {
store.dispatch(movePlayer(data.player.space, 0, data.player.color));
diff --git a/src/components/farm/reducers.js b/src/components/farm/reducers.js
index a5fb4dc..4f245ef 100644
--- a/src/components/farm/reducers.js
+++ b/src/components/farm/reducers.js
@@ -21,7 +21,7 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
SET_OLD_MESSAGES, MESSAGE_PANEL_SPACE, MP_MOUSE,
SET_MP_DIMS, MOVE_PLAYER, SET_NEXT_ACTION, NEXT_UI_ACTION,
MARK_ACTION_CHANGE_HANDLED, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
- AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE } from './actionTypes.js'
+ AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR } from './actionTypes.js'
import { GAME_STATES } from '../../constants.js'
import { spaceContent, corners } from 'game.js'
@@ -107,6 +107,7 @@ const initialState = {
},
ui: { card: { type: 'no-card', contents: '', total: 0 },
cards: [],
+ cardError: false,
action: false,
actionValue: null,
nextAction: false,
@@ -140,6 +141,8 @@ export default function(state = initialState, action) {
return { ...state, ui: { ...state.ui, card: action.card }};
case SET_CARDS:
return { ...state, ui: { ...state.ui, cards: action.cards }};
+ case SET_CARD_ERROR:
+ return { ...state, ui: { ...state.ui, cardError: action.error }};
case MOVE_PLAYER:
return { ...state, spaces: state.spaces
.map((item, index) => {
diff --git a/src/server/farm.scm b/src/server/farm.scm
index 02e3f1f..b49d073 100644
--- a/src/server/farm.scm
+++ b/src/server/farm.scm
@@ -375,28 +375,20 @@
(ridges '(ridge1 ridge2 ridge3 ridge4)))
(cond ((and (member unnormalized-crop ridges)
(not (ridge-available? game unnormalized-crop)))
- (push-message player (conc "Ridge already leased."))
- #f)
+ "Ridge already leased.")
((> (player-space player) 14)
- (push-message player (conc "Crops may only be bought in winter."))
- #f)
+ "Crops may only be bought in winter.")
((> cash-value (player-cash player))
- (push-message player (conc "Could not buy " unnormalized-crop ". Not enough cash."))
- #f)
+ (conc "Could not buy " unnormalized-crop ". Not enough cash."))
((< cash-value (* total-cost (game-setting 'down-payment game)))
- (push-message player
- (conc "Could not buy " unnormalized-crop ". Not enough down payment."))
- #f)
- ((> (- total-cost cash-value) (- (game-setting 'max-debt game) (player-debt player)))
- (push-message player
- (conc "Could not buy " unnormalized-crop ". Not enough credit."))
- #f)
+ (conc "Could not buy " unnormalized-crop ". Not enough down payment."))
+ ((> (- total-cost cash-value) (max 0 (- (game-setting 'max-debt game) (player-debt player))))
+ (conc "Could not buy " unnormalized-crop ". Not enough credit."))
((and (eq? unnormalized-crop 'cows)
(= (- (player-asset 'cows player)
(fold + 0 (map cdr (player-ridges player))))
20))
- (push-message player (conc "Could not buy " unnormalized-crop " because it would exceed maximum allowed on farm."))
- #f)
+ (conc "Could not buy " unnormalized-crop " because it would exceed maximum allowed on farm."))
(else
(let ((assets (player-assets player)))
(safe-set!
@@ -408,7 +400,6 @@
(when (member unnormalized-crop ridges)
(safe-set! (player-ridges player)
(alist-update unnormalized-crop amount (player-ridges player))))
- (push-message player (conc "You bought " amount " " crop "."))
#t)))))
(define (make-player-year-rule id rule)
@@ -880,26 +871,29 @@
((string=? type "buy")
(let* ((id (alist-ref 'id msg))
(otb (find (lambda (x) (= id (alist-ref 'id x)))
- (player-otbs player))))
- (when (buy-crop (normalize-crop
- (string->symbol (alist-ref 'crop otb)))
- (string->symbol (alist-ref 'crop otb))
- (alist-ref 'amount otb)
- (* (or (and (number? (alist-ref 'cash msg))
- (alist-ref 'cash msg))
- 0)
- 1000)
- player
- game)
- (safe-set! (game-otbs game)
- (append (game-otbs game)
- (filter (lambda (x) (= id (alist-ref 'id x)))
- (player-otbs player))))
- (safe-set! (player-otbs player)
- (filter (lambda (x) (not (= id (alist-ref 'id x))))
- (player-otbs player)))))
- (message-players! game player '() type: "update")
- (create-ws-response player "buy" '()))
+ (player-otbs player)))
+ (bought-crop (buy-crop (normalize-crop
+ (string->symbol (alist-ref 'crop otb)))
+ (string->symbol (alist-ref 'crop otb))
+ (alist-ref 'amount otb)
+ (* (or (and (number? (alist-ref 'cash msg))
+ (alist-ref 'cash msg))
+ 0)
+ 1000)
+ player
+ game)))
+ (if (eq? bought-crop #t)
+ (begin
+ (safe-set! (game-otbs game)
+ (append (game-otbs game)
+ (filter (lambda (x) (= id (alist-ref 'id x)))
+ (player-otbs player))))
+ (safe-set! (player-otbs player)
+ (filter (lambda (x) (not (= id (alist-ref 'id x))))
+ (player-otbs player)))
+ (message-players! game player '() type: "update")
+ (create-ws-response player "buy" '()))
+ (create-ws-response player "buy" `((error . ,bought-crop))))))
((string=? type "buy-uncle-bert")
(safe-set! (player-cash player) (- (player-cash player) 10000))
(safe-set! (player-assets player)
@@ -1873,7 +1867,6 @@
;; mark spaces
-;; support trading farmers fates
-;; test tractor/harvester a lot better
-
;; trade notification keeps popping up
+
+;; you can see how much money you make before you harvest
diff --git a/src/style.scss b/src/style.scss
index c8e1ee5..2732007 100644
--- a/src/style.scss
+++ b/src/style.scss
@@ -558,7 +558,7 @@ $tab-margin: 0.3rem;
flex-grow: 2;
}
@include breakpoint(large) {
- width: 40rem;
+ width: 26rem;
}
}
@@ -804,3 +804,8 @@ $intro-time: 6s;
bottom: 0;
opacity: 0.5;
right: 4px; }
+
+.error {
+ font-size: 1.2rem;
+ color: red;
+ font-weight: bold }
diff --git a/webpack.common.js b/webpack.common.js
index 7fca86f..5bd0cc7 100644
--- a/webpack.common.js
+++ b/webpack.common.js
@@ -46,8 +46,7 @@ module.exports = {
chunkFilename: '[id].css',
}),
new CopyPlugin([
- { from: './src/server/farm.scm', to: './farm.scm' },
- { from: './src/server/farm', to: './farm' },
+ { from: './src/server/', to: './' },
{ from: './assets/game/', to: './assets/game/' }
]),
new webpack.LoaderOptionsPlugin({