Skip to content

Commit

Permalink
Slight cleanup refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Feb 6, 2024
1 parent 7e7a657 commit 56327c6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/ui/drawPanicBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function wordBubblePanicRect(textCenter: Point, lineHeight: number, lines
return { rect: { p: minp, sz: vsub(maxp, minp) }, color: lerpSpline(panicColorSpline, progress) as RgbColor };
}


export function renderPanicBar(panic: PanicData, game_from_clock: SE1): RenderableRect {
const panic_fraction = getPanicFraction(panic, game_from_clock);

Expand Down
4 changes: 2 additions & 2 deletions src/ui/gl-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { FIXED_WORD_BUBBLE_SIZE, canvas_from_hand_tile } from "./render";
import { spriteLocOfMob } from "./sprite-sheet";
import { resizeView } from "./ui-helpers";
import { CanvasGlInfo } from "./use-canvas";
import { BUBBLE_FONT_SIZE, canvas_from_drag_tile, cell_in_canvas, drawBubbleAux, pan_canvas_from_world_of_state } from "./view-helpers";
import { BUBBLE_FONT_SIZE, canvas_from_drag_tile, cell_in_canvas, drawBubbleAux, pan_canvas_from_world_of_state, textCenterOfBubble } from "./view-helpers";
import { canvas_bds_in_canvas, getWidgetPoint, hand_bds_in_canvas, panic_bds_in_canvas } from "./widget-helpers";

const shadowColorRgba: RgbaColor = [128, 128, 100, Math.floor(0.4 * 255)];
Expand Down Expand Up @@ -248,7 +248,7 @@ export function renderGlPane(ci: CanvasGlInfo, env: GlEnv, state: GameState): vo
// draw word bubble progress bars
for (const wordBonus of cs.wordBonusState.active) {
if (cs.wordBonusState.shown !== undefined && vequal(cs.wordBonusState.shown, wordBonus.p_in_world_int)) {
const text_in_canvas = vadd({ x: -24, y: -24 }, apply(canvas_from_world, vadd(wordBonus.p_in_world_int, { x: 0.4, y: 0 })));
const text_in_canvas = textCenterOfBubble(canvas_from_world, wordBonus.p_in_world_int);
const rr = wordBubblePanicRect(text_in_canvas, BUBBLE_FONT_SIZE, 2, FIXED_WORD_BUBBLE_SIZE, getWordBonusFraction(wordBonus, cs.game_from_clock));
glFillRect(env, rr.rect, rr.color);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { vadd, vdiv, vequal, vm, vscale, vsub, vtrans } from '../util/vutil';
import { drawAnimation } from './drawAnimation';
import { drawBonus } from './drawBonus';
import { CanvasInfo } from './use-canvas';
import { cell_in_canvas, drawBubble, drawBubbleAux, pan_canvas_from_world_of_state } from './view-helpers';
import { apexOfBubble, cell_in_canvas, drawBubble, drawBubbleAux, pan_canvas_from_world_of_state, textCenterOfBubble } from './view-helpers';
import { GLOBAL_BORDER, PANIC_THICK, canvas_bds_in_canvas, canvas_from_hand, canvas_from_toolbar, effective_toolbar_bds_in_canvas, getWidgetPoint, hand_bds_in_canvas, inner_hand_bds_in_canvas, panic_bds_in_canvas, pause_button_bds_in_canvas, score_bds_in_canvas, spacer1_bds_in_canvas, spacer2_bds_in_canvas, toolbar_bds_in_canvas, world_bds_in_canvas } from './widget-helpers';

const INTERFACE_RADIUS = 2 * GLOBAL_BORDER;
Expand Down Expand Up @@ -217,8 +217,8 @@ export function canvas_from_hand_tile(index: number): SE2 {
function drawWordBubble(ci: CanvasInfo, cs: CoreState, pan_canvas_from_world: SE2) {
for (const wordBonus of cs.wordBonusState.active) {
if (cs.wordBonusState.shown !== undefined && vequal(cs.wordBonusState.shown, wordBonus.p_in_world_int)) {
const apex_in_canvas = apply(pan_canvas_from_world, vadd(wordBonus.p_in_world_int, { x: 0.4, y: 0.4 }));
const text_in_canvas = vadd({ x: -24, y: -24 }, apply(pan_canvas_from_world, vadd(wordBonus.p_in_world_int, { x: 0.4, y: 0 })));
const apex_in_canvas = apexOfBubble(pan_canvas_from_world, wordBonus.p_in_world_int);
const text_in_canvas = textCenterOfBubble(pan_canvas_from_world, wordBonus.p_in_world_int);
drawBubbleAux(ci.d, [wordBonus.word.toUpperCase(), ''], text_in_canvas, apex_in_canvas, FIXED_WORD_BUBBLE_SIZE, 1);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/ui/view-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apply, compose, ident, inverse, SE2, translate } from '../util/se2';
import { vm, vsub } from '../util/vutil';
import { vadd, vm, vsub } from '../util/vutil';
import { CoreState, GameState, MouseState } from '../core/state';
import { Point, Rect } from '../util/types';
import { getDragWidgetPoint, getWidgetPoint } from './widget-helpers';
Expand Down Expand Up @@ -127,3 +127,11 @@ export function drawBubbleAux(
d.fillText(lines[i], textCenter.x, textCenter.y + i * BUBBLE_FONT_SIZE);
}
}

export function textCenterOfBubble(canvas_from_world: SE2, p_in_world_int: Point): Point {
return vadd({ x: -24, y: -24 }, apply(canvas_from_world, vadd(p_in_world_int, { x: 0.4, y: 0 })));
}

export function apexOfBubble(canvas_from_world: SE2, p_in_world_int: Point): Point {
return apply(canvas_from_world, vadd(p_in_world_int, { x: 0.4, y: 0.4 }));
}
2 changes: 1 addition & 1 deletion src/util/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const DEBUG = {
instructions: false,
skipAheadPanic: false,
acceleratePanic: false,
accelerateWordBonus: false,
accelerateWordBonus: true,
interval: false,
glProfiling: false,
canvasProfiling: false,
Expand Down

0 comments on commit 56327c6

Please sign in to comment.