add formatter to project
This commit is contained in:
parent
2d597906ae
commit
1550601fa7
10 changed files with 176 additions and 167 deletions
5
Program/.prettierrc
Normal file
5
Program/.prettierrc
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false
|
||||||
|
}
|
||||||
|
|
@ -6,8 +6,7 @@ export class Vector implements IPoint{
|
||||||
y: number
|
y: number
|
||||||
|
|
||||||
constructor(x: number, y?: number) {
|
constructor(x: number, y?: number) {
|
||||||
if(y===undefined)
|
if (y === undefined) y = x
|
||||||
y = x
|
|
||||||
this.x = x
|
this.x = x
|
||||||
this.y = y
|
this.y = y
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +34,8 @@ export class Vector implements IPoint{
|
||||||
|
|
||||||
//IPoint interface functions
|
//IPoint interface functions
|
||||||
set(x?: number, y?: number): void {
|
set(x?: number, y?: number): void {
|
||||||
if (x !== undefined)
|
if (x !== undefined) this.x = x
|
||||||
this.x = x
|
if (y !== undefined) this.y = y
|
||||||
if (y !== undefined)
|
|
||||||
this.y = y
|
|
||||||
}
|
}
|
||||||
copyFrom(p: IPoint): this {
|
copyFrom(p: IPoint): this {
|
||||||
this.set(p.x, p.y)
|
this.set(p.x, p.y)
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,43 @@
|
||||||
import { Human } from "../Components/human";
|
import { Container, DisplayObject, Text } from "pixi.js"
|
||||||
import { Container, DisplayObject, Text } from "pixi.js";
|
import { AABB } from "../Datatypes/aabb"
|
||||||
import { AABB } from "../Datatypes/aabb";
|
import { System, Entity } from "ecsy"
|
||||||
import { System, Entity } from "ecsy";
|
import globals from "../globals"
|
||||||
import globals from "../globals";
|
import { Name } from "../Components/name"
|
||||||
import { Name } from "../Components/name";
|
|
||||||
|
|
||||||
// MovableSystem
|
// MovableSystem
|
||||||
export class InfoSystem extends System {
|
export class InfoSystem extends System {
|
||||||
priority = 80
|
priority = 80
|
||||||
|
|
||||||
dirty: boolean
|
|
||||||
|
|
||||||
root: Container
|
root: Container
|
||||||
elements: { [id: string]: DisplayObject } = {}
|
elements: { [id: string]: DisplayObject } = {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
globals.selected.onChange(_ => this.dirty = true)
|
|
||||||
|
|
||||||
//todo: make this more flexible for other resolutions
|
//todo: make this more flexible for other resolutions
|
||||||
let bounds = new AABB(0, 162, 162, 126)
|
let bounds = new AABB(0, 162, 162, 126)
|
||||||
|
|
||||||
this.root = globals.app.stage.addChild(new Container())
|
this.root = globals.app.stage.addChild(new Container())
|
||||||
this.root.position = bounds.min()
|
this.root.position = bounds.min()
|
||||||
this.root.width = bounds.size.x
|
|
||||||
this.root.height = bounds.size.y
|
|
||||||
|
|
||||||
let name = new Text('Name: ',{fontFamily : 'babyblocks', fontSize: 8, fill : 0xffffff});
|
let name = new Text("Name: ", {
|
||||||
name.x = 2
|
fontFamily: "babyblocks",
|
||||||
|
fontSize: 8,
|
||||||
|
fill: 0xffffff
|
||||||
|
})
|
||||||
|
name.x = 1
|
||||||
this.root.addChild(name)
|
this.root.addChild(name)
|
||||||
this.elements.name = name
|
this.elements.name = name
|
||||||
|
|
||||||
globals.selected.onChange(selected => this.select(selected))
|
globals.selected.onChange(selected => this.select(selected))
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(delta : number) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
select(entity: Entity) {
|
select(entity: Entity) {
|
||||||
(this.elements.name as Text).text = `Name: ${entity?.getComponent(Name)?.fullName() || "-"}`
|
; (this.elements.name as Text).text = `Name: ${entity
|
||||||
|
?.getComponent(Name)
|
||||||
|
?.fullName() || "-"}`
|
||||||
}
|
}
|
||||||
|
|
||||||
static queries = {
|
execute(delta: number) { }
|
||||||
UIComponent: {
|
|
||||||
components: [ Human ]
|
static queries = {}
|
||||||
},
|
queries: any
|
||||||
}
|
|
||||||
queries: any;
|
|
||||||
}
|
}
|
||||||
|
|
@ -10,12 +10,15 @@ import { Vector } from "../Datatypes/vector"
|
||||||
export class VisibleHumanSystem extends System {
|
export class VisibleHumanSystem extends System {
|
||||||
priority = 50
|
priority = 50
|
||||||
|
|
||||||
|
|
||||||
execute(delta: number) {
|
execute(delta: number) {
|
||||||
// add sprite at start
|
// add sprite at start
|
||||||
this.queries.newHumans.results.forEach((entity: Entity) => {
|
this.queries.newHumans.results.forEach((entity: Entity) => {
|
||||||
let texture = entity.getComponent(Appearance).idleTexture
|
let texture = entity.getComponent(Appearance).idleTexture
|
||||||
entity.addComponent(SpriteRenderer, <SpriteRenderer>{texture: texture, offset: new Vector(-texture.width/2, -texture.height), scale:2})
|
entity.addComponent(SpriteRenderer, <SpriteRenderer>{
|
||||||
|
texture: texture,
|
||||||
|
offset: new Vector(-texture.width / 2, -texture.height),
|
||||||
|
scale: 2
|
||||||
|
})
|
||||||
})
|
})
|
||||||
//update sprite texture
|
//update sprite texture
|
||||||
this.queries.visibleHumans.changed.forEach((entity: Entity) => {
|
this.queries.visibleHumans.changed.forEach((entity: Entity) => {
|
||||||
|
|
@ -33,7 +36,7 @@ export class VisibleHumanSystem extends System {
|
||||||
listen: {
|
listen: {
|
||||||
changed: [Appearance]
|
changed: [Appearance]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
queries: any
|
queries: any
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { System } from "ecsy"
|
import { System } from "ecsy"
|
||||||
import globals from "../../globals";
|
import globals from "../../globals"
|
||||||
|
|
||||||
// MovableSystem
|
// MovableSystem
|
||||||
export class RenderSystem extends System {
|
export class RenderSystem extends System {
|
||||||
|
|
@ -7,6 +7,6 @@ export class RenderSystem extends System {
|
||||||
|
|
||||||
// This method will get called on every frame by default
|
// This method will get called on every frame by default
|
||||||
execute(_delta: number) {
|
execute(_delta: number) {
|
||||||
globals.app.renderer.render(globals.app.stage);
|
globals.app.renderer.render(globals.app.stage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { System, Entity } from "ecsy";
|
import { System, Entity } from "ecsy"
|
||||||
import { Position } from "../../Components/position";
|
import { Position } from "../../Components/position"
|
||||||
import { SpriteRenderer } from "../../Components/rendering/spriteRenderer";
|
import { SpriteRenderer } from "../../Components/rendering/spriteRenderer"
|
||||||
import { Sprite, DisplayObject } from "pixi.js";
|
import { Sprite, DisplayObject } from "pixi.js"
|
||||||
import { PixiRepresentation } from "../../Components/rendering/pixiRepresentation";
|
import { PixiRepresentation } from "../../Components/rendering/pixiRepresentation"
|
||||||
import { addOrSetComponent } from "../../util";
|
import { addOrSetComponent } from "../../util"
|
||||||
import globals from "../../globals";
|
import globals from "../../globals"
|
||||||
import { Point } from "../../Datatypes/point";
|
import { Point } from "../../Datatypes/point"
|
||||||
|
|
||||||
// MovableSystem
|
// MovableSystem
|
||||||
export class SpriteSystem extends System {
|
export class SpriteSystem extends System {
|
||||||
|
|
@ -15,8 +15,7 @@ export class SpriteSystem extends System {
|
||||||
execute(delta: number) {
|
execute(delta: number) {
|
||||||
// Iterate through all the entities on the query
|
// Iterate through all the entities on the query
|
||||||
this.queries.sprites.added.forEach((entity: Entity) => {
|
this.queries.sprites.added.forEach((entity: Entity) => {
|
||||||
if(!(entity as any).alive)
|
if (!(entity as any).alive) return
|
||||||
return
|
|
||||||
|
|
||||||
let renderer = entity.getComponent(SpriteRenderer)
|
let renderer = entity.getComponent(SpriteRenderer)
|
||||||
let pos = entity.getComponent(Position)
|
let pos = entity.getComponent(Position)
|
||||||
|
|
@ -24,12 +23,13 @@ export class SpriteSystem extends System {
|
||||||
sprite.scale = new Point(renderer.scale)
|
sprite.scale = new Point(renderer.scale)
|
||||||
sprite.position = pos.value.add(renderer.offset.scale(renderer.scale))
|
sprite.position = pos.value.add(renderer.offset.scale(renderer.scale))
|
||||||
globals.app.stage.addChild(sprite)
|
globals.app.stage.addChild(sprite)
|
||||||
addOrSetComponent(entity, PixiRepresentation, <PixiRepresentation>{value: <DisplayObject>sprite})
|
addOrSetComponent(entity, PixiRepresentation, <PixiRepresentation>{
|
||||||
|
value: <DisplayObject>sprite
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
this.queries.sprites.changed.forEach((entity: Entity) => {
|
this.queries.sprites.changed.forEach((entity: Entity) => {
|
||||||
if(!(entity as any).alive)
|
if (!(entity as any).alive) return
|
||||||
return
|
|
||||||
let renderer = entity.getComponent(SpriteRenderer)
|
let renderer = entity.getComponent(SpriteRenderer)
|
||||||
let pos = entity.getComponent(Position)
|
let pos = entity.getComponent(Position)
|
||||||
let object = entity.getComponent(PixiRepresentation).value as Sprite
|
let object = entity.getComponent(PixiRepresentation).value as Sprite
|
||||||
|
|
@ -45,7 +45,7 @@ export class SpriteSystem extends System {
|
||||||
added: true,
|
added: true,
|
||||||
changed: true
|
changed: true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
queries: any;
|
}
|
||||||
|
queries: any
|
||||||
}
|
}
|
||||||
|
|
@ -5,14 +5,7 @@ export const canvasHeight = 288
|
||||||
|
|
||||||
export const roomBounds = new AABB(19, 34, 125, 113)
|
export const roomBounds = new AABB(19, 34, 125, 113)
|
||||||
|
|
||||||
export const FirstNames = [
|
export const FirstNames = ["Jules", "Levi", "Sarah", "Simon", "Ronja", "Marko"]
|
||||||
"Jules",
|
|
||||||
"Levi",
|
|
||||||
"Sarah",
|
|
||||||
"Simon",
|
|
||||||
"Ronja",
|
|
||||||
"Marko"
|
|
||||||
]
|
|
||||||
|
|
||||||
export const LastNames = [
|
export const LastNames = [
|
||||||
"Adams",
|
"Adams",
|
||||||
|
|
@ -40,5 +33,5 @@ export const LastNames = [
|
||||||
"White",
|
"White",
|
||||||
"Xiang",
|
"Xiang",
|
||||||
"Yakub",
|
"Yakub",
|
||||||
"Zafar",
|
"Zafar"
|
||||||
]
|
]
|
||||||
|
|
@ -1,27 +1,26 @@
|
||||||
import { Loader, Sprite } from "pixi.js";
|
import { Loader, Sprite } from "pixi.js"
|
||||||
import { Door } from "./Components/door";
|
import { Door } from "./Components/door"
|
||||||
import { DebugRect } from "./Components/rendering/debugRect";
|
import { DebugRect } from "./Components/rendering/debugRect"
|
||||||
import { roomBounds } from "./constants";
|
import { roomBounds } from "./constants"
|
||||||
import globals from "./globals";
|
import globals from "./globals"
|
||||||
import { createRandomHuman } from "./util";
|
import { createRandomHuman } from "./util"
|
||||||
import { Position } from "./Components/position";
|
import { Position } from "./Components/position"
|
||||||
import { Point } from "./Datatypes/point";
|
import { Point } from "./Datatypes/point"
|
||||||
import { World } from "ecsy";
|
import { World } from "ecsy"
|
||||||
import { TestSystem } from "./Systems/TestSystem";
|
import { TestSystem } from "./Systems/TestSystem"
|
||||||
import { AdventureReturnSystem } from "./Systems/AdventureReturnSystem";
|
import { AdventureReturnSystem } from "./Systems/AdventureReturnSystem"
|
||||||
import { DoorSystem } from "./Systems/DoorSystem";
|
import { DoorSystem } from "./Systems/DoorSystem"
|
||||||
import { RandomWalkSystem } from "./Systems/RandomWalkSystem";
|
import { RandomWalkSystem } from "./Systems/RandomWalkSystem"
|
||||||
import { PathWalkerSystem } from "./Systems/PathWalkerSystem";
|
import { PathWalkerSystem } from "./Systems/PathWalkerSystem"
|
||||||
import { VisibleHumanSystem } from "./Systems/VisibleHumanSystem";
|
import { VisibleHumanSystem } from "./Systems/VisibleHumanSystem"
|
||||||
import { SpriteSystem } from "./Systems/rendering/SpriteSystem";
|
import { SpriteSystem } from "./Systems/rendering/SpriteSystem"
|
||||||
import { ClickableSystem } from "./Systems/ClickableSystem";
|
import { ClickableSystem } from "./Systems/ClickableSystem"
|
||||||
import { InfoSystem } from "./Systems/InfoSystem";
|
import { InfoSystem } from "./Systems/InfoSystem"
|
||||||
import { DebugRenderSystem } from "./Systems/rendering/DebugRenderSystem";
|
import { DebugRenderSystem } from "./Systems/rendering/DebugRenderSystem"
|
||||||
import { ZOrderSystem } from "./Systems/rendering/ZOrderSystem";
|
import { ZOrderSystem } from "./Systems/rendering/ZOrderSystem"
|
||||||
import { PixiCleanupSystem } from "./Systems/rendering/PixiCleanupSystem";
|
import { PixiCleanupSystem } from "./Systems/rendering/PixiCleanupSystem"
|
||||||
import { RenderSystem } from "./Systems/rendering/RenderSystem";
|
import { RenderSystem } from "./Systems/rendering/RenderSystem"
|
||||||
import { Vector } from "./Datatypes/vector";
|
import { Vector } from "./Datatypes/vector"
|
||||||
|
|
||||||
|
|
||||||
export function setup() {
|
export function setup() {
|
||||||
// Create world and register the systems on it
|
// Create world and register the systems on it
|
||||||
|
|
@ -42,8 +41,7 @@ export function setup(){
|
||||||
.registerSystem(PixiCleanupSystem) //prio 99
|
.registerSystem(PixiCleanupSystem) //prio 99
|
||||||
.registerSystem(RenderSystem) //prio 100
|
.registerSystem(RenderSystem) //prio 100
|
||||||
|
|
||||||
|
let resources = Loader.shared.resources
|
||||||
let resources = Loader.shared.resources;
|
|
||||||
|
|
||||||
//base sprites without entity representation
|
//base sprites without entity representation
|
||||||
const bgTex = new Sprite(resources["Background"].texture)
|
const bgTex = new Sprite(resources["Background"].texture)
|
||||||
|
|
@ -53,18 +51,23 @@ export function setup(){
|
||||||
//start entities
|
//start entities
|
||||||
|
|
||||||
//door
|
//door
|
||||||
globals.world.createEntity()
|
globals.world
|
||||||
|
.createEntity()
|
||||||
.addComponent(Position, <Position>{ value: new Point(76, 4) })
|
.addComponent(Position, <Position>{ value: new Point(76, 4) })
|
||||||
.addComponent(Door, <Door>{open: true,
|
.addComponent(Door, <Door>{
|
||||||
openOffset: new Vector(0), openTex: resources["Door"].spritesheet.textures[0],
|
open: true,
|
||||||
closedOffset: new Vector(0), closedTex: resources["Door"].spritesheet.textures[1]})
|
openOffset: new Vector(0),
|
||||||
|
openTex: resources["Door"].spritesheet.textures[0],
|
||||||
|
closedOffset: new Vector(0),
|
||||||
|
closedTex: resources["Door"].spritesheet.textures[1]
|
||||||
|
})
|
||||||
|
|
||||||
//debug room bounds
|
//debug room bounds
|
||||||
globals.world.createEntity()
|
globals.world
|
||||||
.addComponent(DebugRect, <DebugRect>{color:0x0000FF, rect: roomBounds})
|
.createEntity()
|
||||||
|
.addComponent(DebugRect, <DebugRect>{ color: 0x0000ff, rect: roomBounds })
|
||||||
|
|
||||||
//example humans
|
//example humans
|
||||||
//TODO delete those
|
//TODO delete those
|
||||||
for(let i=0;i<10;i++)
|
for (let i = 0; i < 10; i++) createRandomHuman(globals.world)
|
||||||
createRandomHuman(globals.world)
|
|
||||||
}
|
}
|
||||||
|
|
@ -11,8 +11,11 @@ import { roomBounds, FirstNames, LastNames } from "./constants"
|
||||||
import { Clickable } from "./Components/clickable"
|
import { Clickable } from "./Components/clickable"
|
||||||
import globals from "./globals"
|
import globals from "./globals"
|
||||||
|
|
||||||
|
export function addOrSetComponent(
|
||||||
export function addOrSetComponent(entity: Entity, Component: ComponentConstructor<Component>, values: any) {
|
entity: Entity,
|
||||||
|
Component: ComponentConstructor<Component>,
|
||||||
|
values: any
|
||||||
|
) {
|
||||||
if (entity.hasComponent(Component)) {
|
if (entity.hasComponent(Component)) {
|
||||||
//component exists, copy values into it
|
//component exists, copy values into it
|
||||||
let component: any = entity.getMutableComponent(Component)
|
let component: any = entity.getMutableComponent(Component)
|
||||||
|
|
@ -35,16 +38,26 @@ export function randomArrayValue(array: any[]):any{
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRandomHuman(world: World) {
|
export function createRandomHuman(world: World) {
|
||||||
let resources = Loader.shared.resources;
|
let resources = Loader.shared.resources
|
||||||
let entity = world.createEntity()
|
let entity = world.createEntity()
|
||||||
entity
|
entity
|
||||||
.addComponent(Human)
|
.addComponent(Human)
|
||||||
.addComponent(Name, <Name>{first: randomArrayValue(FirstNames), last:randomArrayValue(LastNames)})
|
.addComponent(Name, <Name>{
|
||||||
.addComponent(Appearance, <Appearance>{idleTexture: resources["Human"].texture}) //Todo: generate appearance from body traits instead?
|
first: randomArrayValue(FirstNames),
|
||||||
|
last: randomArrayValue(LastNames)
|
||||||
|
})
|
||||||
|
.addComponent(Appearance, <Appearance>{
|
||||||
|
idleTexture: resources["Human"].texture
|
||||||
|
}) //Todo: generate appearance from body traits instead?
|
||||||
.addComponent(InCabin)
|
.addComponent(InCabin)
|
||||||
.addComponent(Position, <Position>{ value: roomBounds.randomPoint() })
|
.addComponent(Position, <Position>{ value: roomBounds.randomPoint() })
|
||||||
.addComponent(OrderZ)
|
.addComponent(OrderZ)
|
||||||
.addComponent(WalkRandomly)
|
.addComponent(WalkRandomly)
|
||||||
//todo: change this into selecing the human instead of killing it...
|
.addComponent(Clickable, {
|
||||||
.addComponent(Clickable, { actions: { "click": (event: interaction.InteractionEvent) => {globals.selected.set(entity)} }})
|
actions: {
|
||||||
|
click: (event: interaction.InteractionEvent) => {
|
||||||
|
globals.selected.set(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
html, body {
|
html,
|
||||||
|
body {
|
||||||
margin: 10;
|
margin: 10;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background-color: rgb(198, 221, 235);
|
background-color: rgb(198, 221, 235);
|
||||||
|
|
@ -11,7 +12,9 @@ canvas {
|
||||||
image-rendering: crisp-edges;
|
image-rendering: crisp-edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas, img { /* makes a change, noticeable [28/05/16] */
|
canvas,
|
||||||
|
img {
|
||||||
|
/* makes a change, noticeable [28/05/16] */
|
||||||
image-rendering: optimizeSpeed;
|
image-rendering: optimizeSpeed;
|
||||||
image-rendering: -moz-crisp-edges;
|
image-rendering: -moz-crisp-edges;
|
||||||
image-rendering: -webkit-optimize-contrast;
|
image-rendering: -webkit-optimize-contrast;
|
||||||
|
|
@ -20,19 +23,18 @@ canvas, img { /* makes a change, noticeable [28/05/16] */
|
||||||
-ms-interpolation-mode: nearest-neighbor;
|
-ms-interpolation-mode: nearest-neighbor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'pinch';
|
font-family: "pinch";
|
||||||
src: url('assets/Fonts/pinch.woff2') format('woff2'),
|
src: url("assets/Fonts/pinch.woff2") format("woff2"),
|
||||||
url('assets/Fonts/pinch.woff') format('woff');
|
url("assets/Fonts/pinch.woff") format("woff");
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'babyblocks';
|
font-family: "babyblocks";
|
||||||
src: url('assets/Fonts/BabyBlocks.woff2') format('woff2'),
|
src: url("assets/Fonts/BabyBlocks.woff2") format("woff2"),
|
||||||
url('assets/Fonts/BabyBlocks.woff') format('woff'),
|
url("assets/Fonts/BabyBlocks.woff") format("woff"),
|
||||||
url('assets/Fonts/BabyBlocks.ttf') format('ttf');
|
url("assets/Fonts/BabyBlocks.ttf") format("ttf");
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue