Skip to content

Commit

Permalink
fix: 街に椅子が集まりやすくする
Browse files Browse the repository at this point in the history
  • Loading branch information
narirou committed Dec 2, 2024
1 parent 2638ffb commit c372c85
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions frontend/app/components/hooks/use-ghost-chairs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
import { useEffect, useState } from "react";
import { NearByChair } from "~/types";
import { TownList } from "../modules/map/map-data";

const randomInt = (min: number, max: number) =>
Math.floor(Math.random() * (max - min + 1)) + min;

const emulateChairs = [...Array(100).keys()].map((i) => {
// 街には椅子が集まりやすい
const townGhostChairs = TownList.flatMap(({ centerCoordinate, name }) => {
return [...Array(8).keys()].map((i) => ({
id: name + "-ghost-" + i,
current_coordinate: {
latitude: randomInt(
centerCoordinate.latitude - 50,
centerCoordinate.latitude + 50,
),
longitude: randomInt(
centerCoordinate.longitude - 50,
centerCoordinate.longitude + 50,
),
},
model: String(i),
name: "ghost",
}));
});

const ghostChairs = [...Array(70).keys()].map((i) => {
return {
id: "simulate" + i,
id: "ghost" + i,
current_coordinate: {
latitude: randomInt(-500, 500),
longitude: randomInt(-500, 500),
},
model: String(i),
name: "hoge",
name: "ghost",
};
}) satisfies NearByChair[];

export const useGhostChairs = (): NearByChair[] => {
const [enabled, setEnabled] = useState<boolean>(false);
const [chairs, setChairs] = useState<NearByChair[]>(emulateChairs);
const [chairs, setChairs] = useState<NearByChair[]>([
...townGhostChairs,
...ghostChairs,
]);

useEffect(() => {
const onMessage = ({
Expand Down

0 comments on commit c372c85

Please sign in to comment.