• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mapping entire classes of enums

 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to build an hardware interface device that sits between
two game controllers and maps controller buttons based on which
game is to be played. So the device will run some java app where
I've statically coded all the mappings. There's one mapping for
each controller (EnumTGC and EnumPGC) and multiple
controller:controller mappings. Also, multiple games can use the
same controller:controller mapping but one game can only use one
controller:controller mapping. So....

so far so good. but here I run into trouble

when combined with the executable


Does that make sense? Overall idea here is the user will select which game is to be played
(hardcoded here to shrink the problem) and the associated controller:controller mapping gets used.

As always, all help/suggestions/advice/constructive criticism are all welcome,

TIA,

Still-learning Steve
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stuart,

Maybe the following example is useful for you. I have replaced EnumTGC and EnumPGC with interfaces with the more descriptive names Command and Button.

The point is that eventually all your games should care about is some mapping from Buttons to Commands. We can use the following type for this:
If your game detects that a certain button is pushed, it can easily look up the associated command like so:
Here's how it would look:
 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Genius! I thought the EnumMap might be of help but have not worked with it before. I'll give it a try.

Thanks for your help!!

CASE CLOSED

Still-learning Steve
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you're programming to an interface, so it doesn't really matter whether you use a HashMap or an EnumMap. EnumMaps are just slightly more efficient than HashMaps are.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic