Skip to content

Commit ba7a90a

Browse files
committed
v0.2.2
1 parent 7d69077 commit ba7a90a

10 files changed

Lines changed: 177 additions & 169 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-hex-engine",
33
"description": "Hexagon Map Editor and Game Engine",
4-
"version": "0.2.1",
4+
"version": "0.2.2",
55
"main": "lib/index.js",
66
"author": "IcculusC",
77
"repository": "IcculusC/react-hex-engine",

src/Hexagon.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Hexagon extends Component {
1212
children: PropTypes.node,
1313
classes: PropTypes.objectOf(PropTypes.any),
1414
data: PropTypes.object,
15+
hoverable: PropTypes.bool,
1516
highlighted: PropTypes.bool,
1617
layout: PropTypes.objectOf(PropTypes.any).isRequired,
1718
onClick: PropTypes.func,
@@ -26,14 +27,14 @@ class Hexagon extends Component {
2627
q: PropTypes.number.isRequired,
2728
r: PropTypes.number.isRequired,
2829
s: PropTypes.number.isRequired,
30+
selectable: PropTypes.bool,
2931
selected: PropTypes.bool,
3032
showCoordinates: PropTypes.bool,
3133
text: PropTypes.string,
3234
TextProps: PropTypes.objectOf(PropTypes.any)
3335
};
3436

3537
static defaultProps = {
36-
className: "",
3738
classes: {
3839
group: "",
3940
hexagon: "",
@@ -46,6 +47,8 @@ class Hexagon extends Component {
4647
selected: "",
4748
text: ""
4849
},
50+
hoverable: true,
51+
selectable: true,
4952
showCoordinates: false,
5053
text: "",
5154
TextProps: {}
@@ -157,11 +160,13 @@ class Hexagon extends Component {
157160
const {
158161
classes,
159162
highlighted,
163+
hoverable,
160164
layout,
161165
points,
162166
q,
163167
r,
164168
s,
169+
selectable,
165170
selected,
166171
showCoordinates,
167172
text,
@@ -199,15 +204,15 @@ class Hexagon extends Component {
199204
>
200205
<g
201206
className={classNames("hexagon", classes.hexagon, {
202-
[classes.selected]: selected,
207+
[classes.selected]: selectable && selected,
203208
[classes.highlighted]: highlighted,
204-
[classes.hovered]: hovered
209+
[classes.hovered]: hoverable && hovered
205210
})}
206211
>
207212
<polygon className={classes.polygon} points={points} />
208213
{this.props.children}
209214
{text ? (
210-
<Text className={classes.text} {...TextProps}>
215+
<Text classes={{ text: classes.text }} {...TextProps}>
211216
{text}
212217
</Text>
213218
) : null}

src/Layout.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
3-
import classNames from "classnames";
43
import memoize from "memoize-one";
54
import Hex from "./models/Hex";
65
import HexUtils from "./HexUtils";
@@ -11,7 +10,6 @@ import { LayoutProvider, withViewBox } from "./Context";
1110
export class Layout extends Component {
1211
static propTypes = {
1312
children: PropTypes.node.isRequired,
14-
className: PropTypes.string,
1513
classes: PropTypes.objectOf(PropTypes.string),
1614
flat: PropTypes.bool,
1715
origin: PropTypes.object,
@@ -84,15 +82,7 @@ export class Layout extends Component {
8482
});
8583

8684
render() {
87-
const {
88-
flat,
89-
children,
90-
classes,
91-
className,
92-
size,
93-
viewBox,
94-
...rest
95-
} = this.props;
85+
const { flat, children, classes, size, viewBox, ...rest } = this.props;
9686
const orientation = flat ? Orientation.Flat : Orientation.Pointy;
9787
const points = Layout.calculateCoordinates(orientation, size)
9888
.map(point => point.toString())
@@ -101,7 +91,7 @@ export class Layout extends Component {
10191
const inBounds = this.filterChildren(children, layout, viewBox);
10292
return (
10393
<LayoutProvider value={{ layout, points }}>
104-
<g className={classNames(className, classes.layout)}>{inBounds}</g>
94+
<g className={classes.layout}>{inBounds}</g>
10595
</LayoutProvider>
10696
);
10797
}

src/Text.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
3-
import classNames from "classnames";
43

54
class Text extends Component {
65
static propTypes = {
76
anchor: PropTypes.string,
87
children: PropTypes.string,
9-
className: PropTypes.string,
108
classes: PropTypes.objectOf(PropTypes.string),
119
x: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1210
y: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
@@ -18,10 +16,10 @@ class Text extends Component {
1816
};
1917

2018
render() {
21-
const { anchor, children, className, classes, x, y } = this.props;
19+
const { anchor, children, classes, x, y } = this.props;
2220
return (
2321
<text
24-
className={classNames(className, classes.text)}
22+
className={classes.text}
2523
textAnchor={anchor}
2624
x={x || 0}
2725
y={y ? y : "0.3em"}

src/models/Hex.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
class Hex {
2-
constructor(q, r, s) {
2+
constructor(q, r, s, meta = {}) {
33
this.q = q;
44
this.r = r;
55
this.s = s;
6+
this.meta = {};
67
}
78

89
toString() {
@@ -11,13 +12,13 @@ class Hex {
1112
}
1213

1314
toJSON() {
14-
const { q, r, s } = this;
15-
return { q, r, s };
15+
const { meta, q, r, s } = this;
16+
return { meta, q, r, s };
1617
}
1718

1819
static fromJSON(obj) {
19-
const { q, r, s } = obj;
20-
return new Hex(q, r, s);
20+
const { meta, q, r, s } = obj;
21+
return new Hex(q, r, s, meta);
2122
}
2223
}
2324

test/src/GridGenerator.test.js

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,66 @@
1-
import GridGenerator from '../../src/GridGenerator';
1+
import GridGenerator from "../../src/GridGenerator";
22

3-
test('getGenerator should work when the request exists', () => {
4-
expect(GridGenerator.getGenerator('rectangle')).toBe(GridGenerator.rectangle);
3+
test("getGenerator should work when the request exists", () => {
4+
expect(GridGenerator.getGenerator("rectangle")).toBe(GridGenerator.rectangle);
55
});
66

7-
test('getGenerator should work when the request does not exist', () => {
8-
expect(GridGenerator.getGenerator('bogus')).toBeNull();
7+
test("getGenerator should work when the request does not exist", () => {
8+
expect(GridGenerator.getGenerator("bogus")).toBeNull();
99
});
1010

11-
test('parallelogram should work', () => {
12-
expect(GridGenerator.parallelogram(0, 1, 0, 1)).toEqual(
13-
[
14-
{ q: 0, r: 0, s: -0 },
15-
{ q: 0, r: 1, s: -1 },
16-
{ q: 1, r: 0, s: -1 },
17-
{ q: 1, r: 1, s: -2 },
18-
],
19-
);
11+
test("parallelogram should work", () => {
12+
expect(GridGenerator.parallelogram(0, 1, 0, 1)).toEqual([
13+
{ meta: {}, q: 0, r: 0, s: -0 },
14+
{ meta: {}, q: 0, r: 1, s: -1 },
15+
{ meta: {}, q: 1, r: 0, s: -1 },
16+
{ meta: {}, q: 1, r: 1, s: -2 }
17+
]);
2018
});
2119

22-
test('triangle should work', () => {
23-
expect(GridGenerator.triangle(1)).toEqual(
24-
[
25-
{ q: 0, r: 0, s: -0 },
26-
{ q: 0, r: 1, s: -1 },
27-
{ q: 1, r: 0, s: -1 },
28-
],
29-
);
20+
test("triangle should work", () => {
21+
expect(GridGenerator.triangle(1)).toEqual([
22+
{ meta: {}, q: 0, r: 0, s: -0 },
23+
{ meta: {}, q: 0, r: 1, s: -1 },
24+
{ meta: {}, q: 1, r: 0, s: -1 }
25+
]);
3026
});
3127

32-
test('hexagon should work', () => {
33-
expect(GridGenerator.hexagon(1)).toEqual(
34-
[
35-
{ q: -1, r: 0, s: 1 },
36-
{ q: -1, r: 1, s: 0 },
37-
{ q: 0, r: -1, s: 1 },
38-
{ q: 0, r: 0, s: -0 },
39-
{ q: 0, r: 1, s: -1 },
40-
{ q: 1, r: -1, s: 0 },
41-
{ q: 1, r: 0, s: -1 },
42-
],
43-
);
28+
test("hexagon should work", () => {
29+
expect(GridGenerator.hexagon(1)).toEqual([
30+
{ meta: {}, q: -1, r: 0, s: 1 },
31+
{ meta: {}, q: -1, r: 1, s: 0 },
32+
{ meta: {}, q: 0, r: -1, s: 1 },
33+
{ meta: {}, q: 0, r: 0, s: -0 },
34+
{ meta: {}, q: 0, r: 1, s: -1 },
35+
{ meta: {}, q: 1, r: -1, s: 0 },
36+
{ meta: {}, q: 1, r: 0, s: -1 }
37+
]);
4438
});
4539

46-
test('rectangle should work', () => {
47-
expect(GridGenerator.rectangle(3, 3)).toEqual(
48-
[
49-
{ q: -0, r: 0, s: 0 },
50-
{ q: 1, r: 0, s: -1 },
51-
{ q: 2, r: 0, s: -2 },
52-
{ q: -0, r: 1, s: -1 },
53-
{ q: 1, r: 1, s: -2 },
54-
{ q: 2, r: 1, s: -3 },
55-
{ q: -1, r: 2, s: -1 },
56-
{ q: 0, r: 2, s: -2 },
57-
{ q: 1, r: 2, s: -3 },
58-
],
59-
);
40+
test("rectangle should work", () => {
41+
expect(GridGenerator.rectangle(3, 3)).toEqual([
42+
{ meta: {}, q: -0, r: 0, s: 0 },
43+
{ meta: {}, q: 1, r: 0, s: -1 },
44+
{ meta: {}, q: 2, r: 0, s: -2 },
45+
{ meta: {}, q: -0, r: 1, s: -1 },
46+
{ meta: {}, q: 1, r: 1, s: -2 },
47+
{ meta: {}, q: 2, r: 1, s: -3 },
48+
{ meta: {}, q: -1, r: 2, s: -1 },
49+
{ meta: {}, q: 0, r: 2, s: -2 },
50+
{ meta: {}, q: 1, r: 2, s: -3 }
51+
]);
6052
});
6153

62-
test('orientedRectangle should work', () => {
63-
expect(GridGenerator.orientedRectangle(3, 3)).toEqual(
64-
[
65-
{ q: 0, r: -0, s: 0 },
66-
{ q: 0, r: 1, s: -1 },
67-
{ q: 0, r: 2, s: -2 },
68-
{ q: 1, r: -0, s: -1 },
69-
{ q: 1, r: 1, s: -2 },
70-
{ q: 1, r: 2, s: -3 },
71-
{ q: 2, r: -1, s: -1 },
72-
{ q: 2, r: 0, s: -2 },
73-
{ q: 2, r: 1, s: -3 },
74-
],
75-
);
54+
test("orientedRectangle should work", () => {
55+
expect(GridGenerator.orientedRectangle(3, 3)).toEqual([
56+
{ meta: {}, q: 0, r: -0, s: 0 },
57+
{ meta: {}, q: 0, r: 1, s: -1 },
58+
{ meta: {}, q: 0, r: 2, s: -2 },
59+
{ meta: {}, q: 1, r: -0, s: -1 },
60+
{ meta: {}, q: 1, r: 1, s: -2 },
61+
{ meta: {}, q: 1, r: 2, s: -3 },
62+
{ meta: {}, q: 2, r: -1, s: -1 },
63+
{ meta: {}, q: 2, r: 0, s: -2 },
64+
{ meta: {}, q: 2, r: 1, s: -3 }
65+
]);
7666
});

0 commit comments

Comments
 (0)