Skip to content

Commit

Permalink
#6: Added type field to all model types, started styling resolve list…
Browse files Browse the repository at this point in the history
… components
  • Loading branch information
tomwwright committed Nov 21, 2017
1 parent 7ab97de commit e5d05c8
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 7 deletions.
24 changes: 24 additions & 0 deletions assets/maps/test.map.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "test-map",
"type": "map",
"nextId": 0,
"playerIds": [
"#PR",
Expand Down Expand Up @@ -36,6 +37,7 @@
"dataMap": {
"#PR": {
"id": "#PR",
"type": "player",
"colour": 16711680,
"territoryIds": [
"#T2"
Expand All @@ -55,6 +57,7 @@
},
"#PB": {
"id": "#PB",
"type": "player",
"colour": 255,
"territoryIds": [
"#T1",
Expand All @@ -75,6 +78,7 @@
},
"#PG": {
"id": "#PG",
"type": "player",
"colour": 10027263,
"territoryIds": [
"#T5"
Expand All @@ -91,6 +95,7 @@
},
"#T1": {
"id": "#T1",
"type": "territory",
"playerId": "#PB",
"unitIds": [
"#UR1",
Expand All @@ -113,6 +118,7 @@
},
"#T2": {
"id": "#T2",
"type": "territory",
"playerId": "#PR",
"unitIds": [
"#UR4"
Expand All @@ -127,6 +133,7 @@
},
"#T3": {
"id": "#T3",
"type": "territory",
"playerId": "#PB",
"unitIds": [
"#UB1",
Expand All @@ -146,6 +153,7 @@
},
"#T4": {
"id": "#T4",
"type": "territory",
"playerId": null,
"unitIds": [
"#U1"
Expand All @@ -163,6 +171,7 @@
},
"#T5": {
"id": "#T5",
"type": "territory",
"playerId": "#PG",
"unitIds": [
"#UG1"
Expand All @@ -180,63 +189,73 @@
},
"#E12": {
"id": "#E12",
"type": "edge",
"unitIds": [],
"territoryAId": "#T1",
"territoryBId": "#T2"
},
"#E13": {
"id": "#E13",
"type": "edge",
"unitIds": [],
"territoryAId": "#T1",
"territoryBId": "#T3"
},
"#E23": {
"id": "#E23",
"type": "edge",
"unitIds": [],
"territoryAId": "#T2",
"territoryBId": "#T3"
},
"#E34": {
"id": "#E34",
"type": "edge",
"unitIds": [],
"territoryAId": "#T3",
"territoryBId": "#T4"
},
"#E35": {
"id": "#E35",
"type": "edge",
"unitIds": [],
"territoryAId": "#T3",
"territoryBId": "#T5"
},
"#E45": {
"id": "#E45",
"type": "edge",
"unitIds": [],
"territoryAId": "#T4",
"territoryBId": "#T5"
},
"#UR1": {
"id": "#UR1",
"type": "unit",
"playerId": "#PR",
"locationId": "#T1",
"destinationId": null,
"statuses": []
},
"#UR2": {
"id": "#UR2",
"type": "unit",
"playerId": "#PR",
"locationId": "#T1",
"destinationId": null,
"statuses": []
},
"#UR3": {
"id": "#UR3",
"type": "unit",
"playerId": "#PR",
"locationId": "#T1",
"destinationId": "#T2",
"statuses": []
},
"#UR4": {
"id": "#UR4",
"type": "unit",
"playerId": "#PR",
"locationId": "#T2",
"destinationId": "#T3",
Expand All @@ -246,6 +265,7 @@
},
"#UB1": {
"id": "#UB1",
"type": "unit",
"playerId": "#PB",
"locationId": "#T3",
"destinationId": "#T2",
Expand All @@ -260,6 +280,7 @@
},
"#UB3": {
"id": "#UB3",
"type": "unit",
"playerId": "#PB",
"locationId": "#T3",
"destinationId": null,
Expand All @@ -269,6 +290,7 @@
},
"#UB4": {
"id": "#UB4",
"type": "unit",
"playerId": "#PB",
"locationId": "#T3",
"destinationId": "#T4",
Expand All @@ -278,13 +300,15 @@
},
"#UG1": {
"id": "#UG1",
"type": "unit",
"playerId": "#PG",
"locationId": "#T5",
"destinationId": "#T4",
"statuses": []
},
"#U1": {
"id": "#U1",
"type": "unit",
"playerId": null,
"locationId": "#T4",
"destinationId": null,
Expand Down
22 changes: 22 additions & 0 deletions src/game/components/CombatListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import { Text, Small } from 'rebass';

import InfoPane from 'game/components/InfoPane';

import { Colour, ColourStrings } from 'models/values';
import { ID } from 'models/utils';
import Combat from 'models/combat';

type CombatListItemProps = {
combat: Combat;
}

const CombatListItem: React.StatelessComponent<CombatListItemProps> = ({ combat }) => {
return (
<InfoPane>
<Text>Combat <Small>{combat.location.data.type == "territory" ? "Territory" : "Edge"} {combat.location.data.id} </Small></Text>
</InfoPane >
);
}

export default CombatListItem;
24 changes: 24 additions & 0 deletions src/game/components/PlayerListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { Text, Small } from 'rebass';

import InfoPane from 'game/components/InfoPane';

import { Colour, ColourStrings } from 'models/values';
import { ID } from 'models/utils';
import Player from 'models/player';

type PlayerListItemProps = {
player: Player;
}

const PlayerListItem: React.StatelessComponent<PlayerListItemProps> = ({ player }) => {
const colour = ColourStrings[player.data.colour];

return (
<InfoPane>
<Text color={colour}>Player {player.data.id}</Text>
</InfoPane>
);
}

export default PlayerListItem;
31 changes: 24 additions & 7 deletions src/game/components/ResolveInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as React from 'react';
import { Small, Text, Button } from 'rebass';
import InfoPane from 'game/components/InfoPane';
import UnitListItem from 'game/components/UnitListItem';
import PlayerListItem from 'game/components/PlayerListItem';
import CombatListItem from 'game/components/CombatListItem';
import TerritoryListItem from 'game/components/TerritoryListItem';

import GameStore from 'game/stores/game';
import UiStore from 'game/stores/ui';
import GameStore, { ResolveState } from 'game/stores/game';

import Player from 'models/player';
import { TerritoryAction, TerritoryActionDefinitions, ColourStrings } from 'models/values';
import UiStore from 'game/stores/ui';

type ResolveInfoProps = {
gameStore: GameStore;
Expand All @@ -20,10 +22,25 @@ const ResolveInfo: React.StatelessComponent<ResolveInfoProps> = ({ gameStore, ui
<Text>
Resolving: {gameStore.resolveState}
</Text>
<Small>
{gameStore.resolveIds.map((id, i) => <Text key={i}>ID {id}</Text>)}
</Small>
</InfoPane>

{gameStore.resolveIds.map((id, i) => {
switch (gameStore.resolveState) {
case ResolveState.ADD_DEFEND:
case ResolveState.EDGE_MOVES:
case ResolveState.MOVES:
return <UnitListItem key={i} unit={gameStore.map.unit(id)} />;
case ResolveState.FOOD:
case ResolveState.TERRITORY_ACTIONS:
case ResolveState.TERRITORY_CONTROL:
return <TerritoryListItem key={i} territory={gameStore.map.territory(id)} />;
case ResolveState.GOLD:
return <PlayerListItem key={i} player={gameStore.map.player(id)} />
case ResolveState.COMBATS:
return <CombatListItem key={i} combat={gameStore.combats.find(combat => combat.location.data.id === id)} />
}
})}

<Button onClick={() => uiStore.onClickResolve(gameStore.resolveIds[0])}>Resolve</Button>
</div>
);
Expand Down
24 changes: 24 additions & 0 deletions src/game/components/TerritoryListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { Text, Small } from 'rebass';

import InfoPane from 'game/components/InfoPane';

import { Colour, ColourStrings } from 'models/values';
import { ID } from 'models/utils';
import Territory from 'models/territory';

type TerritoryListItemProps = {
territory: Territory;
}

const TerritoryListItem: React.StatelessComponent<TerritoryListItemProps> = ({ territory }) => {
const colour = ColourStrings[territory.player ? territory.player.data.colour : Colour.BLACK];

return (
<InfoPane>
<Text color={colour}>Territory {territory.data.id}</Text>
</InfoPane>
);
}

export default TerritoryListItem;
24 changes: 24 additions & 0 deletions src/game/components/UnitListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { Text, Small } from 'rebass';

import InfoPane from 'game/components/InfoPane';

import { Colour, ColourStrings } from 'models/values';
import { ID } from 'models/utils';
import Unit from 'models/unit';

type UnitListItemProps = {
unit: Unit;
}

const UnitListItem: React.StatelessComponent<UnitListItemProps> = ({ unit }) => {
const colour = ColourStrings[unit.player ? unit.player.data.colour : Colour.BLACK];

return (
<InfoPane>
<Text color={colour}>Unit {unit.data.id} <Small color={ColourStrings[Colour.BLACK]}>{unit.location.data.type == "territory" ? "Territory" : "Edge"} {unit.data.locationId}</Small></Text>
</InfoPane>
);
}

export default UnitListItem;
1 change: 1 addition & 0 deletions src/models/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UnitContainer, { UnitContainerData } from "models/unitcontainer";
import Territory from "models/territory";

export type EdgeData = UnitContainerData & {
type: "edge";
territoryAId: ID;
territoryBId: ID;
};
Expand Down
2 changes: 2 additions & 0 deletions src/models/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { applyMoveUnits } from 'models/actions/move';
import { applyTerritoryAction } from 'models/actions/territory';

export type GameMapData = HasID & {
type: "map";
dataMap: DataMap;
territoryIds: ID[];
playerIds: ID[];
Expand Down Expand Up @@ -107,6 +108,7 @@ export default class GameMap extends UnitContainer<GameMapData> {

addUnit(territory: Territory): GameMap {
const unitData: UnitData = {
type: "unit",
id: toID(this.data.nextId),
playerId: territory.data.playerId,
locationId: territory.data.id,
Expand Down
1 change: 1 addition & 0 deletions src/models/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Unit from "models/unit";
import { Colour } from "models/values";

export type PlayerData = UnitContainerData & {
type: "player";
colour: Colour;
territoryIds: ID[];
gold: number;
Expand Down
1 change: 1 addition & 0 deletions src/models/territory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Unit from "models/unit";
import { TerritoryProperty, TerritoryAction, TerritoryActionDefinitions, TerritoryType, propsToActions, propsToType, Status } from "models/values";

export type TerritoryData = UnitContainerData & {
type: "territory";
edgeIds: ID[];
playerId: ID;
food: number;
Expand Down
Loading

0 comments on commit e5d05c8

Please sign in to comment.