board-game-engine-react 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,9 @@
1
1
  @charset "UTF-8";
2
+ :root {
3
+ --dark-orange: #F58F29;
4
+ --dark-amethyst: #380036;
5
+ --lipstick-red: #EC0B43; }
6
+
2
7
  html, body, #storybook-root, .story {
3
8
  height: 100%; }
4
9
 
@@ -1 +1 @@
1
- html,body,#storybook-root,.story{height:100%}.button{border:3px solid var(--dark-amethyst);display:inline-block;padding:.5em;font-size:1.5em;font-family:inherit;text-decoration:none;cursor:pointer;border-radius:.3em;box-shadow:0 4px 6px rgba(0,0,0,0.15);margin:.5em}.button--style-b{background-color:var(--dark-amethyst);color:white}.button--style-c{background-color:var(--lipstick-red);color:white}.button--x-small{font-size:.9em;padding:.3em .5em;border-radius:.2em}.game{color:black}.shared-board,.personal-board{padding:1em 0;border-bottom:1px solid white}.grid{border:1px solid black;box-sizing:border-box;background-color:#333;max-width:500px}.grid__cell{border:1px solid black;background-color:#fff;aspect-ratio:1;display:flex;align-items:center;justify-content:center;color:#666;position:relative;overflow:auto}.grid__cell .space{height:100%;width:100%}.space{box-sizing:border-box;min-width:10px;min-height:10px}.space:not(:has(.entity)):not(.grid__cell>:only-child){border:1px solid grey}.space--clickable{background-color:rgba(144,238,144,0.4)}.space--targeted{background-color:grey}.space__entity-grid{box-sizing:border-box;align-items:center;justify-content:center}.space__entity-grid__cell{box-sizing:border-box;overflow:auto}.entity{padding:.2em;min-height:20px;min-width:20px;box-sizing:border-box;border:1px solid black;overflow:hidden;font-size:.5em;font-family:"Nunito", sans-serif;font-weight:bold;display:inline-block}.entity.player-0{background-color:pink}.entity--clickable{background-color:rgba(144,238,144,0.4)}.entity.player-0.entity--clickable{background-color:#f0e0d8}.entity.player-1{background-color:lightblue}.entity.player-1.entity--clickable{background-color:paleturquoise}.debug-panel .pane{max-width:420px !important}.game-status{position:absolute;top:50%;left:0;transform:translateY(-50%);width:100%;border-top:1em;border-bottom:1em;padding:1em;background-color:var(--dark-orange);color:black;box-sizing:border-box;font-size:3em}.debug-panel .visibility-toggle{top:70px !important}.debug-panel .visibility-toggle svg{display:none}.debug-panel .visibility-toggle .icon::after{position:relative;left:3px;content:"⚙️";font-size:20px;display:block;width:20px;height:20px}.debug-panel .menu{position:relative;top:70px !important}
1
+ :root{--dark-orange: #F58F29;--dark-amethyst: #380036;--lipstick-red: #EC0B43}html,body,#storybook-root,.story{height:100%}.button{border:3px solid var(--dark-amethyst);display:inline-block;padding:.5em;font-size:1.5em;font-family:inherit;text-decoration:none;cursor:pointer;border-radius:.3em;box-shadow:0 4px 6px rgba(0,0,0,0.15);margin:.5em}.button--style-b{background-color:var(--dark-amethyst);color:white}.button--style-c{background-color:var(--lipstick-red);color:white}.button--x-small{font-size:.9em;padding:.3em .5em;border-radius:.2em}.game{color:black}.shared-board,.personal-board{padding:1em 0;border-bottom:1px solid white}.grid{border:1px solid black;box-sizing:border-box;background-color:#333;max-width:500px}.grid__cell{border:1px solid black;background-color:#fff;aspect-ratio:1;display:flex;align-items:center;justify-content:center;color:#666;position:relative;overflow:auto}.grid__cell .space{height:100%;width:100%}.space{box-sizing:border-box;min-width:10px;min-height:10px}.space:not(:has(.entity)):not(.grid__cell>:only-child){border:1px solid grey}.space--clickable{background-color:rgba(144,238,144,0.4)}.space--targeted{background-color:grey}.space__entity-grid{box-sizing:border-box;align-items:center;justify-content:center}.space__entity-grid__cell{box-sizing:border-box;overflow:auto}.entity{padding:.2em;min-height:20px;min-width:20px;box-sizing:border-box;border:1px solid black;overflow:hidden;font-size:.5em;font-family:"Nunito", sans-serif;font-weight:bold;display:inline-block}.entity.player-0{background-color:pink}.entity--clickable{background-color:rgba(144,238,144,0.4)}.entity.player-0.entity--clickable{background-color:#f0e0d8}.entity.player-1{background-color:lightblue}.entity.player-1.entity--clickable{background-color:paleturquoise}.debug-panel .pane{max-width:420px !important}.game-status{position:absolute;top:50%;left:0;transform:translateY(-50%);width:100%;border-top:1em;border-bottom:1em;padding:1em;background-color:var(--dark-orange);color:black;box-sizing:border-box;font-size:3em}.debug-panel .visibility-toggle{top:70px !important}.debug-panel .visibility-toggle svg{display:none}.debug-panel .visibility-toggle .icon::after{position:relative;left:3px;content:"⚙️";font-size:20px;display:block;width:20px;height:20px}.debug-panel .menu{position:relative;top:70px !important}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "board-game-engine-react",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "React library for using board-game-engine",
5
5
  "main": "dist/board-game-engine-react.js",
6
6
  "scripts": {
package/src/styles.scss CHANGED
@@ -1,3 +1,9 @@
1
+ :root {
2
+ --dark-orange: #F58F29;
3
+ --dark-amethyst: #380036;
4
+ --lipstick-red: #EC0B43;
5
+ }
6
+
1
7
  html, body, #storybook-root, .story, {
2
8
  height: 100%;
3
9
  }
@@ -1,49 +1,47 @@
1
1
  import React from 'react'
2
- import BoardGameEngineReact from '../src/index'
2
+ import { Game, useGameserverConnection } from '../src/index'
3
+ import ticTacToe from './tic-tac-toe.json'
3
4
  import { ErrorBoundary } from 'react-error-boundary'
4
5
  import './styles.css'
5
6
 
6
- const dialogue = `
7
- title: Start
8
- ---
9
- Red: Hello.
10
- Blue: Hi!
11
- Red: I'm here.
12
- Blue: I'm here too!
13
- ===
14
- `
15
-
16
7
  export default {
17
- title: 'BoardGameEngineReact',
18
- component: BoardGameEngineReact,
8
+ title: 'Game',
9
+ component: Game,
19
10
  className: 'board-game-engine-react',
20
11
  args: {
21
- dialogue,
12
+ gameRules: JSON.stringify(ticTacToe, null, 2),
13
+ numPlayers: 2,
22
14
  },
23
15
  argTypes: {
24
- dialogue: {
16
+ gameRules: {
25
17
  control: 'text'
18
+ },
19
+ numPlayers: {
20
+ control: 'number'
26
21
  }
27
22
  }
28
23
  }
29
24
 
30
- const Template = (props) => {
25
+ const Template = ({ gameRules, numPlayers }) => {
26
+ const gameConnection = useGameserverConnection({
27
+ gameRules,
28
+ singlePlayer: true,
29
+ numPlayers,
30
+ })
31
+
31
32
  return (
32
33
  <div className="story">
33
34
  <ErrorBoundary
34
- resetKeys={[props.dialogue]}
35
+ resetKeys={[gameRules, numPlayers]}
35
36
  fallbackRender={({ error }) => {
36
37
  return (
37
38
  <div>
38
- Invalid Dialogue: {error.message}
39
+ Invalid Game Rules {error}
39
40
  </div>
40
41
  )
41
42
  }}
42
43
  >
43
- <BoardGameEngineReact
44
- {...props}
45
- onDialogueEnd={() => { alert('onDialogueEnd called') }}
46
- />
44
+ <Game gameConnection={gameConnection} />
47
45
  </ErrorBoundary>
48
46
  </div>
49
47
  )
@@ -0,0 +1,53 @@
1
+ {
2
+ "entities": [
3
+ {
4
+ "name": "mainGrid",
5
+ "type": "Grid",
6
+ "width": 3,
7
+ "height": 3
8
+ }
9
+ ],
10
+ "numPlayers": 2,
11
+ "moves": {
12
+ "placePlayerMarker": {
13
+ "type": "PlaceNew",
14
+ "entity": {
15
+ "thatMatches": "isCurrentPlayer"
16
+ },
17
+ "arguments": {
18
+ "destination": {
19
+ "thatMatches": [
20
+ { "type": "Space" },
21
+ "isEmpty"
22
+ ],
23
+ "playerChoice": true
24
+ }
25
+ }
26
+ }
27
+ },
28
+ "endConditions": [
29
+ {
30
+ "conditions": [{
31
+ "conditionType": "HasLine",
32
+ "target": "mainGrid",
33
+ "sequence": [
34
+ {
35
+ "minCount": 3,
36
+ "conditions": [{
37
+ "conditionType": "ContainsSame",
38
+ "properties": ["player"]
39
+ }]
40
+ }
41
+ ]
42
+ }],
43
+ "result": { "winner": "ownerOfFirstResultEntity" }
44
+ },
45
+ {
46
+ "conditions": [{
47
+ "conditionType": "IsFull",
48
+ "target": "mainGrid"
49
+ }],
50
+ "result": { "draw": true }
51
+ }
52
+ ]
53
+ }