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.

add move range for token

See original GitHub issue

I am adding move range for token, I suppose it is a common function for hex grid game. here is how it look like move range

for now, I just simply put the highlight and range calculation methods in hex. Before I wanna submit PR, I found there must be a activeId alike props to indicate which token is currently selected when it comes multi-token… I was struggling with the multi-token things.

My thought is manage the activeToken id state in hex state, add selectToken methods as follow, but I am not sure how to update activeToken id immediately.

_selectToken(target) {
   let tokens = this.props.children, index = 0;
   const coordinate = `${target.x},${target.y},${target.z}`;
   if(Array.isArray(tokens)) {
     tokens.forEach((token) => {
       const {x, y, z} = token.props;
       console.warn(`multi token, curToken xyz: ${x}, ${y}, ${z}, clicked@:${coordinate}`);
       if (x === target.x && y === target.y && z === target.z)
         this.setState({ activeId: index });
       index += 1;
     });
     // because setState is async.. activeId would be updated @nextClicked..
     console.warn(`activeToken id: ${this.state.activeId}`);
     return tokens[this.state.activeId];
   } else {
       // handle single token..
   }
}

I am not experienced in React…Any suggestion @nicolodavis , thx !

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jstacodercommented, Mar 19, 2018

setState can also take a function As its second argument, and you are guaranteed this function will not be called until after the state update happens, I think that’s what your looking for?

0reactions
nicolodaviscommented, May 29, 2018

Closing this for lack of activity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

add move range for token · Issue #156 - GitHub
I am adding move range for token, I suppose it is a common function for hex grid game. here is how it look...
Read more >
Token movement limits? : r/Roll20 - Reddit
If you just want to have a reminder of movement range, you could just add an aura of the appropriate size to the...
Read more >
Adding, replacing, moving and removing nodes
Adding new nodes is called "bootstrapping". The num_tokens parameter will define the amount of virtual nodes (tokens) the joining node will be assigned ......
Read more >
FG Academy Presents: FGU Token Movement - YouTube
Fantasy Grounds Unity Token Movement : Controlling the movement of players and NPC's as the host.We now have live streaming simultaneously ...
Read more >
Adding or replacing single-token nodes | Apache Cassandra 2.2
Existing nodes can keep their existing token assignments, and new nodes are assigned tokens that bisect (or trisect) the existing token ranges.
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