Skip to content

Commit

Permalink
skeleton of sheet state flow
Browse files Browse the repository at this point in the history
  • Loading branch information
William Nadeau committed Apr 18, 2018
1 parent bc88bd7 commit a978a45
Show file tree
Hide file tree
Showing 21 changed files with 384 additions and 317 deletions.
48 changes: 45 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"private": true,
"dependencies": {
"mathjs": "^4.1.1",
"react": "^16.3.1",
"react": "^16.3.2",
"react-dom": "^16.3.1",
"react-scripts-ts": "2.14.0"
"react-redux": "^5.0.7",
"react-scripts-ts": "2.14.0",
"redux": "^4.0.0",
"typesafe-actions": "^1.1.2"
},
"scripts": {
"start": "react-scripts-ts start",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Sheets</title>
</head>
<body>
<noscript>
Expand Down
63 changes: 2 additions & 61 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import './App.css';
import Sheet from './sheet/Sheet';
import * as S from './sheet/SheetModel';
import * as S from './sheet/sheetModel';
import './extensions/Act';

const logo = require('./logo.svg');
Expand All @@ -17,70 +16,12 @@ interface AppProps {
class App extends React.Component<AppProps, AppState> {

state = this.initialState();

initialState(): AppState {

let initial: S.Sheet = {
name: 'Roland of Gilead',
statistics: [
{ name: 'fighter level', modifiers: [{ formula: '5' }] },
{ name: 'wizard level', modifiers: [{ formula: '3' }] },
{ name: 'favored class bonus', modifiers: [{ formula: '[fighter level]' }] },
{ name: 'total level', modifiers: [{ formula: '[fighter level] + [wizard level]' }] },
{
name: 'base attack bonus', modifiers: [
{ formula: '[fighter level]' },
{ formula: '[wizard level] / 2' }
]
},
{
name: 'hit point maximum',
modifiers: [
{ formula: '[constitution modifier] * [total level]' },
{ formula: '([fighter level] - 1) * 5.5 + 10' },
{ formula: '[wizard level] * 3.5' },
{ formula: '[favored class bonus]' },
],
resource: {
name: 'hit points',
current: 63,
recharge: [{ name: 'rest', amount: ['[hit point maximum]'] }]
}
},
{ name: 'constitution', modifiers: [{ formula: '14' }] },
{ name: 'constitution modifier', modifiers: [{ formula: '([constitution] - 10) / 2' }] },
],
inventory: [
{
name: 'Big Irons with the Sandalwood Grips',
stock: 2,
description: 'The Sandalwood Guns are the guns of a true gunslinger.'
},
{
name: 'Horn of Eld', stock: 1, description: 'The Horn of Eld is the personal horn of Arthur Eld.'
},
{ name: 'Old Cowboy\'s Boots', stock: 2 },
{ name: 'Traveler\'s Clothes', stock: 1 },
{ name: 'Gunna', stock: 1, description: 'In his bag he always seems to have what he needs.' },
{ name: 'Grow Bag', stock: 1, description: 'A magical bag that has the ability to generate coins.' },
],
abilities: [
{
name: 'Weapon Training (firearms)',
source: 'fighter 5',
description: 'https://www.d20pfsrd.com/classes/core-classes/fighter/#TOC-Weapon-Training'
}
]
};

let restored: S.Sheet = JSON.parse(JSON.stringify(initial));

return {
sheets: [

restored,

{ name: 'Steven Deschain', statistics: [], inventory: [], abilities: [] },
,

]
};
Expand Down
21 changes: 21 additions & 0 deletions src/core/Cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default class Cache<T> {
private internalCache: {[key: string]: T} = {};

public getFromCache(key: string, valueCreator: (key: string) => T) : T {
const cachedValue = this.internalCache[key];

if (cachedValue) {
return cachedValue;
}

var calculated = valueCreator(key);

this.internalCache[key] = calculated;

return calculated;
}

public clear() {
this.internalCache = {};
}
}
9 changes: 9 additions & 0 deletions src/core/RootAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as SheetActions from '../sheet/sheetActions';

type RootAction =
SheetActions.CreateSheetAction |
SheetActions.DeleteSheetAction |
SheetActions.UpdateSheetAction |
SheetActions.LoadSheetsAction;

export default RootAction;
7 changes: 7 additions & 0 deletions src/core/RootState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SheetState from '../sheet/SheetState';

type RootState = {
sheetState: SheetState
};

export default RootState;
9 changes: 9 additions & 0 deletions src/core/initialState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import RootState from '../core/RootState';

const initialState: RootState = {
sheetState: {
sheets: []
}
};

export default initialState;
11 changes: 11 additions & 0 deletions src/core/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { combineReducers } from 'redux';
import RootState from './RootState';
import RootAction from './RootAction';
import sheetReducer from '../sheet/sheetReducer';

const rootReducer = combineReducers<RootState, RootAction>(
{
sheetState: sheetReducer
});

export default rootReducer;
37 changes: 0 additions & 37 deletions src/sheet/AbilitiesSection.tsx

This file was deleted.

36 changes: 0 additions & 36 deletions src/sheet/InventorySection.tsx

This file was deleted.

43 changes: 0 additions & 43 deletions src/sheet/ResourcesSection.tsx

This file was deleted.

Loading

0 comments on commit a978a45

Please sign in to comment.