-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8aa1499
commit de4dd2b
Showing
7 changed files
with
220 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { generateColorMap } from "./daily"; | ||
|
||
describe(generateColorMap, () => { | ||
it("generates a color map based on a main color", () => { | ||
const mainColor = "#000099"; | ||
const colorMap = generateColorMap(mainColor); | ||
|
||
expect(colorMap).toEqual({ | ||
Check failure on line 10 in src/game/themes/daily.spec.ts GitHub Actions / buildsrc/game/themes/daily.spec.ts > generateColorMap > generates a color map based on a main color
|
||
white: "#000099", | ||
red: "#000099", | ||
yellow: "#000099", | ||
blue: "#000099", | ||
purple: "#000099", | ||
black: "#000099", | ||
green: "#000099", | ||
aqua: "#000099", | ||
darkgreen: "#000099", | ||
darkblue: "#000099", | ||
brown: "#000099", | ||
pink: "#000099", | ||
turquoise: "#000099", | ||
orange: "#000099", | ||
lightyellow: "#000099", | ||
gray: "#000099" | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const lighten = (mainColor: string, amount: number): string => { | ||
const color = mainColor.startsWith("#") ? mainColor.slice(1) : mainColor; | ||
const num = parseInt(color, 16); | ||
|
||
let r = (num >> 16) + amount; | ||
let g = ((num >> 8) & 0x00ff) + amount; | ||
let b = (num & 0x0000ff) + amount; | ||
|
||
r = Math.min(255, Math.max(0, r)); | ||
g = Math.min(255, Math.max(0, g)); | ||
b = Math.min(255, Math.max(0, b)); | ||
|
||
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, "0")}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { generateRandomLevel } from "@/game/level-creation/generateRandomLevel"; | ||
import { getDailySettings } from "@/game/level-types/daily"; | ||
import { mulberry32 } from "@/support/random"; | ||
import { fakeDate } from "@/support/schedule"; | ||
|
||
import { LevelLayout as LevelLayoutComponent } from "../LevelLayout/LevelLayout"; | ||
|
||
type CustomArgs = { | ||
theme: string; | ||
}; | ||
|
||
const occasionDates: [Date, name: string][] = [ | ||
[new Date("2022-02-14"), "valentine"], | ||
[new Date("2022-12-25"), "christmas"], | ||
[new Date("2022-10-31"), "halloween"], | ||
[new Date("2022-01-01"), "newYear"], | ||
[new Date("2022-04-22"), "earthDay"], | ||
[new Date("2022-04-01"), "aprilFools"], | ||
[new Date("2022-03-17"), "stPatricks"] | ||
]; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export | ||
const meta: Meta<CustomArgs> = { | ||
title: "BlockSort/Theme", | ||
parameters: { | ||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout | ||
layout: "centered" | ||
}, | ||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ["autodocs"], | ||
// More on argTypes: https://storybook.js.org/docs/api/argtypes | ||
argTypes: { | ||
theme: { | ||
options: ["default", ...occasionDates.map(([, name]) => name)], | ||
control: { type: "select" } | ||
} | ||
}, | ||
args: { | ||
theme: "valentine" | ||
} | ||
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const SEED = 123456789; | ||
|
||
const random = mulberry32(SEED); | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args | ||
export const DailyTheme: Story = { | ||
args: {}, | ||
render: (args) => { | ||
const settings = getDailySettings(11); | ||
const level = generateRandomLevel(settings, random); | ||
// fake the date | ||
const date = occasionDates.find((date) => date[1] === args.theme)?.[0]; | ||
if (date) { | ||
fakeDate(date); | ||
} | ||
|
||
return ( | ||
<div className="flex w-full flex-col"> | ||
<LevelLayoutComponent | ||
started={true} | ||
levelState={level} | ||
theme={"daily"} | ||
/> | ||
</div> | ||
); | ||
} | ||
}; |