hexkit

Hex Kit is a desktop application built on modern webapp technologies: React, Redux, and Electron. Hex Kit has it's own internal API (Redux actions) that can be used by 3rd-party plugins. With a little Javascript, new functionality (custom painting tools, generators, etc) can be added to Hex Kit.

Usage no npm install needed!

<script type="module">
  import hexkit from 'https://cdn.skypack.dev/hexkit';
</script>

README

Introduction

Hex Kit is a desktop application built on modern webapp technologies: React, Redux, and Electron. Hex Kit has it's own internal API (Redux actions) that can be used by 3rd-party plugins. With a little Javascript, new functionality (custom painting tools, generators, etc) can be added to Hex Kit.

Tiles

Hex Kit uses a URI scheme to define tiles and tilesets. The schema of the URI is the name of tileset, and the subsequent path can point to a specific file or folder in the directory structure of the tileset, i.e.:

HK-Fantasyland://HK - Wasteland/

or:

HK-Fantasyland://HK - Grass/HK_grass_003.png

The former will randomly paint from all tiles in the HK - Wasteland folder, while the latter will specifically paint the HK_grass_003.png tile.

Coordinates

Hex Kit uses the offset coordinate system to designate the location of tiles. Starting in the top-left corner, the tile is designated by it's row and column. The coordinate values increase as the location moves right and downward. Red Blob Games has an execellent tutorial on the ins-and-outs of hexagon math.

0,0   0,1   0,2
   1,0   1,1   1,2
2,0   2,1   2,2   

Installing the API

The Hex Kit API library is available to be installed via NPM.

npm add hex-kit

Calling the API

Hex Kit uses the Redux action pattern for making changes to the map. First, you'll want to create a "store" to send actions to:

import { createStore } from 'hexkit'

let store = createStore()

Then to paint a new tile, you want to dispatch an action via the paintTiles method:

import { paintTiles } from 'hex-kit'

store.dispatch(paintTiles([{
    coord: { x: 0, y: 0 },
    layer: 0,
    uri: 'HK-Fantasyland://HK - Wasteland/'
}])

Observing the App

The app state is inspectable as well. Use the 'getState' member of the store to get a snapshot of the current map and state of the app.

let state = store.getState()

console.log(state.map.layers[0].tiles[0])

The Redux store is often automatically relayed to a React app, like so:

import { createStore } from 'hex-kit'
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { connect } from 'react-redux' 

let store = createStore()

class MyPluginComponent extends React.Component {
    render() {
        return <div>
            The first tile's URI is {state.map.layers[0].tiles[0].source}
        </div>
    }
}

let MyPlugin = connect(state => state)(MyPluginComponent)

ReactDOM.render(
    <Provider store={store}><MyPlugin /><Provider>,
    document.getElementById('myplugin'))