Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ worker-configuration.d.ts

!.dev.vars.example
!.env.example

.direnv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Hai, haiToIndex } from "shared/hai.ts";
import { type Hai, haiToIndex } from "./utils";

function deleteSyuntsu(remainingTehai: TehaiIndex): number {
let extractCount = 0;
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions app/lib/redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from "redis";
import type { Hai } from "./hai";
import { sortTehai } from "./hai";
import type { Hai } from "./hai/utils";
import { sortTehai } from "./hai/utils";

export function getRedisClient(env: Env) {
const client = createClient({
Expand Down Expand Up @@ -73,8 +73,9 @@ export const tedashi = async (
if (index < 0 || 12 < index) {
throw new Error("index out of tehai length");
}
const deletedTehai = state.tehai.filter((_, i) => i !== index);
const discardedHai = state.tehai[index];
const sortedTehai = sortTehai(state.tehai);
const deletedTehai = sortedTehai.filter((_, i) => i !== index);
const discardedHai = sortedTehai[index];

const newGameState: GameState = {
...state,
Expand Down
24 changes: 3 additions & 21 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import { drizzle as drizzleNeon } from "drizzle-orm/neon-http";
import { drizzle as drizzlePg } from "drizzle-orm/node-postgres";
import type { c } from "node_modules/better-auth/dist/shared/better-auth.C9FmyZ5W.cjs";
import { Link, useNavigate } from "react-router";
import { authClient } from "~/lib/auth-client";
import { getRedisClient } from "~/lib/redis";
import type { Route } from "./+types/_index";

export async function loader({ context }: Route.LoaderArgs) {
const { env } = context.cloudflare;
const db =
env.NODE_ENV === "development"
? drizzlePg(env.DATABASE_URL)
: drizzleNeon(env.DATABASE_URL);
const redisClient = getRedisClient(env);
redisClient.on("error", (err) => console.log("Redis Client Error", err));
await redisClient.connect();
await redisClient.set("key", "value");
const value = await redisClient.get("key");
console.log(value);
}

export default function Page() {
const navigate = useNavigate();
const anonymousLoginAndStart = async () => {
const user = await authClient.getSession();
if (!user) {
const _user = await authClient.signIn.anonymous();
if (user.data) {
const _user = await authClient.signOut();
}
const _user = await authClient.signIn.anonymous();
navigate("/play");
};
return (
Expand Down
Empty file added app/routes/play.agari.ts
Empty file.
Empty file added app/routes/play.ryukyoku.ts
Empty file.
36 changes: 35 additions & 1 deletion app/routes/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Form } from "react-router";
import { getAuth } from "~/lib/auth";
import { getDB } from "~/lib/db";
import { hai, haiyama } from "~/lib/db/schema";
import { dbHaiToHai, sortTehai } from "~/lib/hai";
import judgeAgari from "~/lib/hai/judgeAgari";
import { dbHaiToHai, sortTehai } from "~/lib/hai/utils";
import { type GameState, getRedisClient, init } from "~/lib/redis";
import type { Route } from "./+types/play";

Expand Down Expand Up @@ -73,6 +74,9 @@ export async function loader({
export default function Page({ loaderData }: Route.ComponentProps) {
let { haiyama, sutehai, tsumohai, junme, kyoku, tehai } = loaderData;
tehai = sortTehai(tehai);
const isAgari =
tehai && tsumohai ? judgeAgari(sortTehai([...tehai, tsumohai])) : false;
const isRyukyoku = junme === 19;
const indexedSutehai = sutehai.map((hai, index) => ({
...hai,
index: index,
Expand All @@ -84,6 +88,36 @@ export default function Page({ loaderData }: Route.ComponentProps) {

return (
<div className="p-4">
{isAgari && (
<dialog id="agari_modal" className="modal" open>
<div className="modal-box">
<h3 className="font-bold text-lg">ツモ!</h3>
<div className="modal-action">
<form method="post" action="/play/agari">
<input type="hidden" value={junme} name="junme" />
<button className="btn" type="submit">
確認
</button>
</form>
</div>
</div>
</dialog>
)}
{isRyukyoku && (
<dialog id="ryukyoku_modal" className="modal" open>
<div className="modal-box">
<h3 className="font-bold text-lg">流局</h3>
<div className="modal-action">
<form method="post" action="/play/ryukyoku">
<button className="btn" type="submit">
確認
</button>
</form>
</div>
</div>
</dialog>
)}

<p className="text-xl mb-4">
Play Page - 局 {kyoku} 巡目 {junme}
</p>
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{ nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [ redis ];
};
}
);
}