Skip to content

Commit

Permalink
fix: timer component initialize before context
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed May 26, 2024
1 parent fd729ed commit c970780
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/draw/uvquad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getInternalContext, getKaboomContext } from "@/kaboom";
import { vec2 } from "@/math";
import { GameObj, Rect, UVQuadComp } from "@/types";
import { Rect, vec2 } from "@/math";
import type { GameObj, UVQuadComp } from "@/types";

export function uvquad(w: number, h: number): UVQuadComp {
const k = getKaboomContext(this);
Expand Down
3 changes: 1 addition & 2 deletions src/components/misc/lifespan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import easings from "@/easings";
import { getKaboomContext } from "@/kaboom";
import { EmptyComp, GameObj, LifespanCompOpt, OpacityComp } from "@/types";
import { wait } from "scripts/lib";

export function lifespan(time: number, opt: LifespanCompOpt = {}): EmptyComp {
const k = getKaboomContext(this);
Expand All @@ -14,7 +13,7 @@ export function lifespan(time: number, opt: LifespanCompOpt = {}): EmptyComp {
id: "lifespan",
require: ["opacity"],
async add(this: GameObj<OpacityComp>) {
await wait(time);
await k.wait(time);
this.opacity = this.opacity ?? 1;
if (fade > 0) {
await k.tween(
Expand Down
4 changes: 2 additions & 2 deletions src/components/misc/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import {
} from "@/types";

export function timer(): TimerComp {
const k = getKaboomContext(this);

return {
id: "timer",
wait(
this: GameObj<TimerComp>,
time: number,
action?: () => void,
): TimerController {
const k = getKaboomContext(this);
const actions = [];
if (action) actions.push(action);
let t = 0;
Expand Down Expand Up @@ -72,6 +71,7 @@ export function timer(): TimerComp {
setValue: (value: V) => void,
easeFunc = easings.linear,
) {
const k = getKaboomContext(this);
let curTime = 0;
const onEndEvents: Array<() => void> = [];
const ev = this.onUpdate(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/transform/move.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EmptyComp, GameObj, PosComp, Vec2 } from "@/types";
import { Vec2 } from "@/math";
import type { EmptyComp, GameObj, PosComp } from "@/types";

export function move(dir: number | Vec2, speed: number): EmptyComp {
const d = typeof dir === "number" ? Vec2.fromAngle(dir) : dir.unit();
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"noEmit": true,
"allowJs": true,
"esModuleInterop": true,
"target": "esnext",
"moduleResolution": "node",
"target": "ESNext",
"moduleResolution": "Node",
"noImplicitThis": false,
"resolveJsonModule": true,
"baseUrl": "./",
"paths": {
"@/*": [
"src/*"
"./src/*"
],
}
},
Expand Down

0 comments on commit c970780

Please sign in to comment.