Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface IAction extends ReduxAction {
payload: any
}

/** Game */
/** Academy */
export const SAVE_CANVAS = 'SAVE_CANVAS'

/** Playground */
Expand Down
2 changes: 1 addition & 1 deletion src/containers/GameContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = (dispatch: Dis
)

const mapStateToProps: MapStateToProps<StateProps, {}, IState> = state => ({
canvas: state.game.canvas
canvas: state.academy.gameCanvas
})

export default connect(mapStateToProps, mapDispatchToProps)(Game)
4 changes: 2 additions & 2 deletions src/mocks/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Store } from 'redux'
import * as mockStore from 'redux-mock-store'

import {
defaultAcademy,
defaultApplication,
defaultGame,
defaultPlayground,
defaultSession,
IState
Expand All @@ -12,8 +12,8 @@ import {
export function mockInitialStore<P>(): Store<IState> {
const createStore = (mockStore as any)()
const state: IState = {
academy: defaultAcademy,
application: defaultApplication,
game: defaultGame,
playground: defaultPlayground,
session: defaultSession
}
Expand Down
6 changes: 3 additions & 3 deletions src/reducers/game.ts → src/reducers/academy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Reducer } from 'redux'

import { IAction, SAVE_CANVAS } from '../actions/actionTypes'
import { defaultGame, IGameState } from './states'
import { defaultAcademy, IAcademyState } from './states'

export const reducer: Reducer<IGameState> = (state = defaultGame, action: IAction) => {
export const reducer: Reducer<IAcademyState> = (state = defaultAcademy, action: IAction) => {
switch (action.type) {
case SAVE_CANVAS:
return {
...state,
canvas: action.payload
gameCanvas: action.payload
}
default:
return state
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { reducer as academy } from './academy'
import { reducer as application } from './application'
import { reducer as game } from './game'
import { reducer as playground } from './playground'
import { reducer as session } from './session'

export default {
academy,
application,
game,
playground,
session
}
31 changes: 17 additions & 14 deletions src/reducers/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import { SourceError } from '../slang/types'
import { HistoryHelper } from '../utils/history'

export interface IState {
readonly academy: IAcademyState
readonly application: IApplicationState
readonly game: IGameState
readonly playground: IPlaygroundState
readonly session: ISessionState
}

export interface IAcademyState {
readonly gameCanvas?: HTMLCanvasElement
}

export interface IApplicationState {
readonly title: string
readonly environment: ApplicationEnvironment
}

export const sourceChapters = [1, 2]
const latestSourceChapter = sourceChapters.slice(-1)[0]

export interface IGameState {
readonly canvas?: HTMLCanvasElement
export interface IPlaygroundState extends IWorkspaceState {
readonly queryString?: string
}

export interface IPlaygroundState {
interface IWorkspaceState {
readonly context: Context
readonly editorValue: string
readonly editorWidth: string
readonly isRunning: boolean
readonly queryString?: string
readonly output: InterpreterOutput[]
readonly replValue: string
readonly sourceChapter: number
Expand All @@ -37,11 +37,11 @@ export interface IPlaygroundState {
}

export interface ISessionState {
readonly assessmentOverviews?: IAssessmentOverview[]
readonly assessments: Map<number, IAssessment>
readonly announcements?: Announcement[]
readonly historyHelper: HistoryHelper
readonly token?: string
readonly assessments: Map<number, IAssessment>
readonly assessmentOverviews?: IAssessmentOverview[]
readonly username?: string
}

Expand Down Expand Up @@ -97,6 +97,9 @@ export enum ApplicationEnvironment {
Test = 'test'
}

export const sourceChapters = [1, 2]
const latestSourceChapter = sourceChapters.slice(-1)[0]

const currentEnvironment = (): ApplicationEnvironment => {
switch (process.env.NODE_ENV) {
case 'development':
Expand All @@ -108,15 +111,15 @@ const currentEnvironment = (): ApplicationEnvironment => {
}
}

export const defaultAcademy: IAcademyState = {
gameCanvas: undefined
}

export const defaultApplication: IApplicationState = {
title: 'Cadet',
environment: currentEnvironment()
}

export const defaultGame: IGameState = {
canvas: undefined
}

export const defaultPlayground: IPlaygroundState = {
context: createContext(latestSourceChapter),
editorValue: '',
Expand Down