Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DS, 3DS, (S)NES, N64, GameCube, and Switch button profiles #375

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/json-schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
git add config.matchmode.schema.json
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git diff-index --quiet HEAD || { echo 'Please update the json schemas by running `dotnet run -- regenjsonschemas`'; exit 1; }
git diff-index --quiet HEAD || { echo 'The configuration schema has changed. Please update the json schema files by running `dotnet run -- regenjsonschemas` locally and committing the output.'; exit 1; }
67 changes: 63 additions & 4 deletions TPP.Core/ButtonProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ public enum ButtonProfile
{
[EnumMember(Value = "gb")] GameBoy,
[EnumMember(Value = "gba")] GameBoyAdvance,
[EnumMember(Value = "nds")] NintendoDS,
[EnumMember(Value = "3ds")] Nintendo3DS,

[EnumMember(Value = "nes")] NES,
[EnumMember(Value = "snes")] SNES,
[EnumMember(Value = "n64")] N64,
[EnumMember(Value = "gc")] GameCube,
[EnumMember(Value = "switch")] Switch,

[EnumMember(Value = "dualgb")] DualGameBoy,
[EnumMember(Value = "dualnes")] DualNES,
[EnumMember(Value = "dualsnes")] DualSNES,
[EnumMember(Value = "dualn64")] DualN64,
[EnumMember(Value = "dualgc")] DualGameCube,
}

public static class ButtonProfileExtensions
Expand All @@ -19,14 +32,60 @@ public static InputParserBuilder ToInputParserBuilder(this ButtonProfile profile
ButtonProfile.GameBoy => InputParserBuilder.FromBare()
.Buttons("a", "b", "start", "select")
.DPad()
.RemappedDPad(up: "n", down: "s", left: "w", right: "e", mapsToPrefix: "")
.RemappedDPad(up: "north", down: "south", left: "west", right: "east", mapsToPrefix: "")
.LengthRestrictions(maxSetLength: 2, maxSequenceLength: 1)
.HoldEnabled(true),
// Max set length of 3 is too short to perform Soft Reset (A+B+Start+Select)
.LengthRestrictions(maxSetLength: 3, maxSequenceLength: 1),
ButtonProfile.GameBoyAdvance => ButtonProfile.GameBoy.ToInputParserBuilder()
.Buttons("l", "r"),
ButtonProfile.NintendoDS => ButtonProfile.SNES.ToInputParserBuilder()
.Touchscreen(width: 256, height: 192, multitouch: false, allowDrag: true),
ButtonProfile.Nintendo3DS => ButtonProfile.SNES.ToInputParserBuilder()
.SimpleAliasedDPad("d", "")
.AnalogStick("c", true)
.Touchscreen(width: 320, height: 240, multitouch: false, allowDrag: true)
// Prevent Soft Reset in 3DS Pokemon Games (L+R+Start/Select) as well as Luma3DS and NTR menu shortcuts
.Conflicts(("l", "select"), ("l", "start")),

ButtonProfile.NES => ButtonProfile.GameBoy.ToInputParserBuilder(),
ButtonProfile.SNES => ButtonProfile.GameBoyAdvance.ToInputParserBuilder()
.Buttons("x", "y"),
ButtonProfile.N64 => InputParserBuilder.FromBare()
.Buttons("a", "b", "start", "l", "r", "z")
.DPad()
.SimpleAliasedDPad("d", "")
.DPad("c")
.AnalogStick("a", true)
.SimpleAliasedAnalogStick("l", "a", true)
.LengthRestrictions(maxSetLength: 4, maxSequenceLength: 1),
ButtonProfile.GameCube => InputParserBuilder.FromBare()
.Buttons("a", "b", "x", "y", "l", "r", "z", "start")
.AliasedButtons(("pause", "start"))
.DPad()
.SimpleAliasedDPad("d", "")
.AnalogStick("l", true)
.AnalogStick("r", true)
.SimpleAliasedAnalogStick("c", "r", true)
.Conflicts(("x", "start")) // Prevent Soft Reset in Pokemon XD (B+X+Start)
.LengthRestrictions(maxSetLength: 4, maxSequenceLength: 1),
ButtonProfile.Switch => InputParserBuilder.FromBare()
.Buttons("a", "b", "x", "y", "l", "r", "zl", "zr", "lstick", "rstick", "plus", "minus") // Capture and Home buttons omitted on purpose
.AliasedButtons(("start", "plus"), ("select", "minus"), ("+", "plus"), ("-", "minus"), ("l2", "zl"), ("r2", "zr"), ("l3", "lstick"), ("r3", "rstick"))
.DPad()
.SimpleAliasedDPad("d", "")
.AnalogStick("l", true)
.AnalogStick("r", true)
.SimpleAliasedAnalogStick("c", "r", true)
.LengthRestrictions(maxSetLength: 4, maxSequenceLength: 1),

ButtonProfile.DualGameBoy => ButtonProfile.GameBoy.ToInputParserBuilder()
.LeftRightSidesEnabled(true),
ButtonProfile.DualNES => ButtonProfile.NES.ToInputParserBuilder()
.LeftRightSidesEnabled(true),
ButtonProfile.DualSNES => ButtonProfile.SNES.ToInputParserBuilder()
.LeftRightSidesEnabled(true),
ButtonProfile.DualN64 => ButtonProfile.DualN64.ToInputParserBuilder()
.LeftRightSidesEnabled(true),
ButtonProfile.DualGameCube => ButtonProfile.GameCube.ToInputParserBuilder()
.LeftRightSidesEnabled(true),
};
}
}
13 changes: 12 additions & 1 deletion TPP.Core/config.runmode.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
"enum": [
"gb",
"gba",
"dualgb"
"nds",
"3ds",
"nes",
"snes",
"n64",
"gc",
"switch",
"dualgb",
"dualnes",
"dualsnes",
"dualn64",
"dualgc"
]
},
"FramesPerSecond": {
Expand Down
74 changes: 72 additions & 2 deletions TPP.Inputting/InputParserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,26 @@ public InputParserBuilder AnalogStick(string prefix, bool allowSpin)
Conflicts((spinl, up), (spinl, down), (spinl, left), (spinl, right));
Conflicts((spinr, up), (spinr, down), (spinr, left), (spinr, right));
}
return this;
return this.CardinalAnalogStickMapping(prefix);
}

/// <summary>
/// Adds an aliased analog stick, automatically building a stick for an aliased prefix
/// </summary>
/// <param name="aliasPrefix">prefix for the aliased analog stick</param>
/// <param name="mapsToPrefix">prefix for the analog stick that the alias names map to</param>
/// <param name="allowSpin">if enabled, additional prefixed "spinl" and "spinr" buttons are added</param>
public InputParserBuilder SimpleAliasedAnalogStick(string aliasPrefix, string mapsToPrefix, bool allowSpin) =>
AliasedAnalogStick(
up: aliasPrefix + "up",
down: aliasPrefix + "down",
left: aliasPrefix + "left",
right: aliasPrefix + "right",
spinl: allowSpin ? aliasPrefix + "spinl" : null,
spinr: allowSpin ? aliasPrefix + "spinr" : null,
mapsToPrefix
).CardinalAnalogStickAliases(aliasPrefix, mapsToPrefix);

/// <summary>
/// Adds an aliased analog stick. This is a shortcut for adding aliased analog inputs for
/// "up"/"down"/"left"/"right", plus configuring respective conflicts, like inputting opposing directions.
Expand Down Expand Up @@ -321,6 +338,7 @@ public InputParserBuilder RemappedAnalogStick(
/// <summary>
/// Add a D-pad. This is a shortcut for adding buttons for "up"/"down"/"left"/"right",
/// plus configuring respective conflicts, like inputting opposing directions.
/// Also automatically adds N E W S and North East West South remappings for the pad.
/// </summary>
/// <param name="prefix">prefix for the D-pad, which will get prepended to "up"/"down"/"left"/"right"</param>
public InputParserBuilder DPad(string prefix = "")
Expand All @@ -331,9 +349,23 @@ public InputParserBuilder DPad(string prefix = "")
string right = prefix + "right";
Buttons(up, down, left, right);
Conflicts((up, down), (left, right));
return this;
return this.CardinalDPadMapping(prefix);
}

/// <summary>
/// Adds an aliased D-pad, automatically building up/down/left/right buttons for an aliased prefix
/// </summary>
/// <param name="aliasPrefix">prefix for the aliased D-pad</param>
/// <param name="mapsToPrefix">prefix for the D-pad that the alias names map to</param>
public InputParserBuilder SimpleAliasedDPad(string aliasPrefix, string mapsToPrefix) =>
AliasedDPad(
up: aliasPrefix + "up",
down: aliasPrefix + "down",
left: aliasPrefix + "left",
right: aliasPrefix + "right",
mapsToPrefix
).CardinalDPadAliases(aliasPrefix, mapsToPrefix);

/// <summary>
/// Add an aliased D-pad. This is a shortcut for adding aliased buttons for "up"/"down"/"left"/"right",
/// plus configuring respective conflicts, like inputting opposing directions.
Expand Down Expand Up @@ -376,6 +408,44 @@ public InputParserBuilder RemappedDPad(string up, string down, string left, stri
return this;
}

/// <summary>
/// Add N E W S and North East West South remapped D-pad.
/// </summary>
/// <param name="prefix">prefix for the D-pad that the remapping names map to,
/// which will get prepended to "n"/"s"/"w"/"e"</param>
public InputParserBuilder CardinalDPadMapping(string prefix) =>
RemappedDPad(up: prefix + "n", down: prefix + "s", left: prefix + "w", right: prefix + "e", prefix)
.RemappedDPad(up: prefix + "north", down: prefix + "south", left: prefix + "west", right: prefix + "east", prefix);

/// <summary>
/// Add N E W S and North East West South remapped Analog Stick.
/// </summary>
/// <param name="prefix">prefix for the stick that the remapping names map to,
/// which will get prepended to "n"/"s"/"w"/"e"</param>
public InputParserBuilder CardinalAnalogStickMapping(string prefix) =>
RemappedAnalogStick(up: prefix + "n", down: prefix + "s", left: prefix + "w", right: prefix + "e", spinl: null, spinr: null, prefix)
.RemappedAnalogStick(up: prefix + "north", down: prefix + "south", left: prefix + "west", right: prefix + "east", spinl: null, spinr: null, prefix);

/// <summary>
/// Add N E W S and North East West South D-pad aliases.
/// </summary>
/// <param name="prefix">prefix for the aliased D-pad,
/// <param name="mapsToPrefix">prefix that the aliased D-pad maps to</param>
public InputParserBuilder CardinalDPadAliases(string prefix, string mapsToPrefix) =>
AliasedDPad(up: prefix + "n", down: prefix + "s", left: prefix + "w", right: prefix + "e", mapsToPrefix)
.AliasedDPad(up: prefix + "north", down: prefix + "south", left: prefix + "west", right: prefix + "east", mapsToPrefix);


/// <summary>
/// Add N E W S and North East West South Analog Stick aliases.
/// </summary>
/// <param name="prefix">prefix for the aliased stick,
/// <param name="mapsToPrefix">prefix that the aliased stick maps to</param>
public InputParserBuilder CardinalAnalogStickAliases(string prefix, string mapsToPrefix) =>
AliasedAnalogStick(up: prefix + "n", down: prefix + "s", left: prefix + "w", right: prefix + "e", spinl: null, spinr: null, mapsToPrefix)
.AliasedAnalogStick(up: prefix + "north", down: prefix + "south", left: prefix + "west", right: prefix + "east", spinl: null, spinr: null, mapsToPrefix);


public InputParserBuilder LeftRightSidesEnabled(bool enabled)
{
_leftRightSides = enabled;
Expand Down
Loading
Loading