Skip to content

Commit

Permalink
Add stone as a resbar resource
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Feb 17, 2024
1 parent cec3c2b commit d146ee0
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 25 deletions.
75 changes: 75 additions & 0 deletions public/assets/svg/stone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/assets/toolbar-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts/render-svgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ do
inkscape -z -w ${LARGE_SIZE} -h ${LARGE_SIZE} ${WORKDIR}/${base}.svg -e ${WORKDIR}/${base}.png
done

PNGS=$(echo "arrow hand dynamite bomb vowel consonant copy timer wood axe" | perl -ane "for (@F) {print qq(${WORKDIR}\/\$_.png )}")
PNGS=$(echo "arrow hand dynamite bomb vowel consonant copy timer wood stone" | perl -ane "for (@F) {print qq(${WORKDIR}\/\$_.png )}")
echo $PNGS
montage $PNGS -background '#ffffff00' -tile 16x1 public/assets/toolbar-large.png
2 changes: 1 addition & 1 deletion src/core/bonus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function overlapScoringOfBonus(bonus: Bonus, p_in_world_int: Point): Scor
export function resolveScoring(state: CoreState, scoring: Scoring): CoreState {
const bonus = scoring.bonus;
switch (bonus.t) {
case 'tree': return produce(state, s => { s.slowState.resource.wood++; s.slowState.resource.axe++; });
case 'tree': return produce(state, s => { s.slowState.resource.wood++; });
case 'bomb': return produce(state, s => { s.slowState.inventory.bombs++; });
case 'required': return produce(state, s => { incrementScore(s, 10); });
case 'vowel': return produce(state, s => { s.slowState.inventory.vowels += 5; });
Expand Down
3 changes: 1 addition & 2 deletions src/core/landing-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export function removeSource(state: CoreState, src: MoveSourceId): CoreState {
switch (src.t) {
case 'mobile': return putMobileNowhere(state, src.id, 'noclear');
case 'freshResource': return produce(state, cs => {
if (src.res == 'wood' || src.res == 'axe')
cs.slowState.resource[src.res]--;
cs.slowState.resource[src.res]--;
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function mkGameState(seed: number, creative: boolean, bonusLayerSeed: num
},
resource: {
wood: 0,
axe: 0,
stone: 0,
},
scoring: { score: 0, highWaterMark: 0 },
currentTool: 'pointer',
Expand Down
12 changes: 3 additions & 9 deletions src/core/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export type Tool = (typeof tools)[number];

const resbarResources = [
'wood',
'axe',
'stone',
] as const;

export type ResbarResource = (typeof resbarResources)[number];
export type WorldOnlyResource =
| 'planks'
| 'axe'
;
export type Resource = ResbarResource | WorldOnlyResource;

Expand Down Expand Up @@ -85,14 +86,7 @@ export function getCurrentResources(state: CoreState): ResbarResource[] {
if (state.slowState.winState.t == 'lost') {
return [];
}
const resources: ResbarResource[] = [];
if (state.slowState.resource.wood > 0) {
resources.push('wood');
}
if (state.slowState.resource.axe > 0) {
resources.push('axe');
}
return resources;
return resbarResources.filter(res => state.slowState.resource[res] > 0);
}

export function rectOfTool(tool: Tool): Rect {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/instructions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function exampleState(): GameState {
},
resource: {
wood: 0,
axe: 0,
stone: 0,
},
scoring: {
score: 7,
Expand Down
10 changes: 1 addition & 9 deletions src/ui/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,15 @@ function drawResbar(d: CanvasRenderingContext2D, state: CoreState) {

const ress = getCurrentResources(state);
ress.forEach((res, ix_in_resbar) => {

const ICON_SCALE = 0.7;
const S_in_canvas = resbar_bds_in_canvas.sz.x;
const rect_in_canvas = apply_to_rect(
canvas_from_resbar(),
{ p: { x: 0, y: S_in_canvas * ix_in_resbar }, sz: { x: S_in_canvas, y: S_in_canvas } },
);
const scaled_rect_in_canvas = scaleRectToCenter(rect_in_canvas, ICON_SCALE);

drawImage(d, toolbar, largeRectOf(res), scaled_rect_in_canvas);

if (res == 'wood') {
drawToolbarCount(d, rect_in_canvas, state.slowState.resource.wood);
}
if (res == 'axe') {
drawToolbarCount(d, rect_in_canvas, state.slowState.resource.axe);
}
drawToolbarCount(d, rect_in_canvas, state.slowState.resource[res]);
});

}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/sprite-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function spriteLocOfRes(res: Resource): Point {
case 'wood': return { x: 1, y: 6 };
case 'axe': return { x: 1, y: 7 };
case 'planks': return { x: 1, y: 8 };
case 'stone': return { x: 1, y: 9 };
}
}

Expand All @@ -94,7 +95,7 @@ export function largeSpriteLoc(tool: Tool | ResbarResource): Point {
case 'copy': return { y: 0, x: 6 };
case 'time': return { y: 0, x: 7 };
case 'wood': return { y: 0, x: 8 };
case 'axe': return { y: 0, x: 9 };
case 'stone': return { y: 0, x: 9 };
}
}

Expand Down

0 comments on commit d146ee0

Please sign in to comment.