From 8b7f83a14a0a8fdcb261874545d90962b6a57a45 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 4 Sep 2021 03:49:49 +0300 Subject: [PATCH] Separated display and room characteristics: updated context, created default value --- src/constants.ts | 16 ++++++++++++++++ src/context.tsx | 7 +++---- src/{types.ts => types/context.ts} | 8 +++++--- src/types/room.ts | 7 +++++-- 4 files changed, 29 insertions(+), 9 deletions(-) rename src/{types.ts => types/context.ts} (56%) diff --git a/src/constants.ts b/src/constants.ts index dbd8aec..0aa0abf 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,4 @@ +import { ContextData } from "./types/context"; import { PeriodFormat } from "./types/time"; export const lessonPeriods: readonly PeriodFormat[] = [ @@ -18,3 +19,18 @@ export const WeekDays = [ "Saturday", "Sunday", ] as const; + +// It will look like Windows 11 logo, lol +export const defaultState: ContextData = { + map: [ + { x: 5, y: 5 }, + { x: 110, y: 5 }, + { x: 5, y: 110 }, + { x: 110, y: 110 }, + ].map((coordinates) => ({ coordinates, size: { w: 100, h: 100 } })), + char: Array(4) + .fill(0) + .map(() => ({ + free: true, + })), +}; diff --git a/src/context.tsx b/src/context.tsx index 2d3ecef..d8a6813 100644 --- a/src/context.tsx +++ b/src/context.tsx @@ -1,12 +1,11 @@ import { createContext, FC, useContext, useState } from "react"; -import { ContextData, ContextValue } from "./types"; - -const defaultState: ContextData = { x: 0 }; +import { defaultState } from "./constants"; +import { ContextData, ContextValue } from "./types/context"; const Context = createContext(undefined); export const RoomContextProvider: FC = ({ children }) => { - const [state, setState] = useState(defaultState); + const [state, setState] = useState(defaultState); return ( {children} diff --git a/src/types.ts b/src/types/context.ts similarity index 56% rename from src/types.ts rename to src/types/context.ts index f31f14e..126e87d 100644 --- a/src/types.ts +++ b/src/types/context.ts @@ -1,10 +1,12 @@ import { Dispatch, SetStateAction } from "react"; +import { RoomDisplay, RoomState } from "./room"; export interface ContextData { - // TODO: describe state + map: RoomDisplay[]; + char: RoomState[]; } -export interface ContextValue { +export type ContextValue = { state: ContextData; setState: Dispatch>; -} +}; diff --git a/src/types/room.ts b/src/types/room.ts index 219274e..453ade1 100644 --- a/src/types/room.ts +++ b/src/types/room.ts @@ -1,5 +1,8 @@ -export type RoomT = { +export interface RoomDisplay { coordinates: { x: number; y: number }; size: { w: number; h: number }; +} + +export interface RoomState { free: boolean; -}; +}