Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
921e1f0
Delete everything
adzialocha Aug 23, 2022
00c4176
Set up Rollup project
adzialocha Aug 23, 2022
93f0626
Correct .nvmrc format
adzialocha Aug 23, 2022
cfb55ab
Add a README.md
adzialocha Aug 23, 2022
aef56a0
Update dependencies
adzialocha Aug 23, 2022
411c619
Rename too ZooAdventures component
adzialocha Aug 23, 2022
30e9aff
Add nodemon to watch for changes
adzialocha Aug 23, 2022
5346e77
Install graphql-request dependencies
adzialocha Aug 23, 2022
891f522
Add CommonJS to build library
adzialocha Aug 23, 2022
41f9806
Initial script to build schema and first board
adzialocha Aug 23, 2022
a1dc4f5
Initialise key pair and pass over configuration
adzialocha Aug 23, 2022
0913969
Display game board
adzialocha Aug 23, 2022
6fc83c5
Update field when clicking
adzialocha Aug 23, 2022
f9b3531
Add linter for react hooks
adzialocha Aug 23, 2022
79f3509
Define animal emoji based on public key
adzialocha Aug 23, 2022
400a53e
A little bit of styling
adzialocha Aug 23, 2022
50b4568
Do not show hover when already set
adzialocha Aug 23, 2022
0050b46
Do not send request when field is already set
adzialocha Aug 23, 2022
5e1f28e
Frequently update game board
adzialocha Aug 23, 2022
ca7dd33
Block player if they just made a move
adzialocha Aug 23, 2022
363e576
Split up in multiple files
adzialocha Aug 23, 2022
b0395d9
Move React components into separate files
adzialocha Aug 23, 2022
003ac79
Add some comments, improve logic for blocking player
adzialocha Aug 23, 2022
e426504
Add some doc strings
adzialocha Aug 23, 2022
09c3d39
WIP detect winner
adzialocha Aug 23, 2022
97cac6a
Add some doc strings
adzialocha Aug 24, 2022
9af8c7d
Calculate win combinations once, represent them as strings
adzialocha Aug 24, 2022
da8a28b
Get current winners of board
adzialocha Aug 24, 2022
605fe60
Show winner on board
adzialocha Aug 24, 2022
dc4260f
Fix checking winning positions
adzialocha Aug 24, 2022
ddd8961
Update comment
adzialocha Aug 24, 2022
e86ae85
Show messages to the user
adzialocha Aug 24, 2022
caf50bd
Style Message component, move animal info to the bottom
adzialocha Aug 24, 2022
67d593b
Remove emojis which are not animals
adzialocha Aug 24, 2022
92caf0e
Change message on the bottom
adzialocha Aug 24, 2022
cee7e0b
Change winSize to 3, check for sane configs
adzialocha Aug 24, 2022
925924a
Upload screenshot
adzialocha Aug 24, 2022
93be9f9
Update README.md
adzialocha Aug 24, 2022
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
Prev Previous commit
Next Next commit
Add some doc strings
  • Loading branch information
adzialocha committed Aug 23, 2022
commit e4265041801559ea693235f932f28df42c39c48b
12 changes: 6 additions & 6 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { GraphQLClient } from 'graphql-request';

import { GameBoard } from './GameBoard';
import { fetchBoard, updateBoardField } from './board';
import { fetchBoard, updateBoard } from './board';
import { loadKeyPair, loadLastMove, storeLastMove } from './storage';
import { publicKeyToAnimal } from './animals';

Expand Down Expand Up @@ -45,7 +45,7 @@ export const Game: React.FC<Props> = ({ config }) => {
// updates from the node
const [ready, setReady] = useState(true);

const updateBoard = useCallback(async () => {
const update = useCallback(async () => {
const board = await fetchBoard(
client,
config.schemaId,
Expand Down Expand Up @@ -100,7 +100,7 @@ export const Game: React.FC<Props> = ({ config }) => {
// The method gives us back the "latest" view id, that is, we assume that
// our last write is now the latest edge of the operation graph. But who
// knows, maybe some concurrent write by someone decided something else!
const latestViewId = await updateBoardField(
const latestViewId = await updateBoard(
client,
keyPair,
config.schemaId,
Expand All @@ -118,15 +118,15 @@ export const Game: React.FC<Props> = ({ config }) => {

useEffect(() => {
const interval = window.setInterval(() => {
updateBoard();
update();
}, config.updateIntervalMs);

updateBoard();
update();

return () => {
window.clearInterval(interval);
};
}, [client, updateBoard, config.updateIntervalMs]);
}, [client, update, config.updateIntervalMs]);

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/GameBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import styled from 'styled-components';

// All dimensions in pixels
const FIELD_SIZE = 60;
const GAP_SIZE = 17;
const ICON_SIZE = 28;
Expand Down
8 changes: 7 additions & 1 deletion src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {

import { nextArgs, publish } from './request';

export async function updateBoardField(
/**
* We're making a move. Send that update to the board.
*/
export async function updateBoard(
client: GraphQLClient,
keyPair: KeyPair,
schemaId: string,
Expand Down Expand Up @@ -41,6 +44,9 @@ export async function updateBoardField(
return generateHash(entry);
}

/**
* Get the latest board game state from the node.
*/
export async function fetchBoard(
client: GraphQLClient,
schemaId: string,
Expand Down
12 changes: 12 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/**
* Zoo Adventures game configuration.
*/
export type Configuration = {
/** Dimensions of the board, set to 4 when it is a 4x4 board */
boardSize: number;

/** All players play on the same board, this is the document id of it */
documentId: string;

/** URL of the p2panda node */
endpoint: string;

/** ID of the game board schema, make sure the board size matches the fields */
schemaId: string;

/** Interval to fetch latest board game state from node in milliseconds */
updateIntervalMs: number;
};