Skip to content

Commit

Permalink
Merge branch 'master' into cheukyin699/#93-component-unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck-sys committed Feb 29, 2020
2 parents f9027fb + 4083afe commit eae5b60
Show file tree
Hide file tree
Showing 21 changed files with 4,116 additions and 4,372 deletions.
7,352 changes: 3,721 additions & 3,631 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"mocha": "^6.2.1",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-scripts": "3.2.0",
"react-scripts": "^3.3.1",
"react-test-renderer": "^16.12.0",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
Expand Down
54 changes: 28 additions & 26 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React from "react";

import {IEvent, IChoice} from "./events/core";
import LandingEvent from "./events/LandingEvent";
import PickFacultyEvent from "./events/PickFacultyEvent";
import BoomerGregorEvent from "./events/BoomerGregorEvent";
import {CuteGirlEvent} from "./events/CuteGirlEvent";
import FratPartyEvent from "./events/FratPartyEvent";
import { IEvent, IChoice } from "./events/core";

import PlayerStats from "./trackers/PlayerStats";
import EventTracker from "./trackers/EventTracker";

import ChoicesManager from "./events/ChoicesManager";
import EventsManager from "./events/EventsManager";
import events from "./events.json";
import choices from "./choices.json";
import Hud from "./components/hud/Hud";
import GamePlayConsole from "./components/gamePlayConsole/GamePlayConsole";
import Choices from "./components/choices/Choices";

// tslint:disable-next-line:no-empty-interface
export interface IProps {}
export interface IProps { }

export interface IState {
week: number;
Expand All @@ -24,22 +22,25 @@ export interface IState {
eventTracker: EventTracker;
}

export default class App extends React.Component <IProps, IState> {
export default class App extends React.Component<IProps, IState> {
private name: string;
private choiceManager: ChoicesManager;
private eventManager: EventsManager;

constructor(props: IProps) {
super(props);

const playerStats = new PlayerStats();
const eventTracker = new EventTracker(
[new BoomerGregorEvent(), new CuteGirlEvent(), new FratPartyEvent()],
[new LandingEvent(), new PickFacultyEvent()]
[events.BoomerGregorEvent, events.CuteGirlEvent, events.FratPartyEvent],
[events.LandingEvent, events.PickFacultyEvent, events.PickResidenceEvent]
);
let firstEvent = eventTracker.getNextEvent();

//TODO: should we auto allocate a dummy player name or allow user to input their own?
this.name = "P1";

this.choiceManager = new ChoicesManager(choices);
this.eventManager = new EventsManager(events);
this.state = {
// TODO: The week number may not be how we choose to track time,
// we should create some abstraction for this similar to how
Expand All @@ -53,11 +54,11 @@ export default class App extends React.Component <IProps, IState> {
}

makeChoice = (choice: IChoice) => {
this.state.playerStats.applyStatChanges(choice.statChanges());

for (let followUp of choice.followUps()) {
this.state.eventTracker.queueFollowUpEvent(followUp);
}
this.state.playerStats.applyStatChanges(choice.statChanges, choice.dlogo);
if (choice.followUp !== ""){
this.state.eventTracker.queueFollowUpEvent(this.eventManager.get(choice.followUp));
}

let nextEvent = this.state.eventTracker.getNextEvent();

Expand All @@ -77,24 +78,25 @@ export default class App extends React.Component <IProps, IState> {
<div id="app">
<div id="game-container">
<Hud
playerStats={this.state.playerStats}
week={this.state.week}
name={this.name}
playerStats={this.state.playerStats}
week={this.state.week}
name={this.name}
/>
<GamePlayConsole
mode={currentEvent.gamePlayMode()}
imgPath={currentEvent.imgPath()}
mode={currentEvent.gamePlayMode}
imgPath={currentEvent.imgPath}
/>
<section
id="user-interaction-box"
className={currentEvent.hasBottomBoxBorder() ? "nes-container is-rounded" : ""}
id="user-interaction-box"
className={currentEvent.hasBottomBoxBorder ? "nes-container is-rounded" : ""}
>
<div id="bottom-menu" className="bottom-container">
<p id="prompt" className="this-align-center">
{currentEvent.prompt()}
{currentEvent.prompt}
</p>
<Choices
choices={currentEvent.choices()}
choices={currentEvent.choices}
mgr={this.choiceManager}
makeChoice={this.makeChoice}
/>
</div>
Expand Down
144 changes: 144 additions & 0 deletions src/choices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"TrustNaturalRecursion":
{
"answer":"Trust the natural recursion",
"followUp":"",
"statChanges":[10, 0.5, -15]
},
"OkBoomer":
{
"answer":"Ok, Boomer",
"followUp":"",
"statChanges":[60, -0.02, -8]
},
"FiveverAlone":
{
"answer":"5ever alone",
"followUp":"",
"statChanges":[-50, -1.5, -15]
},
"RunAway":
{
"answer":"meep merp. run away",
"followUp":"",
"statChanges":[-25, 0, -15]
},
"ShowFilas":
{
"answer":"Show her your Filas",
"followUp":"",
"statChanges":[35, 0.5, 0]
},
"BuyTheTix":
{
"answer":"Buy her EDC (Electronic Daisy Carnival) tickets",
"followUp":"CuteGirlTixEvent",
"statChanges":[5, -0.01, 0]
},
"ComplimentFilas":
{
"answer":"Compliment her Filas",
"followUp":"CuteFilasEvent",
"statChanges":[1, 0, 0]
},
"StalkInstagram":
{
"answer":"Stalk her on Instagram",
"followUp":"",
"statChanges":[-50, -1.5, -35]
},
"OhYes":
{
"answer":"OH YES",
"followUp":"HasBoyfriendEvent",
"statChanges":[20, -0.02, -3]
},
"Nope":
{
"answer":"no...",
"followUp":"NoVIPTixEvent",
"statChanges":[-5, 0, 0]
},
"GrossFrats":
{
"answer":"Ew! Frats are gross!",
"followUp":"",
"statChanges":[-20, 0.5, 5]
},
"YayBedsheets":
{
"answer":"I love wearing my bedsheets!",
"followUp":"",
"statChanges":[40, -1.0, -50]
},
"Start":
{
"answer":"Accept Offer",
"followUp":"",
"statChanges":[0, 0, 0]
},
"Arts":
{
"answer":"Arts",
"followUp":"",
"statChanges":[50, 2.0, 100],
"dlogo": "ARTS.png"
},
"ApScience":
{
"answer":"Applied Science",
"followUp":"",
"statChanges":[0, 4.0, 100],
"dlogo": "APSC.png"
},
"Science":
{
"answer":"Science",
"followUp":"",
"statChanges":[50, 3.0, 100],
"dlogo": "SCIE.png"
},
"Forestry":
{
"answer":"Forestry",
"followUp":"",
"statChanges":[100, 2.0, 100],
"dlogo": "FORE.png"
},
"Commerce":
{
"answer":"Commerce",
"followUp":"",
"statChanges":[100, 2.0, 100],
"dlogo": "COMM.png"
},
"Kinesiology":
{
"answer":"Kinesiology",
"followUp":"",
"statChanges":[100, 2.0, 100],
"dlogo": "KIN.png"
},
"LFS":
{
"answer":"Land and Food Systems",
"followUp":"",
"statChanges":[100, 2.0, 100],
"dlogo": "LFS.png"
},
"TotemPark": {
"answer": "Totem Park",
"followUp": "",
"statChanges": [0, 0, 0]
},
"PlaceVanier": {
"answer": "Place Vanier",
"followUp": "",
"statChanges": [0, 0, 0]
},
"OrchardCommons": {
"answer": "Orchard Commons",
"followUp": "",
"statChanges": [0, 0, 0]
}
}
2 changes: 1 addition & 1 deletion src/components/choices/ChoiceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function ChoiceButton(props: IProps) {
className="choice-btn-70 is-primary nes-btn"
onClick={() => props.makeChoice(props.choice)}
>
{props.choice.answer()}
{props.choice.answer}
</button>
);
}
23 changes: 13 additions & 10 deletions src/components/choices/Choices.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import React from "react";

import ChoiceButton from "./ChoiceButton";
import {IChoice} from "./../../events/core";
import { IChoice } from "./../../events/core";
import ChoicesManager from "./../../events/ChoicesManager";

interface IProps {
choices: IChoice[];
choices: string[];
mgr: ChoicesManager;
makeChoice(choice: IChoice): void;
}

export default function Choices(props: IProps) {
const choiceButtons = props.choices.map(choice =>
(
<ChoiceButton
key={choice.answer()}
choice={choice}
makeChoice={props.makeChoice}
/>
)
const choiceButtons = props.choices && props.choices.map((choice: string) => {
const c = props.mgr.get(choice);
return (
<ChoiceButton
key={c.answer}
choice={c}
makeChoice={props.makeChoice}
/>
);
});

return (
<div className="Choices">
Expand Down
11 changes: 5 additions & 6 deletions src/components/gamePlayConsole/GamePlayConsole.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from "react";

import placeholderImg from "../../assets/place-holder-image.png";
import { GamePlayMode } from "../../events/core";
import placeholderImg from "./../../assets/place-holder-image.png";
import { GamePlayMode } from "./../../events/core";

interface IProps {
mode: GamePlayMode;
mode: string;
imgPath: string;
}

Expand All @@ -24,7 +23,7 @@ const generateAcceptanceLetter = () => {
const generateComic = (img: string) => {
return (
<img
src={img === "" ? placeholderImg : img}
src={img === "" ? placeholderImg : require(`../../assets/${img}`)}
alt="Gameplay comic"
className="event-illustration"
/>
Expand All @@ -37,4 +36,4 @@ export default function GamePlayConsole(props: IProps) {
{props.mode === GamePlayMode.AcceptanceLetter ? generateAcceptanceLetter() : generateComic(props.imgPath)}
</section >
);
}
}
Loading

0 comments on commit eae5b60

Please sign in to comment.