From 9092050c37aa8ee238d181d35c4075c8a6945283 Mon Sep 17 00:00:00 2001 From: Simon J Date: Fri, 3 Sep 2021 13:03:50 +1000 Subject: [PATCH] Additional Icons (#43) --- src/clock.ts | 1 + src/icon.ts | 29 ++++++++++++++++++++++++++++- tests/icon.test.ts | 26 ++++++++++++++++++++++++++ web/icons/C-3PO-31823.svg | 15 +++++++++++++++ web/icons/Chewbacca-89771.svg | 13 +++++++++++++ web/icons/Darth-Vader-35734.svg | 12 ++++++++++++ web/icons/Luke-Skywalker-39424.svg | 15 +++++++++++++++ web/icons/Princess-Leia-68568.svg | 24 ++++++++++++++++++++++++ web/icons/R2-D2-39423.svg | 27 +++++++++++++++++++++++++++ web/icons/Yoda-68107.svg | 23 +++++++++++++++++++++++ 10 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 web/icons/C-3PO-31823.svg create mode 100644 web/icons/Chewbacca-89771.svg create mode 100644 web/icons/Darth-Vader-35734.svg create mode 100644 web/icons/Luke-Skywalker-39424.svg create mode 100644 web/icons/Princess-Leia-68568.svg create mode 100644 web/icons/R2-D2-39423.svg create mode 100644 web/icons/Yoda-68107.svg diff --git a/src/clock.ts b/src/clock.ts index 0a38342..39e806e 100644 --- a/src/clock.ts +++ b/src/clock.ts @@ -1,6 +1,7 @@ import dayjs, { Dayjs } from "dayjs"; export const isChristmas = (clock: Clock = SystemClock) => clock.now().month() == 11 && clock.now().date() == 25; +export const isMay4 = (clock: Clock = SystemClock) => clock.now().month() == 4 && clock.now().date() == 4; export const isHalloween = (clock: Clock = SystemClock) => clock.now().month() == 9 && clock.now().date() == 31 export const isHoli = (clock: Clock = SystemClock) => ["2022/03/18", "2023/03/07", "2024/03/25", "2025/03/14"].map(dayjs).find(it => it.isSame(clock.now())) != undefined export const isCNY = (clock: Clock = SystemClock) => ["2022/02/01", "2023/01/22", "2024/02/10", "2025/02/29"].map(dayjs).find(it => it.isSame(clock.now())) != undefined diff --git a/src/icon.ts b/src/icon.ts index c9d0469..c1de5c3 100644 --- a/src/icon.ts +++ b/src/icon.ts @@ -10,6 +10,7 @@ import { isCNY_2024, isHalloween, isHoli, + isMay4, SystemClock, } from "./clock"; import path from "path"; @@ -217,7 +218,14 @@ export type ICON = | "yoRabbit" | "yoTiger" | "chapel" - | "audioWave"; + | "audioWave" + | "c3po" + | "chewy" + | "darth" + | "skywalker" + | "leia" + | "r2d2" + | "yoda"; const iconFrom = (name: string) => new SvgIcon( @@ -285,8 +293,17 @@ export const ICONS: Record = { yoTiger: iconFrom("Year-of Tiger-22776.svg"), chapel: iconFrom("Chapel-69791.svg"), audioWave: iconFrom("Audio-Wave-1892.svg"), + c3po: iconFrom("C-3PO-31823.svg"), + chewy: iconFrom("Chewbacca-89771.svg"), + darth: iconFrom("Darth-Vader-35734.svg"), + skywalker: iconFrom("Luke-Skywalker-39424.svg"), + leia: iconFrom("Princess-Leia-68568.svg"), + r2d2: iconFrom("R2-D2-39423.svg"), + yoda: iconFrom("Yoda-68107.svg"), }; +export const STAR_WARS = [ICONS.c3po, ICONS.chewy, ICONS.darth, ICONS.skywalker, ICONS.leia, ICONS.r2d2, ICONS.yoda]; + export type RULE = (genre: string) => boolean; export const eq = @@ -438,6 +455,16 @@ export const festivals = (clock: Clock = SystemClock): Transformer => { foregroundColor: "orange", }, }) + ), + maybeTransform( + () => isMay4(clock), + transform({ + svg: STAR_WARS[_.random(STAR_WARS.length - 1)]!.svg, + features: { + backgroundColor: undefined, + foregroundColor: undefined, + }, + }) ) ); }; diff --git a/tests/icon.test.ts b/tests/icon.test.ts index 381d007..fdbfbf3 100644 --- a/tests/icon.test.ts +++ b/tests/icon.test.ts @@ -18,6 +18,7 @@ import { festivals, allOf, features, + STAR_WARS, } from "../src/icon"; describe("SvgIcon", () => { @@ -635,6 +636,31 @@ describe("festivals", () => { }); }); + describe("on may 4", () => { + beforeEach(() => { + now = dayjs("2022/5/4"); + }); + + it("should use the undefined colors, so no color", () => { + const result = original + .apply( + features({ + viewPortIncreasePercent: 12, + backgroundColor: "shouldNotBeUsed", + foregroundColor: "shouldNotBeUsed", + }) + ) + .apply(festivals(clock)) as DummyIcon; + + expect(STAR_WARS.map(it => it.svg)).toContain(result.svg); + expect(result.features).toEqual({ + viewPortIncreasePercent: 12, + backgroundColor: undefined, + foregroundColor: undefined, + }); + }); + }); + describe("on cny", () => { describe("2022", () => { beforeEach(() => { diff --git a/web/icons/C-3PO-31823.svg b/web/icons/C-3PO-31823.svg new file mode 100644 index 0000000..e6aa0ff --- /dev/null +++ b/web/icons/C-3PO-31823.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/Chewbacca-89771.svg b/web/icons/Chewbacca-89771.svg new file mode 100644 index 0000000..2e8387a --- /dev/null +++ b/web/icons/Chewbacca-89771.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/Darth-Vader-35734.svg b/web/icons/Darth-Vader-35734.svg new file mode 100644 index 0000000..08b6d3d --- /dev/null +++ b/web/icons/Darth-Vader-35734.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/Luke-Skywalker-39424.svg b/web/icons/Luke-Skywalker-39424.svg new file mode 100644 index 0000000..4fd0681 --- /dev/null +++ b/web/icons/Luke-Skywalker-39424.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/Princess-Leia-68568.svg b/web/icons/Princess-Leia-68568.svg new file mode 100644 index 0000000..d69bba1 --- /dev/null +++ b/web/icons/Princess-Leia-68568.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/R2-D2-39423.svg b/web/icons/R2-D2-39423.svg new file mode 100644 index 0000000..70d36d6 --- /dev/null +++ b/web/icons/R2-D2-39423.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/icons/Yoda-68107.svg b/web/icons/Yoda-68107.svg new file mode 100644 index 0000000..a0e4565 --- /dev/null +++ b/web/icons/Yoda-68107.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file