Start refactoring
This commit is contained in:
parent
6fc53ee51e
commit
9b47d56d8f
39 changed files with 423 additions and 234 deletions
|
|
@ -18,11 +18,8 @@ A good-looking 2D adventure.
|
|||
- rancher os
|
||||
- Frontend nginx disable logging
|
||||
- procedural piano
|
||||
- obfuscate function names
|
||||
- lightweight object storage
|
||||
- dockerswarm.rocks
|
||||
- local dev env
|
||||
- CI pipeline:
|
||||
- prettier script
|
||||
- tests?
|
||||
- monitoring: https://dockerswarm.rocks/swarmpit/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
<title>{title}</title>
|
||||
<meta name="theme-color" content="#b7455e" />
|
||||
<meta name="viewport" content="initial-scale=1.0" />
|
||||
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
|
|
@ -21,7 +20,7 @@
|
|||
}
|
||||
|
||||
h1 {
|
||||
font-family: 'Roboto', 'Helvetica Neue', sans-serif;
|
||||
font-family: "Roboto", "Helvetica Neue", sans-serif;
|
||||
font-weight: 100;
|
||||
font-size: 3rem;
|
||||
color: white;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { IRenderer } from '../../drawing/i-renderer';
|
||||
import { Command } from '../command';
|
||||
import { IRenderer } from '../../drawing/rendering/i-renderer';
|
||||
|
||||
export class BeforeRenderCommand extends Command {
|
||||
public constructor(public readonly renderer?: IRenderer) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'BeforeRenderCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ export class CursorMoveCommand extends Command {
|
|||
public constructor(public readonly position?: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'CursorMoveCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { IRenderer } from '../../drawing/i-renderer';
|
||||
import { Command } from '../command';
|
||||
import { IRenderer } from '../../drawing/rendering/i-renderer';
|
||||
|
||||
export class RenderCommand extends Command {
|
||||
public constructor(public readonly renderer?: IRenderer) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'RenderCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ export class KeyDownCommand extends Command {
|
|||
public constructor(public readonly key?: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'KeyDownCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ export class KeyUpCommand extends Command {
|
|||
public constructor(public readonly key?: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'KeyUpCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ export class MoveToCommand extends Command {
|
|||
public constructor(public readonly position?: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'MoveToCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ export class PrimaryActionCommand extends Command {
|
|||
public constructor(public readonly position?: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'PrimaryActionCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ export class SecondaryActionCommand extends Command {
|
|||
public constructor(public readonly position?: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'SecondaryActionCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ export class StepCommand extends Command {
|
|||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'StepCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ export class SwipeCommand extends Command {
|
|||
public constructor(public readonly delta?: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'SwipeCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ export class ZoomCommand extends Command {
|
|||
public constructor(public readonly factor?: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return 'ZoomCommand';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Circle } from './primitives/circle';
|
||||
import { IPrimitive } from './primitives/i-primitive';
|
||||
|
||||
export interface IRenderer {
|
||||
startFrame(deltaTime: DOMHighResTimeStamp): void;
|
||||
finishFrame(): void;
|
||||
|
||||
drawPrimitive(primitive: IPrimitive): void;
|
||||
|
||||
setCameraPosition(position: vec2): void;
|
||||
setCursorPosition(position: vec2): void;
|
||||
setInViewArea(size: number): vec2;
|
||||
|
||||
giveUniforms(uniforms: any): void;
|
||||
appendToUniformList(listName: string, ...values: Array<any>): void;
|
||||
|
||||
screenUvToWorldCoordinate(mousePosition: vec2): vec2;
|
||||
drawInfoText(text: string): void;
|
||||
isOnScreen(boundingCircle: Circle): boolean;
|
||||
isPositionOnScreen(position: vec2): boolean;
|
||||
}
|
||||
35
frontend/src/scripts/drawing/lights/circle-light.ts
Normal file
35
frontend/src/scripts/drawing/lights/circle-light.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { ILight } from './i-light';
|
||||
import { vec2, vec3 } from 'gl-matrix';
|
||||
|
||||
export class CircleLight implements ILight {
|
||||
public static uniformName = 'lights';
|
||||
|
||||
constructor(
|
||||
public center: vec2,
|
||||
public radius: number,
|
||||
public color: vec3,
|
||||
public lightness: number
|
||||
) {}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
const listName = CircleLight.uniformName;
|
||||
|
||||
if (!uniforms.hasOwnProperty(listName)) {
|
||||
uniforms[listName] = [];
|
||||
}
|
||||
|
||||
uniforms[listName].push({
|
||||
center: this.center,
|
||||
radius: this.radius,
|
||||
value: this.value,
|
||||
});
|
||||
}
|
||||
|
||||
get value(): vec3 {
|
||||
return vec3.scale(
|
||||
vec3.create(),
|
||||
vec3.normalize(this.color, this.color),
|
||||
this.lightness
|
||||
);
|
||||
}
|
||||
}
|
||||
3
frontend/src/scripts/drawing/lights/i-light.ts
Normal file
3
frontend/src/scripts/drawing/lights/i-light.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export interface ILight {
|
||||
serializeToUniforms(uniforms: any): void;
|
||||
}
|
||||
30
frontend/src/scripts/drawing/lights/point-light.ts
Normal file
30
frontend/src/scripts/drawing/lights/point-light.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { ILight } from './i-light';
|
||||
import { vec2, vec3 } from 'gl-matrix';
|
||||
|
||||
export class PointLight implements ILight {
|
||||
public static uniformName = 'lights';
|
||||
|
||||
constructor(
|
||||
public center: vec2,
|
||||
public color: vec3,
|
||||
public lightness: number
|
||||
) {}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
const listName = PointLight.uniformName;
|
||||
|
||||
if (!uniforms.hasOwnProperty(listName)) {
|
||||
uniforms[listName] = [];
|
||||
}
|
||||
|
||||
uniforms[listName].push({
|
||||
center: this.center,
|
||||
radius: 0,
|
||||
value: this.value,
|
||||
});
|
||||
}
|
||||
|
||||
get value(): vec3 {
|
||||
return vec3.scale(vec3.create(), this.color, this.lightness);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,11 @@ import { vec2 } from 'gl-matrix';
|
|||
import { IPrimitive } from './i-primitive';
|
||||
|
||||
export class Circle implements IPrimitive {
|
||||
public constructor(public center: vec2, public radius: number) {}
|
||||
public constructor(public center = vec2.create(), public radius = 0) {}
|
||||
|
||||
public serializeToUniforms(uniforms: any): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return vec2.distance(this.center, target) - this.radius;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
|
||||
export interface IPrimitive {
|
||||
serializeToUniforms(uniforms: any): void;
|
||||
distance(target: vec2): number;
|
||||
minimumDistance(target: vec2): number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import { Circle } from './circle';
|
|||
import { IPrimitive } from './i-primitive';
|
||||
|
||||
export class TunnelShape implements IPrimitive {
|
||||
public static uniformNameLines = 'lines';
|
||||
public static uniformNameRadii = 'radii';
|
||||
|
||||
public readonly toFromDelta: vec2;
|
||||
private toFromDeltaLength: number;
|
||||
|
||||
|
|
@ -25,6 +28,21 @@ export class TunnelShape implements IPrimitive {
|
|||
);
|
||||
}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
if (!uniforms.hasOwnProperty(TunnelShape.uniformNameLines)) {
|
||||
uniforms[TunnelShape.uniformNameLines] = [];
|
||||
}
|
||||
|
||||
if (!uniforms.hasOwnProperty(TunnelShape.uniformNameRadii)) {
|
||||
uniforms[TunnelShape.uniformNameRadii] = [];
|
||||
}
|
||||
|
||||
uniforms[TunnelShape.uniformNameLines].push(this.from);
|
||||
uniforms[TunnelShape.uniformNameLines].push(this.toFromDelta);
|
||||
uniforms[TunnelShape.uniformNameRadii].push(this.fromRadius);
|
||||
uniforms[TunnelShape.uniformNameRadii].push(this.toRadius);
|
||||
}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
const targetFromDelta = vec2.subtract(vec2.create(), target, this.from);
|
||||
const h = clamp01(
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue