Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dipsy/ui ux enhance #13

Merged
merged 24 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4a255cb
fix history navigation
dipsywong98 Sep 26, 2020
06a0856
TestPanel
dipsywong98 Sep 26, 2020
10c9656
Panel improve display game status
dipsywong98 Sep 26, 2020
d90a7e1
Panel display playerInfo and purchase
dipsywong98 Sep 27, 2020
2f157b1
Panel improve ImageStack display
dipsywong98 Sep 27, 2020
7ec8cbd
Panel improve ImageStack hover
dipsywong98 Sep 27, 2020
cf99aa3
Added method to deduce selected axial location.
danvim Sep 27, 2020
2537a67
Merge pull request #9 from dipsywong98/danvim/selectable-entity
dipsywong98 Sep 27, 2020
e0944f8
fix gameInitialState 2 players, ImageStack hovering cannot click, tes…
dipsywong98 Sep 27, 2020
0347cc7
Improved models
danvim Sep 27, 2020
cb4286b
Merge pull request #10 from dipsywong98/danvim/selectable-entity
dipsywong98 Sep 27, 2020
4f1259a
Merge branch 'dipsy/ui-ux-enhance' of github.com:dipsywong98/photosyn…
dipsywong98 Sep 27, 2020
b66041b
fix ImageStack jitter
dipsywong98 Sep 27, 2020
f785fb2
purchase should show the first purchasable
dipsywong98 Sep 27, 2020
ece5db8
Improved models
danvim Sep 27, 2020
ea02dde
Merge pull request #11 from dipsywong98/danvim/selectable-entity
dipsywong98 Sep 27, 2020
a30bf00
refactor Image and ImageStack
dipsywong98 Sep 27, 2020
ce46871
Improved landscape model
danvim Sep 27, 2020
b542a27
Merge pull request #12 from dipsywong98/danvim/selectable-entity
dipsywong98 Sep 28, 2020
9ad97aa
basic interaction
dipsywong98 Sep 28, 2020
d84e690
hint text
dipsywong98 Sep 28, 2020
4360d9b
Merge branch 'dipsy/ui-ux-enhance' of github.com:dipsywong98/photosyn…
dipsywong98 Sep 28, 2020
fa6eddb
implement GameWorld.setTile and fix hint text when preparing GROW_TREE
dipsywong98 Sep 28, 2020
9d87fd1
Fixed typos. Fixed tree removal and added anim. Removed some dat.gui …
danvim Sep 28, 2020
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@babel/core": "7.9.0",
"@mdi/js": "^5.5.55",
"@mdi/react": "^1.4.0",
"@popperjs/core": "^2.5.2",
"@svgr/webpack": "4.3.3",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
Expand Down Expand Up @@ -64,7 +65,9 @@
"react-app-polyfill": "^1.0.6",
"react-dev-utils": "^10.2.1",
"react-dom": "^16.13.1",
"react-hammerjs": "^1.0.1",
"react-modal": "^3.11.2",
"react-popper": "^2.2.3",
"resolve": "1.15.0",
"resolve-url-loader": "3.1.1",
"sass-loader": "8.0.2",
Expand Down Expand Up @@ -111,6 +114,7 @@
"@types/ramda": "^0.27.14",
"@types/react": "^16.9.48",
"@types/react-dom": "^16.9.0",
"@types/react-hammerjs": "^1.0.1",
"@types/react-modal": "^3.10.6",
"@types/theme-ui": "^0.3.6",
"@types/uuid": "^8.3.0",
Expand Down
Binary file modified public/models/landscape.glb
Binary file not shown.
Binary file modified public/models/ring.glb
Binary file not shown.
10 changes: 10 additions & 0 deletions src/3d/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,13 @@ export const ACTION_COST_PURCHASE: { [k in GrowthStage]: readonly number[] } = {
[GrowthStage.MID]: [3, 3, 4],
[GrowthStage.TALL]: [4, 5]
} as const

export const IMAGE_SIZE = 50
export const IMAGE_SIZE_CSS = `${IMAGE_SIZE}px`

export const GROWTH_STAGE_NAME: { [k in GrowthStage]: string } = {
[GrowthStage.SEED]: 'seed',
[GrowthStage.SHORT]: 'short tree',
[GrowthStage.MID]: 'middle tree',
[GrowthStage.TALL]: 'tall tree'
}
16 changes: 4 additions & 12 deletions src/Game/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import { isTreeGrowthStage } from './isTreeGrowthStage'

export enum GameEvent {
UPDATE_GAME_STATE,
REQUEST_GAME_STATE,
GAME_OVER,
CLICK,
GAME_INIT
CLICK
}

export enum GameActions {
CLICK,
GROW_TREE,
END_TURN,
PLANT_SEED,
Expand Down Expand Up @@ -83,14 +80,6 @@ export class Game extends Observable<typeof GameEvent, GameEventPayload> {

public stop (payload: unknown): void {
this.emit(GameEvent.GAME_OVER, { data: payload })
// this.gameWorld.dispose()
}

public async click (x: number, y: number): Promise<void> {
return await this.dispatch({
action: GameActions.CLICK,
payload: [x, y]
}).catch(this.errorHandler)
}

public async endTurn (): Promise<void> {
Expand All @@ -106,6 +95,9 @@ export class Game extends Observable<typeof GameEvent, GameEventPayload> {
if (gameState.turn === this.nPlayers) {
if (gameState.preparingRound > 0) {
gameState.preparingRound--
if (gameState.preparingRound === 0) {
gameState.rayDirection = -1
}
}
if (gameState.preparingRound === 0) {
gameState.rayDirection++
Expand Down
32 changes: 24 additions & 8 deletions src/Game/GameWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import AxialCoordsSystem from './systems/AxialCoordsSystem'
import TileSystem from './systems/TileSystem'
import SunOrientationTagComponent from './components/SunOrientationTagComponent'
import SunOrientationSystem from './systems/SunOrientationSystem'
import { createTree } from './entities/tree'
import dat from 'dat.gui'
import { Axial } from '../3d/Coordinates/Axial'
import { CYLINDER_OBJ } from '../3d/extraObjects'
Expand All @@ -36,8 +35,9 @@ import { TileInfo } from './types/TileInfo'
import TouchSystem from './systems/TouchSystem'
import { RendererComposerSystem } from './systems/RendererComposerSystem'
import RendererComposerComponent from './components/RendererComposerComponent'
import SelectableTagComponent from './components/SelectableTagComponent'
import SelectableComponent from './components/SelectableComponent'
import SelectionSystem from './systems/SelectionSystem'
import { createTree } from './entities/tree'

export default class GameWorld {
gui: dat.GUI
Expand Down Expand Up @@ -130,7 +130,7 @@ export default class GameWorld {
this.world.registerComponent(TileComponent)
this.world.registerComponent(SunOrientationTagComponent)
this.world.registerComponent(RendererComposerComponent)
this.world.registerComponent(SelectableTagComponent)
this.world.registerComponent(SelectableComponent)

this.world.unregisterSystem(WebGLRendererSystem)
this.world.registerSystem(RendererComposerSystem, { priority: 999, gameWorld: this })
Expand Down Expand Up @@ -257,7 +257,8 @@ export default class GameWorld {
.addObject3DComponent(tileContainer, boardEntity)
.addComponent(AxialCoordsComponent, { axial })
.addComponent(TileComponent)
.addComponent(SelectableTagComponent)
tileEntity
.addComponent(SelectableComponent, { refEntity: tileEntity })
this.tileEntities.set(axial.toString(), tileEntity)
})

Expand All @@ -267,7 +268,6 @@ export default class GameWorld {
const ringContainerObj = new Object3D()
ringContainerObj.name = 'ringContainer'
const ringClone = ring.clone()
ringClone.position.y -= 0.3
const mesh = ringClone.children.find((o): o is Mesh => o instanceof Mesh)
// Assuming material exists and is a MeshStandardMaterial
const originalMaterial = mesh?.material
Expand Down Expand Up @@ -315,13 +315,29 @@ export default class GameWorld {
* @param growthStage
*/
public setTile (axial: Axial, { color, growthStage }: Partial<TileInfo> = {}): void {
// TODO: implement the description
if (color !== undefined && growthStage !== undefined) {
createTree(this, { color, growthStage, axial })
const treeComponent = this.tileEntities.get(axial.toString())?.getComponent(TileComponent)?.treeEntity?.getMutableComponent(TreeComponent)
if (treeComponent !== undefined) {
if (growthStage !== undefined) {
treeComponent.growthStage = growthStage
} else {
treeComponent.reset()
danvim marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
if (color !== undefined && growthStage !== undefined) {
createTree(this, { color, growthStage, axial })
}
}
}

public setRayDirection (directionType: number): void {
this.sunOrientationRad = INITIAL_SUN_ORIENTATION + directionType * Math.PI / 3
}

public getActiveEntity (): ECSYThreeEntity | undefined {
return this.activeObject?.entity?.getComponent(SelectableComponent)?.refEntity
}

public getActiveAxial (): Axial | undefined {
return this.getActiveEntity()?.getComponent(AxialCoordsComponent)?.axial
}
}
10 changes: 10 additions & 0 deletions src/Game/components/SelectableComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, Types } from 'ecsy'
import { ECSYThreeEntity } from 'ecsy-three'

export default class SelectableComponent extends Component<SelectableComponent> {
refEntity!: ECSYThreeEntity
}

SelectableComponent.schema = {
refEntity: { type: Types.Ref }
}
3 changes: 0 additions & 3 deletions src/Game/components/SelectableTagComponent.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/Game/getInitialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getInitialState = (players: number): GameState => {
preparingRound: 2,
dirtyTiles: [],
turn: 0,
rayDirection: -1,
rayDirection: 0,
revolutionLeft: 3,
board: getInitialBoard(),
scoreTokens: {
Expand All @@ -55,7 +55,7 @@ export const getInitialState = (players: number): GameState => {
state.playerInfo[id] = getInitialPlayerInfo(id)
}
if (players === 2) {
state.scoreTokens[3] = []
state.scoreTokens[4] = []
}
return state
}
2 changes: 1 addition & 1 deletion src/Game/systems/SelectionSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GameWorldSystem from './GameWorldSystem'
import SelectableTagComponent from '../components/SelectableTagComponent'
import SelectableTagComponent from '../components/SelectableComponent'
danvim marked this conversation as resolved.
Show resolved Hide resolved
import { ECSYThreeObject3D, Object3DComponent } from 'ecsy-three'
import { Object3D, Raycaster } from 'three'

Expand Down
16 changes: 11 additions & 5 deletions src/Game/systems/TreeSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import jelly from '../easing/3d/jelly'
import TweenComponent from '../components/TweenComponent'
import TweenObjectProperties from '../types/TweenObjectProperties'
import linear from '../easing/3d/linear'
import SelectableTagComponent from '../components/SelectableTagComponent'
import SelectableComponent from '../components/SelectableComponent'

export default class TreeSystem extends GameWorldSystem {
execute (delta: number, time: number): void {
Expand Down Expand Up @@ -51,10 +51,16 @@ export default class TreeSystem extends GameWorldSystem {
return
}

const linkedTileComp = this.gameWorld.tileEntities.get(axialComp.axial.toString())?.getMutableComponent(TileComponent)
if (linkedTileComp !== undefined) {
linkedTileComp.treeEntity = entity
const linkedTileEntity = this.gameWorld.tileEntities.get(axialComp.axial.toString())
if (linkedTileEntity === undefined) {
return
}

const linkedTileComp = linkedTileEntity.getMutableComponent(TileComponent)
if (linkedTileComp === undefined) {
return
}
linkedTileComp.treeEntity = entity

const { color } = treeComp
obj3d.name = 'tree-' + entity.id.toString() + '-' + Color[color]
Expand Down Expand Up @@ -100,7 +106,7 @@ export default class TreeSystem extends GameWorldSystem {
treeComp.plant = this.world
.createEntity()
.addObject3DComponent(plantContainerObj, entity)
.addComponent(SelectableTagComponent)
.addComponent(SelectableComponent, { refEntity: linkedTileEntity })
treeComp.tree = this.world
.createEntity()
.addObject3DComponent(treeObj, treeComp.plant)
Expand Down
File renamed without changes
21 changes: 10 additions & 11 deletions public/images/leaf.svg → src/assets/images/leaf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
21 changes: 10 additions & 11 deletions public/images/sun.svg → src/assets/images/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/token1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/token2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/token3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/token4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/tree-placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 32 additions & 21 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { FunctionComponent, useState } from 'react'
import { useRoom } from '../lib/RoomContext'
import { Flex } from 'theme-ui'
import NavBar from './NavBar'
import { transition } from '../theme/transitions'
Expand All @@ -18,37 +17,49 @@ export enum AppState {
}

const App: FunctionComponent = () => {
const [state, _setState] = useState(AppState.HOME)
const room = useRoom()
const setState = (newState: AppState): void => {
if (newState !== state) {
if (newState === AppState.HOME) {
room.leaveRoom()
window.history.pushState({
pageTitle: 'Whatever Game'
}, '', process.env.PUBLIC_URL)
} else if (newState === AppState.ROOM) {
window.history.pushState({
pageTitle: (room.roomCode ?? '') + ' - Whatever Game'
}, '', `${process.env.PUBLIC_URL}/${room.roomCode ?? ''}`)
}
_setState(newState)
}
}
const [state, setState] = useState(AppState.HOME)
return (
<Box>
<NavBar setState={setState} state={state}/>
<Box sx={{ width: '100vw', height: '100vh', overflow: 'hidden', position: 'relative' }}>
<GameContextProvider>
<GameRenderer/>
<Flex sx={{ width: '100vw', bottom: 0, left: `${-(state - 2) * 100}%`, position: 'absolute', ...transition(0.3, ['left'], 'linear') }}>
<Flex
sx={{
width: '100vw',
bottom: 0,
left: `${-(state - 2) * 100}%`,
position: 'absolute',
...transition(0.3, ['left'], 'linear')
}}>
<GamePlayer setState={setState}/>
</Flex>
<Flex sx={{ width: '100vw', height: '100vh', left: `${-(state - 1) * 100}%`, justifyContent: 'center', alignItems: 'center', position: 'absolute', ...transition(0.3, ['left'], 'linear') }}>
<Flex
sx={{
width: '100vw',
height: '100vh',
left: `${-(state - 1) * 100}%`,
justifyContent: 'center',
alignItems: 'center',
position: 'absolute',
...transition(0.3, ['left'], 'linear')
}}>
<Room setState={setState}/>
</Flex>
<Flex sx={{ width: '100vw', height: '100vh', left: `${-state * 100}%`, justifyContent: 'center', alignItems: 'center', position: 'absolute', ...transition(0.3, ['left'], 'linear') }}>
<Flex
sx={{
width: '100vw',
height: '100vh',
left: `${-state * 100}%`,
justifyContent: 'center',
alignItems: 'center',
position: 'absolute',
...transition(0.3, ['left'], 'linear')
}}>
<Home setState={setState}/>
{
// <TestPanel setState={setState}/>
}
</Flex>
</GameContextProvider>
</Box>
Expand Down
Loading