Skip to content

Commit

Permalink
Ultimatum view models
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo33 committed Dec 25, 2023
1 parent 7a47d43 commit 55a80bc
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 230 deletions.
143 changes: 67 additions & 76 deletions crates/apps/xeejp/package-lock.json

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

4 changes: 2 additions & 2 deletions crates/apps/xeejp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"fast-deep-equal": "^3.1.3",
"flag-icons": "^6.7.0",
"jotai": "^2.3.1",
"next": "13.4.6",
"postcss": "8.4.24",
"next": "^13.5.6",
"postcss": "^8.4.32",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.46.1",
Expand Down
36 changes: 36 additions & 0 deletions crates/apps/xeejp/pages/conduct.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { clientIdAtom, useUltimatumConductor } from "@/api/gameSocket";
import { useAtom } from "jotai";
import { atomWithStorage } from "jotai/utils";
import { useRouter } from "next/router";
import { v4 as uuidv4 } from "uuid";

const conductorPasswordAtom = atomWithStorage<string>(
"conductorPassword",
uuidv4(),
);

const Conduct = () => {
const router = useRouter();
if (!router.isReady) return "loading";
const { roomKey } = router.query;
return <Inner roomKey={roomKey as string} />;
};

const Inner = ({ roomKey }: { roomKey: string }) => {
const [channelId] = useAtom(clientIdAtom);
const [password] = useAtom(conductorPasswordAtom);
let { state, connectionStatus, sendCommand } = useUltimatumConductor(
roomKey,
channelId,
password,
);

return (
<div>
<div>connectionStatus: {connectionStatus}</div>
<div>state: {JSON.stringify(state)}</div>
</div>
);
};

export default Conduct;
15 changes: 9 additions & 6 deletions crates/games/eagle-ultimatum/src/conductor_model.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use serde::{Deserialize, Serialize};
use tsify::Tsify;

use crate::types::{Proposal, Response};
use crate::{
phase::Phase,
types::{Proposal, Response},
};

#[derive(Tsify, Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Tsify, Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct UltimatumConductor {
proposal: Option<Proposal>,
proposed: bool,
response: Option<Response>,
errors: Vec<String>,
pub phase: Phase,
pub proposal: Option<Proposal>,
pub response: Option<Response>,
pub errors: Vec<String>,
}

impl UltimatumConductor {
Expand Down
Loading

0 comments on commit 55a80bc

Please sign in to comment.