mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-22 13:06:15 -04:00
Extracted pure functions to make tests happy
This commit is contained in:
parent
8d7d97608d
commit
a4e24fd397
5 changed files with 199 additions and 193 deletions
|
@ -14,8 +14,6 @@ import {
|
|||
import {
|
||||
brickCenterX,
|
||||
brickCenterY,
|
||||
clamp,
|
||||
comboKeepingRate,
|
||||
countBricksAbove,
|
||||
countBricksBelow,
|
||||
currentLevelInfo,
|
||||
|
@ -42,6 +40,7 @@ import {isOptionOn} from "./options";
|
|||
import {isPremium} from "./premium";
|
||||
import {getRunLevels} from "./newGameState";
|
||||
import {requiredAsyncAlert} from "./asyncAlert";
|
||||
import {clamp, comboKeepingRate} from "./pure_functions";
|
||||
|
||||
export function setMousePos(gameState: GameState, x: number) {
|
||||
gameState.puckPosition = x;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Ball, GameState, PerkId, PerksMap } from "./types";
|
||||
import { icons, upgrades } from "./loadGameData";
|
||||
import { t } from "./i18n/i18n";
|
||||
import {Ball, GameState, PerkId, PerksMap} from "./types";
|
||||
import {icons, upgrades} from "./loadGameData";
|
||||
import {t} from "./i18n/i18n";
|
||||
|
||||
export function getMajorityValue(arr: string[]): string {
|
||||
const count: { [k: string]: number } = {};
|
||||
|
@ -119,9 +119,6 @@ export function distanceBetween(
|
|||
return Math.sqrt(distance2(a, b));
|
||||
}
|
||||
|
||||
export function clamp(value: number, min: number, max: number) {
|
||||
return Math.max(min, Math.min(value, max));
|
||||
}
|
||||
export function defaultSounds() {
|
||||
return {
|
||||
aboutToPlaySound: {
|
||||
|
@ -190,6 +187,3 @@ export function countBricksBelow(gameState: GameState, index: number) {
|
|||
return count;
|
||||
}
|
||||
|
||||
export function comboKeepingRate(level:number){
|
||||
return clamp(1-1/(1+level)*1.5,0,1)
|
||||
}
|
7
src/pure_functions.ts
Normal file
7
src/pure_functions.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export function clamp(value: number, min: number, max: number) {
|
||||
return Math.max(min, Math.min(value, max));
|
||||
}
|
||||
|
||||
export function comboKeepingRate(level: number) {
|
||||
return clamp(1 - 1 / (1 + level) * 1.5, 0, 1)
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { t } from "./i18n/i18n";
|
||||
import {comboKeepingRate} from "./game_utils";
|
||||
|
||||
import {comboKeepingRate} from "./pure_functions";
|
||||
|
||||
export const rawUpgrades = [
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue