Comparing version 2.0.4 to 2.1.0
@@ -1,18 +0,16 @@ | ||
define(["require", "exports", "./gine/config", "./gine/core", "./gine/canvas", "./gine/handle", "./gine/camera", "./gine/image", "./gine/keyboard", "./gine/mouse", "./gine/text", "./gine/tile"], function (require, exports, config_1, core_1, canvas_1, handle_1, camera_1, image_1, keyboard_1, mouse_1, text_1, tile_1) { | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(config_1); | ||
__export(core_1); | ||
__export(canvas_1); | ||
__export(handle_1); | ||
__export(camera_1); | ||
__export(image_1); | ||
__export(keyboard_1); | ||
__export(mouse_1); | ||
__export(text_1); | ||
__export(tile_1); | ||
}); | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./gine/config")); | ||
__export(require("./gine/core")); | ||
__export(require("./gine/canvas")); | ||
__export(require("./gine/handle")); | ||
__export(require("./gine/camera")); | ||
__export(require("./gine/image")); | ||
__export(require("./gine/keyboard")); | ||
__export(require("./gine/mouse")); | ||
__export(require("./gine/text")); | ||
__export(require("./gine/tile")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "gine", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Gine game engine.", | ||
@@ -14,24 +14,15 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"start": "npm run dev", | ||
"dev": "node build/dev-server.js", | ||
"build": "rimraf dist && tsc", | ||
"test": "karma start build/karma.conf.js --single-run" | ||
"start": "npm run build", | ||
"build": "rm -rf dist/ && tsc && echo 'Build completed, check your dist/ folder!'" | ||
}, | ||
"dependencies": { | ||
"es6-shim": "^0.35.3", | ||
"rxjs": "^5.4.3" | ||
"node-ts": "^2.1.2", | ||
"rxjs": "^6.0.0", | ||
"ts-node": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^1.10.3", | ||
"eslint-friendly-formatter": "^1.2.2", | ||
"jasmine-core": "^2.4.1", | ||
"karma": "^0.13.15", | ||
"karma-jasmine": "^0.3.6", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"karma-spec-reporter": "0.0.23", | ||
"karma-webpack": "^2.0.4", | ||
"phantomjs-prebuilt": "^2.1.3", | ||
"rimraf": "^2.5.0", | ||
"tslint": "^5.7.0", | ||
"typescript": "^2.5.3" | ||
"http-server": "^0.11.1", | ||
"tslint": "^5.11.0", | ||
"typescript": "^2.9.2" | ||
}, | ||
@@ -38,0 +29,0 @@ "author": "Bjorn 'Bjeaurn'", |
@@ -1,19 +0,23 @@ | ||
export type Config = { | ||
maxFps: number | ||
tickRate: number | ||
width: number | ||
height: number | ||
usesTiles: boolean | ||
tileSize: number | ||
canvas: HTMLCanvasElement | null | ||
export class Config { | ||
usesTiles: boolean; | ||
tileSize: number; | ||
constructor( | ||
readonly width: number, | ||
readonly height: number, | ||
readonly canvas: HTMLCanvasElement | null, | ||
readonly tickRate: number = 105, | ||
readonly maxFps: number = 60, | ||
usesTiles: boolean = true, | ||
tileSize: number = 16 | ||
) {} | ||
} | ||
export const CONFIG: Config = { | ||
maxFps: 60, | ||
tickRate: 105, | ||
width: 800, | ||
height: 600, | ||
usesTiles: true, | ||
tileSize: 16, | ||
canvas: null | ||
} | ||
maxFps: 60, | ||
tickRate: 105, | ||
width: 800, | ||
height: 600, | ||
usesTiles: true, | ||
tileSize: 16, | ||
canvas: null | ||
}; |
@@ -1,89 +0,80 @@ | ||
import { Font } from './text'; | ||
import { Handle } from './handle' | ||
import { Canvas } from './canvas' | ||
import { CONFIG, Config } from './config' | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
import 'rxjs/add/operator/map' | ||
import 'rxjs/add/observable/merge' | ||
import 'rxjs/add/observable/interval' | ||
import 'rxjs/add/operator/share' | ||
import { Font } from "./text"; | ||
import { Handle } from "./handle"; | ||
import { Canvas } from "./canvas"; | ||
import { CONFIG, Config } from "./config"; | ||
import { map, share } from "rxjs/operators"; | ||
import { Observable, Subscription, interval, merge } from "rxjs"; | ||
export class Gine { | ||
static canvas: Canvas; | ||
static handle: Handle; | ||
public fps: number = 0; | ||
private frameCount: number = 0; | ||
private delta: number = 0; | ||
private tickrate: number = 0; | ||
private tickNr: number = 0; | ||
private then: number = performance.now(); | ||
private second: number = performance.now(); | ||
readonly fpsMs: number; | ||
readonly tickMs: number; | ||
static canvas: Canvas | ||
static handle: Handle | ||
public fps: number = 0 | ||
private frameCount: number = 0 | ||
private delta: number = 0 | ||
private tickrate: number = 0 | ||
private tickNr: number = 0 | ||
private then: number = performance.now() | ||
private second: number = performance.now() | ||
readonly fpsMs: number | ||
readonly tickMs: number | ||
readonly update$: Observable<string>; | ||
private updateSubscription: Subscription; | ||
readonly clock$: Observable<number>; | ||
readonly update$: Observable<string> | ||
private updateSubscription: Subscription | ||
readonly clock$: Observable<number> | ||
constructor(readonly config: Config) { | ||
if (this.config.canvas === null) { | ||
throw new Error("No canvas given!"); | ||
} | ||
Gine.canvas = new Canvas(this.config.canvas); | ||
Gine.handle = new Handle(Gine.canvas.canvasElm); | ||
this.fpsMs = 1000 / this.config.maxFps; | ||
this.tickMs = 1000 / this.config.tickRate; | ||
constructor(readonly config: Config) { | ||
if(this.config.canvas === null) { | ||
throw new Error("No canvas given!"); | ||
} | ||
Gine.canvas = new Canvas(this.config.canvas) | ||
Gine.handle = new Handle(Gine.canvas.canvasElm) | ||
this.fpsMs = 1000 / this.config.maxFps | ||
this.tickMs = 1000 / this.config.tickRate | ||
Gine.handle.setFont(new Font("Helvetica", 16)); | ||
Gine.handle.setColor(0, 0, 0, 0.8); | ||
Gine.handle.setFont(new Font('Helvetica', 16)) | ||
Gine.handle.setColor(0,0,0,0.8) | ||
const ticks = interval(this.tickMs).pipe(map(() => "tick")); | ||
const frames = interval(this.fpsMs).pipe(map(() => "frame")); | ||
const seconds = interval(1000).pipe(map(() => "second")); | ||
const ticks = Observable.interval(this.tickMs).map(() => 'tick') | ||
const frames = Observable.interval(this.fpsMs).map(() => 'frame') | ||
const seconds = Observable.interval(1000).map(() => 'second') | ||
this.update$ = merge(ticks, frames, seconds).pipe(share()); | ||
} | ||
this.update$ = Observable.merge(ticks, frames, seconds) | ||
.share() | ||
} | ||
start() { | ||
this.updateSubscription = this.update$.subscribe(t => this.fn(t)); | ||
} | ||
start() { | ||
this.updateSubscription = this.update$.subscribe( | ||
t => this.fn(t) | ||
) | ||
} | ||
stop() { | ||
this.updateSubscription.unsubscribe(); | ||
} | ||
stop() { | ||
this.updateSubscription.unsubscribe() | ||
fn(type: string): void { | ||
if (type === "frame") this.frame(); | ||
if (type === "tick") this.tick(); | ||
if (type === "second") { | ||
this.fps = this.frameCount; | ||
this.tickrate = this.tickNr; | ||
this.frameCount = 0; | ||
this.tickNr = 0; | ||
} | ||
} | ||
fn(type: string): void { | ||
if(type === 'frame') this.frame() | ||
if(type === 'tick') this.tick() | ||
if(type === 'second') { | ||
this.fps = this.frameCount | ||
this.tickrate = this.tickNr | ||
this.frameCount = 0 | ||
this.tickNr = 0 | ||
} | ||
} | ||
frame(): void { | ||
Gine.handle.clear(); | ||
Gine.handle.setColor(0, 0, 0); | ||
Gine.handle.handle.fillRect(1, 1, CONFIG.width - 2, CONFIG.height - 2); | ||
Gine.handle.setFont(new Font("Helvetica", 10)); | ||
Gine.handle.setColor(0, 255, 0); | ||
Gine.handle.text("" + this.fps + "fps", 5, 16); | ||
Gine.handle.text("" + this.tickrate + " tickrate", 5, 40); | ||
this.frameCount++; | ||
window.requestAnimationFrame(() => {}); | ||
} | ||
frame(): void { | ||
Gine.handle.clear() | ||
Gine.handle.setColor(0,0,0) | ||
Gine.handle.handle.fillRect(1, 1, CONFIG.width-2, CONFIG.height-2) | ||
Gine.handle.setFont(new Font('Helvetica', 10)) | ||
Gine.handle.setColor(0, 255, 0) | ||
Gine.handle.text(""+this.fps+'fps', 5, 16) | ||
Gine.handle.text(""+this.tickrate+' tickrate', 5, 40) | ||
this.frameCount++ | ||
window.requestAnimationFrame( () => {} ) | ||
} | ||
tick(): void { | ||
this.tickNr++ | ||
this.delta = ( performance.now() - this.then) / 1000 | ||
this.then = performance.now() | ||
} | ||
tick(): void { | ||
this.tickNr++; | ||
this.delta = (performance.now() - this.then) / 1000; | ||
this.then = performance.now(); | ||
} | ||
} | ||
@@ -1,35 +0,39 @@ | ||
import { Observable } from "rxjs/Observable" | ||
import 'rxjs/add/operator/filter' | ||
import { Observable, fromEvent, merge } from "rxjs"; | ||
import { map, filter } from "rxjs/operators"; | ||
export type KeyEvent = { | ||
key: string | ||
type: 'keyup' | 'keydown' | ||
} | ||
key: string; | ||
type: "keyup" | "keydown"; | ||
}; | ||
export class Keyboard { | ||
readonly key$: Observable<KeyEvent>; | ||
readonly key$: Observable<KeyEvent> | ||
private pressed: boolean[] = []; | ||
private pressed: boolean[] = [] | ||
constructor(readonly canvas: HTMLCanvasElement) { | ||
// We seem to not be able to use the canvas to bind `keyup` and `keydown` directly. | ||
const keydown = fromEvent(document, "keydown").pipe( | ||
filter((ev: KeyboardEvent) => { | ||
return !this.pressed[ev.keyCode]; | ||
}), | ||
map((ev: KeyboardEvent) => { | ||
this.pressed[ev.keyCode] = true; | ||
return ev; | ||
}) | ||
); | ||
constructor(readonly canvas: HTMLCanvasElement) { | ||
// We seem to not be able to use the canvas to bind `keyup` and `keydown` directly. | ||
const keydown = Observable.fromEvent(document, 'keydown') | ||
.filter( (ev: KeyboardEvent) => { return !this.pressed[ev.keyCode] }) | ||
.map( (ev: KeyboardEvent) => { | ||
this.pressed[ev.keyCode] = true | ||
return ev | ||
}) | ||
const keyup = fromEvent(document, "keyup").pipe( | ||
map((ev: KeyboardEvent) => { | ||
this.pressed[ev.keyCode] = false; | ||
return ev; | ||
}) | ||
); | ||
const keyup = Observable.fromEvent(document, 'keyup') | ||
.map( (ev: KeyboardEvent) => { | ||
this.pressed[ev.keyCode] = false | ||
return ev | ||
}) | ||
this.key$ = Observable.merge(keyup, keydown) | ||
.map( (ev: KeyboardEvent) => { | ||
return <KeyEvent>{ key: ev.key, type: ev.type } | ||
}) | ||
} | ||
} | ||
this.key$ = merge(keyup, keydown).pipe( | ||
map((ev: KeyboardEvent) => { | ||
return <KeyEvent>{ key: ev.key, type: ev.type }; | ||
}) | ||
); | ||
} | ||
} |
@@ -1,43 +0,40 @@ | ||
import { Observable } from 'rxjs/Observable' | ||
import 'rxjs/add/observable/fromEvent' | ||
import 'rxjs/add/observable/merge' | ||
import { Observable, fromEvent, merge } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
export type MousePosition = { | ||
x: number | ||
y: number | ||
button: number | ||
type: 'mouseup' | 'mousedown' | ||
time?: number | ||
} | ||
x: number; | ||
y: number; | ||
button: number; | ||
type: 'mouseup' | 'mousedown'; | ||
time?: number; | ||
}; | ||
export class Mouse { | ||
readonly mouse$: Observable<MousePosition>; | ||
private lastPosition: MousePosition; | ||
readonly mouse$: Observable<MousePosition> | ||
private lastPosition: MousePosition | ||
constructor(readonly canvas: HTMLCanvasElement) { | ||
const mousedown = fromEvent(this.canvas, 'mousedown'); | ||
const mouseup = fromEvent(this.canvas, 'mouseup'); | ||
const mousemove = fromEvent(this.canvas, 'mousemove'); | ||
this.mouse$ = merge(mousedown, mouseup, mousemove).pipe( | ||
map((ev: MouseEvent) => { | ||
this.lastPosition = this.getMousePosition(ev); | ||
return this.lastPosition; | ||
}) | ||
); | ||
} | ||
constructor(readonly canvas: HTMLCanvasElement) { | ||
const mousedown = Observable.fromEvent(this.canvas, 'mousedown') | ||
const mouseup = Observable.fromEvent(this.canvas, 'mouseup') | ||
// mousemove ? | ||
this.mouse$ = Observable.merge(mousedown, mouseup) | ||
.map( | ||
(ev: MouseEvent) => { | ||
this.lastPosition = this.getMousePosition(ev) | ||
return this.lastPosition | ||
} | ||
) | ||
} | ||
getPosition(): MousePosition { | ||
return this.lastPosition; | ||
} | ||
getPosition(): MousePosition { | ||
return this.lastPosition | ||
} | ||
getMousePosition(ev: MouseEvent): MousePosition { | ||
return <MousePosition>{ | ||
x: Math.round((ev.clientX)), | ||
y: Math.round((ev.clientY)), | ||
button: ev.button, | ||
type: ev.type | ||
} | ||
} | ||
} | ||
getMousePosition(ev: MouseEvent): MousePosition { | ||
return <MousePosition>{ | ||
x: Math.round(ev.clientX), | ||
y: Math.round(ev.clientY), | ||
button: ev.button, | ||
type: ev.type | ||
}; | ||
} | ||
} |
@@ -11,2 +11,2 @@ export * from './gine/config' | ||
export * from './gine/text' | ||
export * from './gine/tile' | ||
export * from './gine/tile' |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "amd", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
@@ -6,0 +6,0 @@ "noImplicitAny": true, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
13061
4
16
377
1
+ Addednode-ts@^2.1.2
+ Addedts-node@^7.0.0
+ Addedarrify@1.0.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedbyline@4.2.2(transitive)
+ Addeddiff@3.5.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednode-ts@2.1.2(transitive)
+ Addedrxjs@6.6.7(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedts-node@7.0.1(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addedyn@2.0.0(transitive)
- Removedrxjs@5.5.12(transitive)
- Removedsymbol-observable@1.0.1(transitive)
Updatedrxjs@^6.0.0