diff --git a/app/react/components/dom/date.jsx b/app/react/components/dom/date.jsx new file mode 100644 index 0000000..f2f9d3e --- /dev/null +++ b/app/react/components/dom/date.jsx @@ -0,0 +1,40 @@ +import {useState} from 'react'; + +import styles from './date.module.css'; + +export function Date({season, date}) { + const seasonLabel = (() => { + switch (season) { + case 0: return 'Spring'; + case 1: return 'Summer'; + case 2: return 'Autumn'; + case 3: return 'Winter'; + } + })(); + const dateLabel = (() => { + if (date >= 10 && date < 13) { + return <>{date + 1}th; + } + switch (date % 10) { + case 0: return <>{date + 1}st; + case 1: return <>{date + 1}nd; + case 2: return <>{date + 1}rd; + default: return <>{date + 1}th; + } + })(); + return ( +
+ {seasonLabel} +   + {dateLabel} +
+ ); +} + +function ConnectedDate() { + const [season, setSeason] = useState(0); + const [date, setDate] = useState(0); + return ; +} + +export default ConnectedDate; diff --git a/app/react/components/dom/date.module.css b/app/react/components/dom/date.module.css new file mode 100644 index 0000000..5ff0e88 --- /dev/null +++ b/app/react/components/dom/date.module.css @@ -0,0 +1,11 @@ +.date { + align-items: center; + display: flex; + font-family: Cookbook, Georgia, 'Times New Roman', Times, serif; + font-size: 16px; + text-shadow: 1px 0 0 black, 0 1px 0 black, -1px 0 0 black, 0 -1px 0 black; +} + +.number { + font-family: 'Courier New', Courier, monospace; +} diff --git a/app/react/components/dom/datetime.jsx b/app/react/components/dom/datetime.jsx new file mode 100644 index 0000000..e30ff27 --- /dev/null +++ b/app/react/components/dom/datetime.jsx @@ -0,0 +1,15 @@ +import Date from './date.jsx'; +import Time from './time.jsx'; + +import styles from './datetime.module.css'; + +function DateTime() { + return ( +
+ +
+ ) +} + +export default DateTime; diff --git a/app/react/components/dom/datetime.module.css b/app/react/components/dom/datetime.module.css new file mode 100644 index 0000000..9b762da --- /dev/null +++ b/app/react/components/dom/datetime.module.css @@ -0,0 +1,12 @@ +.datetime { + align-items: center; + color: white; + display: flex; + gap: 6px; + position: absolute; + right: 10px; + top: 4px; + div:first-child:not(:last-child):after { + content: ', '; + } +} diff --git a/app/react/components/dom/time.jsx b/app/react/components/dom/time.jsx new file mode 100644 index 0000000..e50c59e --- /dev/null +++ b/app/react/components/dom/time.jsx @@ -0,0 +1,37 @@ +import {useCallback, useState} from 'react'; + +import {useEcsTick} from '@/react/context/ecs.js'; + +import styles from './time.module.css'; + +export function Time({hour, minute}) { + const formatter = new Intl.DateTimeFormat(undefined, {timeStyle: 'short'}); + const {hour12} = formatter.resolvedOptions(); + const formatted = formatter.format(new Date(2012, 11, 20, hour, minute)); + return ( +
+ { + hour12 + ? <>{formatted.slice(0, -3)}{formatted.slice(-2)} + : formatted + } +
+ ); +} + +function ConnectedTime() { + const [hour, setHour] = useState(-1); + const [minute, setMinute] = useState(0); + useEcsTick(useCallback((paylaod, ecs) => { + const {Time: {hour}} = ecs.get(1); + const wholeHour = Math.floor(hour); + setHour(wholeHour); + setMinute(Math.floor(60 * (hour - wholeHour))); + }, [])); + if (-1 === hour) { + return false; + } + return