Skip to content

Commit

Permalink
fix strawberry autoreveal
Browse files Browse the repository at this point in the history
  • Loading branch information
Vulae committed May 28, 2024
1 parent 5efbe80 commit 50d17b6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
6 changes: 4 additions & 2 deletions src/lib/game/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EventDispatcher } from "$lib/EventDispatcher";
import { F_WORLD } from "./Save";
import * as bt from "bintype";
import { spiralIter } from "$lib/Util";
import { StrawberryTileSecondaryMines } from "./tile/biome/Strawberry";



Expand Down Expand Up @@ -109,12 +110,13 @@ export class World extends EventDispatcher<{
}
}

// TODO: Change these to sets.
let reveal: ValidTile[] = [ ];
let stack: ValidTile[] = [ ];
// If either of strawberry nearby mine values is right.
if(tile.type == 'strawberry') {
if(tile.type == 'strawberry' && tile.secondaryNearbyMines != StrawberryTileSecondaryMines.None) {
const nearbySecondary = tile.secondaryMinesNearby(false);
if(nearbySecondary != null && nearbySecondary == tile.flagsNearby()) {
if(nearbySecondary !== null && nearbySecondary == tile.flagsNearby()) {
stack.push(tile);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/game/theme/retro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TextureAtlas } from "../../Atlas";
import type { ValidParticle } from "../particle/Particle";
import type { MultiMineTile } from "../tile/MultiMine";
import { SingleMineTileState, type SingleMineTile } from "../tile/SingleMine";
import type { StrawberryTile } from "../tile/biome/Strawberry";
import { StrawberryTileSecondaryMines, type StrawberryTile } from "../tile/biome/Strawberry";
import { TILE_NONE_NEARBY, type ValidTile } from "../tile/Tile";
import { Theme, type SoundEffect } from "./Theme";
import { SingleAntiMineTileState, type SingleAntiMineTile } from "../tile/SingleAntiMine";
Expand Down Expand Up @@ -204,15 +204,15 @@ export class ThemeRetro extends Theme {

const nearby1 = tile.minesNearby(true);
const nearby2 = tile.secondaryMinesNearby(true);
if(nearby2 == TILE_NONE_NEARBY) {
if(nearby2 == null) {
this.drawNearby(ctx, nearby1);
} else {
ctx.save();
ctx.scale(0.55, 0.55);
ctx.translate(0.1, 0.45);
this.drawNearby(ctx, tile.secondaryNearbyCountRightSide ? nearby1 : nearby2);
this.drawNearby(ctx, tile.secondaryNearbyMines == StrawberryTileSecondaryMines.Right ? nearby1 : nearby2);
ctx.translate(0.7, 0);
this.drawNearby(ctx, tile.secondaryNearbyCountRightSide ? nearby2 : nearby1);
this.drawNearby(ctx, tile.secondaryNearbyMines == StrawberryTileSecondaryMines.Right ? nearby2 : nearby1);
ctx.restore();
}
break; }
Expand Down
66 changes: 42 additions & 24 deletions src/lib/game/tile/biome/Strawberry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,72 @@ import * as bt from "bintype";



export enum StrawberryTileSecondaryMines {
None,
Left,
Right
}



export class StrawberryTile extends SingleMineTile {
public readonly type: 'strawberry' = 'strawberry';
public readonly secondaryNearbyCountModifier: number | null = null;
public readonly secondaryNearbyCountRightSide: boolean = false;

public readonly secondaryNearbyMines: StrawberryTileSecondaryMines;
public readonly secondaryNearbyMinesModifier: number;

public constructor(world: World, x: number, y: number) {
const isMine = hashNormal(world.tileSeed, x, y, 0) > 0.825;
super(world, x, y, isMine);
if(hashNormal(world.tileSeed, x, y, 1) > 0.3) {
this.secondaryNearbyCountModifier = hashNormal(world.tileSeed, x, y, 2) > 0.3 ? 1 : -1;
this.secondaryNearbyCountRightSide = hashNormal(world.tileSeed, x, y, 3) > 0.5;
}

this.secondaryNearbyMines = hashNormal(world.tileSeed, x, y, 1) > 0.3 ? (
hashNormal(world.tileSeed, x, y, 2) > 0.5 ?
StrawberryTileSecondaryMines.Left :
StrawberryTileSecondaryMines.Right
) : StrawberryTileSecondaryMines.None;
this.secondaryNearbyMinesModifier = hashNormal(world.tileSeed, x, y, 3) > 0.3 ? 1 : -1;
}

private secondaryMinesNearbyCache: number | TILE_NONE_NEARBY | null = null;
public secondaryMinesNearby(useCache: boolean): number | TILE_NONE_NEARBY {
if(this.secondaryMinesNearbyCache !== null && useCache) {
return this.secondaryMinesNearbyCache;
private secondaryNearbyMiensCacheSet: boolean = false;
private secondaryNearbyMinesCache: number | TILE_NONE_NEARBY | null = null;
public secondaryMinesNearby(useCache: boolean): number | TILE_NONE_NEARBY | null {
if(this.secondaryNearbyMiensCacheSet) {
return this.secondaryNearbyMinesCache;
}

if(this.secondaryNearbyCountModifier == null) {
this.secondaryMinesNearbyCache = TILE_NONE_NEARBY;
return TILE_NONE_NEARBY;
if(this.secondaryNearbyMines == StrawberryTileSecondaryMines.None) {
this.secondaryNearbyMiensCacheSet = true;
this.secondaryNearbyMinesCache = null;
return this.secondaryNearbyMinesCache;
}

const nearby = this.minesNearby(useCache);
if(nearby == TILE_NONE_NEARBY) {
this.secondaryMinesNearbyCache = TILE_NONE_NEARBY;
return TILE_NONE_NEARBY;
this.secondaryNearbyMiensCacheSet = true;
this.secondaryNearbyMinesCache = TILE_NONE_NEARBY;
return this.secondaryNearbyMinesCache;
}

const nearby2 = nearby + this.secondaryNearbyCountModifier;
const secondaryNearby = nearby + this.secondaryNearbyMinesModifier;

let allow0 = false;
let secondaryNearbyMinesAllowAnti: boolean = false;
for(const offset of this.searchPattern) {
const tile = getTileType(this.world, this.x + offset.x, this.y + offset.y);
if(tile.prototype instanceof SingleAntiMineTile) {
allow0 = true;
secondaryNearbyMinesAllowAnti = true;
break;
}
}
if(!allow0 && nearby2 == 0) {
this.secondaryMinesNearbyCache = TILE_NONE_NEARBY;
return TILE_NONE_NEARBY;
}

this.secondaryMinesNearbyCache = nearby2;
return this.secondaryMinesNearbyCache;
if(!secondaryNearbyMinesAllowAnti && secondaryNearby <= 0) {
this.secondaryNearbyMiensCacheSet = true;
this.secondaryNearbyMinesCache = null;
return this.secondaryNearbyMinesCache;
} else {
this.secondaryNearbyMiensCacheSet = true;
this.secondaryNearbyMinesCache = secondaryNearby;
return this.secondaryNearbyMinesCache;
}
}

public static load(world: World, x: number, y: number, io: bt.BitIO): ValidTile {
Expand Down

0 comments on commit 50d17b6

Please sign in to comment.