Skip to content

Commit

Permalink
v0.0.7 Entity is aware of scene it is in
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Nov 17, 2023
1 parent 4f698d8 commit 8180e6c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vole-engine/core",
"version": "0.0.6",
"version": "0.0.8",
"description": "Tiny 2D game engine",
"repository": "https://github.com/dinomintstudio/vole",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion src/camera.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Vector} from './vector'
import { Vector } from './vector'

export class Camera {

Expand Down
2 changes: 1 addition & 1 deletion src/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Color {
* http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
*/
class HSLColor {
constructor(public h: number, public s: number, public l: number, public a: number) {}
constructor(public h: number, public s: number, public l: number, public a: number) { }

public static hue2rgb(p: number, q: number, t: number): number {
if (t < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/component/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Entity} from '../entity'
import { Entity } from '../entity'

export abstract class Component {

Expand Down
4 changes: 2 additions & 2 deletions src/component/id.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component} from './component'
import {Entity} from '../entity'
import { Component } from './component'
import { Entity } from '../entity'

export class IdComponent extends Component {

Expand Down
6 changes: 3 additions & 3 deletions src/component/transform.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Vector} from '../vector'
import {Component} from './component'
import {Entity} from '../entity'
import { Vector } from '../vector'
import { Component } from './component'
import { Entity } from '../entity'

export class TransformComponent extends Component {

Expand Down
4 changes: 2 additions & 2 deletions src/engine.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {beforeAll, describe, expect, it, jest} from '@jest/globals'
import {Engine} from './engine'
import { beforeAll, describe, expect, it, jest } from '@jest/globals'
import { Engine } from './engine'

describe('engine test', () => {

Expand Down
10 changes: 5 additions & 5 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {isBrowser} from './util/runtime'
import {Scene} from './scene'
import {Subject} from 'rxjs'
import { isBrowser } from './util/runtime'
import { Scene } from './scene'
import { Subject } from 'rxjs'

export interface FrameInfo {
id: number
Expand Down Expand Up @@ -28,8 +28,8 @@ export class Engine {
delta = 1000 / this.fps

isRunning: boolean = false
frameInfo: FrameInfo = {id: 0, lastFrameMillis: 0, lastFrameDelta: 0, frameRequestMillis: 0}
performanceInfo: PerformanceInfo = {updateDelta: 0, frameDelta: 0, idleDelta: 0, fps: 0, fpsPotential: 0}
frameInfo: FrameInfo = { id: 0, lastFrameMillis: 0, lastFrameDelta: 0, frameRequestMillis: 0 }
performanceInfo: PerformanceInfo = { updateDelta: 0, frameDelta: 0, idleDelta: 0, fps: 0, fpsPotential: 0 }
eventDispatcher: EngineEventDispatcher = {
beforeUpdate: new Subject<number>(),
afterUpdate: new Subject<number>(),
Expand Down
9 changes: 4 additions & 5 deletions src/entity.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {Component} from './component/component'
import {Engine} from './engine'
import { Component } from './component/component'
import { Engine } from './engine'
import { Scene } from './scene'

export type ConstructorType<T> = new (...args: any) => T

export class Entity {

scene?: Scene
components: Map<ConstructorType<any>, Component> = new Map<ConstructorType<any>, Component>()

constructor() {
}

initialized = false

init(engine: Engine): void {
Expand Down
9 changes: 5 additions & 4 deletions src/scene.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Engine} from './engine'
import {Camera} from './camera'
import {Entity} from './entity'
import {IdComponent} from './component'
import { Engine } from './engine'
import { Camera } from './camera'
import { Entity } from './entity'
import { IdComponent } from './component'

export class Scene {

Expand All @@ -24,6 +24,7 @@ export class Scene {
if (entity.get(IdComponent)) return

entity.add(new IdComponent(entity, ++this.engine!.uid))
entity.scene = this
this.entities.push(entity)
}

Expand Down
4 changes: 2 additions & 2 deletions src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/**
* A 2D vector on a plane
*/
import {Cloneable} from './cloneable'
import {clamp} from './util/clamp'
import { Cloneable } from './cloneable'
import { clamp } from './util/clamp'

export class Vector implements Cloneable<Vector> {
/**
Expand Down

0 comments on commit 8180e6c

Please sign in to comment.