Skip to content

Commit

Permalink
Move some files around
Browse files Browse the repository at this point in the history
- ComponentTable, EntitySet, EntityStateContainer move closer to EntityManager
- Hitbox is a component
- Mouse and Keyboard become input
- Test files into subdirectories
- Remove unused localstorage
  • Loading branch information
Dominic Dagradi committed Dec 21, 2020
1 parent 1830fcc commit 7da11f5
Show file tree
Hide file tree
Showing 28 changed files with 39 additions and 51 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "parcel src/index.html",
"build": "parcel build src/index.html --public-url ./",
"buildServer": "npx ts-node --transpile-only src/build/buildServer.ts",
"buildServer": "npx ts-node --transpile-only src/cli/build/buildServer.ts",
"dev": "npx ts-node --transpile-only src/cli/build/dev.ts",
"devServer": "node out/server/server.js",
"typecheck": "tsc -p . --noEmit",
Expand Down Expand Up @@ -69,4 +69,4 @@
"ts-jest": "^26.1.0",
"typescript": "^3.8.3"
}
}
}
4 changes: 2 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
import { EntityId } from '~/entities/EntityId'
import { EntityManager } from '~/entities/EntityManager'
import { GameState, gameProgression, initMap } from '~/Game'
import { IKeyboard } from '~/Keyboard'
import { IKeyboard } from '~/input/Keyboard'
import { Mouse } from '~/input/Mouse'
import { Map } from '~/map/interfaces'
import { getModel, loadGrid } from '~/models'
import { Mouse } from '~/Mouse'
import { ClientMessage, ClientMessageType } from '~/network/ClientMessage'
import { IServerConnection } from '~/network/ServerConnection'
import { ServerMessage, ServerMessageType } from '~/network/ServerMessage'
Expand Down
4 changes: 2 additions & 2 deletions src/clientMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { vec2 } from 'gl-matrix'

import { Client } from '~/Client'
import * as clientHotReload from '~/clientHotReload'
import { Keyboard } from '~/Keyboard'
import { Mouse } from '~/Mouse'
import { Keyboard } from '~/input/Keyboard'
import { Mouse } from '~/input/Mouse'
import { createServerConnectionWs } from '~/network/ServerConnection'

declare global {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Damageable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { vec2 } from 'gl-matrix'

import * as hitbox from '~/components/Hitbox'
import { Transform } from '~/components/Transform'
import * as hitbox from '~/Hitbox'
import { Immutable } from '~/types/immutable'

export type Damageable = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Damager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { vec2 } from 'gl-matrix'

import { Hitbox } from '~/components/Hitbox'
import * as hitbox from '~/components/Hitbox'
import { Transform } from '~/components/Transform'
import { EntityId } from '~/entities/EntityId'
import { Hitbox } from '~/Hitbox'
import * as hitbox from '~/Hitbox'
import { Immutable } from '~/types/immutable'

export type Damager = {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ComponentTable.ts → src/entities/ComponentTable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EntityId } from '~/entities/EntityId'
import { EntityStateContainer } from '~/EntityStateContainer'
import { EntityStateContainer } from '~/entities/EntityStateContainer'
import { Immutable } from '~/types/immutable'
import { SortedMap } from '~/util/SortedMap'

Expand Down
2 changes: 1 addition & 1 deletion src/entities/EntityComponents.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Bullet } from '~/components/Bullet'
import { Damageable } from '~/components/Damageable'
import { Damager } from '~/components/Damager'
import { Hitbox } from '~/components/Hitbox'
import { Team } from '~/components/team'
import { Transform } from '~/components/Transform'
import { Type } from '~/entities/types'
import { Hitbox } from '~/Hitbox'
import { BuilderComponent, BuilderCreator } from '~/systems/builder'
import { PickupType } from '~/systems/pickups'
import { ShooterComponent } from '~/systems/shooter'
Expand Down
8 changes: 4 additions & 4 deletions src/entities/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import * as damageable from '~/components/Damageable'
import { Damageable } from '~/components/Damageable'
import * as damager from '~/components/Damager'
import { Damager } from '~/components/Damager'
import { Hitbox, clone as hitboxClone } from '~/components/Hitbox'
import { Team } from '~/components/team'
import * as transform from '~/components/Transform'
import { Transform } from '~/components/Transform'
import { ComponentTable } from '~/ComponentTable'
import { ComponentTable } from '~/entities/ComponentTable'
import { EntityComponents } from '~/entities/EntityComponents'
import { EntityId } from '~/entities/EntityId'
import { EntitySet } from '~/entities/EntitySet'
import { EntityStateContainer } from '~/entities/EntityStateContainer'
import { Type } from '~/entities/types'
import { EntitySet } from '~/EntitySet'
import { EntityStateContainer } from '~/EntityStateContainer'
import { Hitbox, clone as hitboxClone } from '~/Hitbox'
import { PickupType } from '~/systems/pickups'
import { ShooterComponent, clone as shooterClone } from '~/systems/shooter'
import { TurretComponent } from '~/systems/turret'
Expand Down
2 changes: 1 addition & 1 deletion src/EntitySet.ts → src/entities/EntitySet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EntityId } from '~/entities/EntityId'
import { EntityStateContainer } from '~/EntityStateContainer'
import { EntityStateContainer } from '~/entities/EntityStateContainer'
import { SortedSet } from '~/util/SortedSet'

export class EntitySet implements EntityStateContainer {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentTable } from '~/ComponentTable'
import { ComponentTable } from '~/entities/ComponentTable'
import { EntityId } from '~/entities/EntityId'

type TestEntry = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EntitySet } from './EntitySet'

import { EntityId } from '~/entities/EntityId'
import { EntitySet } from '~/entities/EntitySet'

describe('EntitySet', () => {
it('#has', () => {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions src/interfaces.ts → src/input/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export enum DirectionCollision {
North = 'N',
South = 'S',
East = 'E',
West = 'W',
}

export enum DirectionMove {
N = 0,
NE = -Math.PI / 4,
Expand Down
2 changes: 1 addition & 1 deletion src/network/ClientMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vec2 } from 'gl-matrix'

import { DirectionMove } from '~/interfaces'
import { DirectionMove } from '~/input/interfaces'

export enum ClientMessageType {
// Informs the server about the end of a client frame. Sent every frame from
Expand Down
9 changes: 0 additions & 9 deletions src/storage.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/systems/client/playerInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from '~/Client'
import { DirectionMove } from '~/interfaces'
import { MouseButton } from '~/Mouse'
import { DirectionMove } from '~/input/interfaces'
import { MouseButton } from '~/input/Mouse'
import { ClientMessageType } from '~/network/ClientMessage'

export const keyMap = {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/hiding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { aabb as hitboxAabb } from '~/components/Hitbox'
import { EntityManager } from '~/entities/EntityManager'
import { aabb as hitboxAabb } from '~/Hitbox'
import { aabbOverlapArea } from '~/util/math'

const REQUIRED_OVERLAP = 0.5
Expand Down
8 changes: 7 additions & 1 deletion src/systems/wallCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import { vec2 } from 'gl-matrix'

import { Transform } from '~/components/Transform'
import { TILE_SIZE } from '~/constants'
import { DirectionCollision } from '~/interfaces'
import { SimState } from '~/simulate'
import { Immutable } from '~/types/immutable'
import { aabbOverlap } from '~/util/math'
import { tileBox, tileCoords } from '~/util/tileMath'

enum DirectionCollision {
North = 'N',
South = 'S',
East = 'E',
West = 'W',
}

export const update = (simState: Pick<SimState, 'entityManager'>): void => {
for (const [id] of simState.entityManager.playerNumbers) {
const transform = simState.entityManager.transforms.get(id)!
Expand Down
10 changes: 5 additions & 5 deletions src/tools/map/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import * as _ from 'lodash'
import { Camera } from '~/Camera'
import { TILE_SIZE } from '~/constants'
import * as entities from '~/entities'
import { Keyboard } from '~/Keyboard'
import { Keyboard } from '~/input/Keyboard'
import { Mouse, MouseButton } from '~/input/Mouse'
import { Map } from '~/map/interfaces'
import { Mouse, MouseButton } from '~/Mouse'
import { Canvas2DRenderer } from '~/renderer/Canvas2DRenderer'
import { Primitive2d } from '~/renderer/interfaces'
import * as terrain from '~/terrain'
Expand Down Expand Up @@ -160,8 +160,8 @@ export class Editor {
} else {
this.brush.terrain =
TERRAIN_TYPES[
(TERRAIN_TYPES.indexOf(this.brush.terrain) + 1) %
TERRAIN_TYPES.length
(TERRAIN_TYPES.indexOf(this.brush.terrain) + 1) %
TERRAIN_TYPES.length
]
}

Expand All @@ -184,7 +184,7 @@ export class Editor {
} else {
this.brush.entity =
ENTITY_TYPES[
(ENTITY_TYPES.indexOf(this.brush.entity) + 1) % ENTITY_TYPES.length
(ENTITY_TYPES.indexOf(this.brush.entity) + 1) % ENTITY_TYPES.length
]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shuffle } from 'lodash'

import { PriorityQueue } from './PriorityQueue'
import { PriorityQueue } from '../PriorityQueue'

const permutations = <T>(values: Array<T>): Array<Array<T>> => {
if (values.length === 0) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortedMap } from './SortedMap'
import { SortedMap } from '../SortedMap'

describe('SortedMap', () => {
it('basic adds/removes', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortedSet } from './SortedSet'
import { SortedSet } from '../SortedSet'

describe('SortedSet', () => {
it('basic adds/removes', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vec2 } from 'gl-matrix'

import { segmentSegment } from './collision'
import { segmentSegment } from '../collision'

test('perpendicular, intersecting, neither vertical', () => {
const segment1: [vec2, vec2] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { vec2 } from 'gl-matrix'

import { aabbOverlap } from '../math'

import {
ChildList,
Quadrant,
Expand All @@ -12,7 +11,7 @@ import {
nodeInsert,
nodeQuery,
quadrantOfAabb,
} from './helpers'
} from '../quadtree/helpers'

type TestItem = {
id: string
Expand Down

0 comments on commit 7da11f5

Please sign in to comment.