Skip to content

Commit 734406c

Browse files
Merge pull request #11 from Chia-Network/20240816-demo
Bring in the game cradle into the demo app
2 parents 3cdd83e + 9579ba6 commit 734406c

File tree

15 files changed

+958
-108
lines changed

15 files changed

+958
-108
lines changed

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
sim-tests = []
7+
sim-tests = ["dep:pyo3"]
8+
simulator = ["dep:pyo3"]
89

910
[dependencies]
1011
clvm_tools_rs = { git = "https://github.com/Chia-Network/clvm_tools_rs.git", rev = "ec75759377791c9b785123d2d3e2457d08ac6621" }
@@ -32,9 +33,9 @@ tracing-subscriber = "0.3"
3233
ctor = "0.2.8"
3334
log = "0.4.22"
3435
env_logger = "0.11.3"
36+
pyo3 = { version = "0.20.0", features = ["auto-initialize"], optional = true }
3537

3638
[dev-dependencies]
37-
pyo3 = { version = "0.20.0", features = ["auto-initialize"] }
3839
bls12_381 = { version = "=0.8.0", features = ["experimental"] }
3940

4041
[build-dependencies]
@@ -50,3 +51,4 @@ crate-type = ["cdylib", "rlib"]
5051
[[bin]]
5152
name = "chia-gaming"
5253
path = "src/cmd/main.rs"
54+
required-features = ["simulator"]

resources/web/index.css

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
body {
2+
overflow: hidden;
3+
}
4+
5+
#heading {
6+
display: inline-block;
7+
}
8+
9+
#container {
10+
position: relative;
11+
width: 300vw;
12+
height: 85vw;
13+
overflow: hidden;
14+
}
15+
16+
#app {
17+
top: 0;
18+
left: 30vw;
19+
display: inline-block;
20+
margin: 0;
21+
position: absolute;
22+
padding: 0;
23+
width: 78vw;
24+
height: 85vh;
25+
background: #ccc;
26+
}
27+
28+
#info {
29+
left: 0;
30+
top: 0;
31+
display: inline-block;
32+
margin: 0;
33+
position: absolute;
34+
width: 28vw;
35+
height: 85vh;
36+
background: #bbb;
37+
}
38+
39+
#p1 {
40+
margin: 0;
41+
position: relative;
42+
height: 40vh;
43+
width: 98vw;
44+
background: #fcc;
45+
}
46+
47+
#p2 {
48+
margin: 0;
49+
margin-top: 1rem;
50+
position: relative;
51+
height: 40vh;
52+
width: 98vw;
53+
background: #cfc;
54+
}
55+
56+
.cardspan {
57+
margin-left: 0.5em;
58+
border: 1px solid black;
59+
}

resources/web/index.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<title>Calpoker</title>
4+
<link rel="stylesheet" href="index.css"/>
5+
</head>
6+
<body>
7+
<div>
8+
<h1 id="heading">Calpoker</h1>
9+
<button onclick="exitapp()">Terminate</button>
10+
</div>
11+
<div id="container">
12+
<div id="info"> </div>
13+
<div id="app">
14+
<div id="p1"></div>
15+
<div id="p2"></div>
16+
</div>
17+
</div>
18+
</body>
19+
<script type="text/javascript" src="index.js"> </script>
20+
</body>
21+
</html>

resources/web/index.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
let all_selected_cards = [{}, {}];
2+
3+
function set_card_properties(who, collection) {
4+
for (let i = 0; i < 8; i++) {
5+
let label = `${who}_card${i}`;
6+
let card = document.getElementById(label);
7+
if (!card) {
8+
continue;
9+
}
10+
let n_string = `_${i}`;
11+
if (collection[n_string]) {
12+
card.style.background = 'green';
13+
} else {
14+
card.style.background = 'white';
15+
}
16+
}
17+
}
18+
19+
function check() {
20+
return fetch("idle.json", {
21+
"method": "POST"
22+
}).then((response) => {
23+
return response.json();
24+
}).then((json) => {
25+
if (json.info) {
26+
const info = document.getElementById('info');
27+
info.innerHTML = json.info;
28+
}
29+
if (json.p1) {
30+
const p1 = document.getElementById('p1');
31+
p1.innerHTML = json.p1;
32+
}
33+
if (json.p2) {
34+
const p2 = document.getElementById('p2');
35+
p2.innerHTML = json.p2;
36+
}
37+
38+
set_card_properties('alice', all_selected_cards[0]);
39+
set_card_properties('bob', all_selected_cards[1]);
40+
41+
setTimeout(check, 500);
42+
});
43+
}
44+
45+
function send_alice_word() {
46+
let word = Math.random().toString();
47+
return fetch(`alice_word_hash?word=${word}`, {
48+
"method": "POST"
49+
});
50+
}
51+
52+
function send_bob_word() {
53+
let word = Math.random().toString();
54+
return fetch(`bob_word?word=${word}`, {
55+
"method": "POST"
56+
});
57+
}
58+
59+
function toggle_card(label, selected_cards, n) {
60+
let n_string = `_${n}`;
61+
let card = document.getElementById(label);
62+
if (!card) {
63+
return;
64+
}
65+
if (selected_cards[n_string]) {
66+
card.style.background = 'white';
67+
delete selected_cards[n_string];
68+
} else {
69+
card.style.background = 'green';
70+
selected_cards[n_string] = true;
71+
}
72+
console.log(selected_cards);
73+
}
74+
75+
function alice_toggle(n) {
76+
toggle_card(`alice_card${n}`, all_selected_cards[0], n);
77+
}
78+
79+
function bob_toggle(n) {
80+
toggle_card(`bob_card${n}`, all_selected_cards[1], n);
81+
}
82+
83+
function set_picks(who, id) {
84+
let picks = '';
85+
for (let i = 0; i < 8; i++) {
86+
let n_string = `_${i}`;
87+
picks += (all_selected_cards[id][n_string]) ? '1' : '0';
88+
}
89+
return fetch(`${who}_picks?cards=${picks}`, {
90+
"method": "POST"
91+
});
92+
}
93+
94+
function set_alice_picks() {
95+
set_picks('alice', 0);
96+
}
97+
98+
function set_bob_picks() {
99+
set_picks('bob', 1);
100+
}
101+
102+
function exitapp() {
103+
return fetch("exit", {"method": "POST"}).then((response) => {
104+
console.log("exiting...");
105+
});
106+
}
107+
108+
check();

src/channel_handler/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ impl ReadableMove {
283283
pub fn from_nodeptr(n: NodePtr) -> Self {
284284
ReadableMove(n)
285285
}
286+
287+
pub fn to_nodeptr(&self) -> NodePtr {
288+
self.0
289+
}
286290
}
287291

288292
impl ToClvm<NodePtr> for ReadableMove {

0 commit comments

Comments
 (0)