question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

understanding the run and hexes methods

See original GitHub issue

Hello @flauwekeul,

First, thank you for working on a new version of your library, it actually gave me the motivation to retake an old project. I know the v4 is still in early stage but you provided some examples and the traversers are very promising.

So, I have a grid manager where I instanciate a grid using this.grid = new Grid(...).each(hex => render(hex)).run(), no big deal it works perfectly. Then, I want to access some of the hexes to change some custom properties defined during render, so I use a traverser (I’ve made a circular traverser where you define a range from a center hex), then I do const hexes = this.grid.traverser(...).hexes(), the hexes are here but the first each method is called again, rendering my hexes a second time. const hexes = []; this.grid.traverser(...).each(hex => hexes.push(hex)).run() produces the same result.

I understand the idea of stateful grid and I feel like I should use a stateless grid for some operations, but then this.grid.getHex(coordinates) wont be available so I still need a stateful one, right?

Anyway, I have a lot of fun experimenting with it. Here are some fix/features that could really help me out:

  • hexagon grid shape (using a circular traverser by default?)
  • traversing out of store hexes should not mess with the path
  • A* algorithm with the ability to filter out the non traversable hexes

I know some of them are already in the backlog but you also asked for priorities so these are mine. I know you’re taking a new job so if I can contribute in a way, let me know!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
flauwekeulcommented, Apr 13, 2021

I just released alpha.4. It contains a ring() and spiral() traverser and I’ve tried to fix the duplicate hexes that chaining traversers caused. I’m looking forward to your opinion.

1reaction
mattsrinccommented, Apr 7, 2021

A* algorithm can be perfectly used from here:

https://github.com/bgrins/javascript-astar

with slight modification e.g.

Graph.prototype.neighbors = function(node) {
  var ret = [];
  var x = node.x;
  var y = node.y;
  var grid = this.grid;

  // West
  if (grid[x - 1] && grid[x - 1][y]) {
    ret.push(grid[x - 1][y]);
  }

  // East
  if (grid[x + 1] && grid[x + 1][y]) {
    ret.push(grid[x + 1][y]);
  }

  // South
  if (grid[x] && grid[x][y - 1]) {
    ret.push(grid[x][y - 1]);
  }

  // North
  if (grid[x] && grid[x][y + 1]) {
    ret.push(grid[x][y + 1]);
  }

// two cases added below
  // SouthEast
  if (grid[x+1] && grid[x+1][y - 1]) {
    ret.push(grid[x+1][y - 1]);
  }

  // NorthWest
  if (grid[x-1] && grid[x-1][y + 1]) {
    ret.push(grid[x-1][y + 1]);
  }

  if (this.diagonal) {

that you can manage quickly to use (diagonal movement checks below those displayed in the code above are non-relevant for a hex grid). And with the help of svg.js you can create pages like this (cannot share code, it was paid for):

pathfinding-javascript-console-cIds

We really should be grateful for the great library that cannot have all what we need - but it’s getting close!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run a Hex Crawl? : r/osr - Reddit
I understand how to run a point craw, but the moment by moment of a hexcrawl alludes me. Is it as simple as...
Read more >
Hexcrawl - The Alexandrian
(1) Draw a hexmap. In general, the terrain of each hex is given as a visual reference and the hex is numbered (either...
Read more >
How to run a hex crawl, with Bill Webb - YouTube
The " Hex Crawl" is a classic type of D&D adventure that isn't really described as a "type" anywhere, except in very sparse...
Read more >
Hex-based Campaign Design (Part 1) | The Welsh Piper
Assign a terrain type of your choosing to the sub-hex at the centre of the atlas hex. This defines the atlas hex's primary...
Read more >
3 Hexes To Use When You Need To Make Your Stand
Going counterclockwise, light each candle. Now, this is important. To perform this curse, you must be angry. Focus. Let your anger build to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found