Hello,
I am using an enum called InputCommands to represent input commands in my game independent of the actual keys used as shown below:
public enum InputCommands
{
Accept,
Cancel,
ChangeStorageDevice,
Remove,
MoveLeft,
MoveRight,
MoveDown,
MoveUp,
OpenInGameMenu,
OpenTitleMenu,
Pause,
}
I added an XML file to the content pipeline that lists what keyboard or game pad commands correlate to the InputCommands. This allows changing the keys used without editing their implementation in the rest of the solution. It also allows the user to save custom commands (even though I don't currently implement this in the game).
<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Generic="System.Collections.Generic" xmlns:Input="GameDataTypes">
<Asset Type="Generic:Dictionary[GameUtilities.Input.InputCommands,GameUtilities.Input.KeyList]">
<Item>
<Key>Accept</Key>
<Value>
<KeyboardKeys>
<Item>LeftControl</Item>
<Item>RightControl</Item>
</KeyboardKeys>
<GamePadButtons>
<Item>A</Item>
</GamePadButtons>
</Value>
</Item>
<Item>
<Key>Cancel</Key>
<Value>
<KeyboardKeys>
<Item>LeftShift</Item>
<Item>RightShift</Item>
<Item>Escape</Item>
</KeyboardKeys>
<GamePadButtons>
<Item>B</Item>
</GamePadButtons>
</Value>
</Item>
</Asset>
</XnaContent>
I have a separate project, GameUtilities that contains game code that I reuse between games. One of the classes is InputLibrary that consumes input commands from the game using the InputCommand enum and the InputCommand.xml file.
The problem is, each game will probably have a different InputCommand enum for acceptable commands. Since the main game project has to reference the GameUtilities project, I cannot put InputCommand in the main game project like I would like. I could put InputCommand in a third project that both the main game and the GameUtilities reference, but I would rather the GameUtilities class not have to reference a class that will change between games.
The solution I think is to use strings in the game to represent each game command, but then I lose the IDE benefits of using enum (Auto completion, auto finding all uses, error checking when compiling).
I was hoping someone with some more experience than myself would have a better solution, or am I stuck either making the GameUtilities project dependent on another project or using strings instead of an enum?
-Brett