some bk2 code cleanup

This commit is contained in:
adelikat 2017-05-17 11:53:42 -05:00
parent dfea029fe4
commit e930dd3326
5 changed files with 323 additions and 356 deletions

View File

@ -10,11 +10,11 @@ namespace BizHawk.Client.Common
public class Bk2ControllerAdapter : IMovieController
{
private readonly string _logKey = "";
private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> MyFloatControls = new WorkingDictionary<string, float>();
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>();
public Bk2ControllerAdapter()
{
{
}
public Bk2ControllerAdapter(string key)
@ -41,14 +41,14 @@ namespace BizHawk.Client.Common
{
get
{
return MyBoolButtons[button];
return _myBoolButtons[button];
}
set
{
if (MyBoolButtons.ContainsKey(button))
if (_myBoolButtons.ContainsKey(button))
{
MyBoolButtons[button] = value;
_myBoolButtons[button] = value;
}
}
}
@ -57,12 +57,12 @@ namespace BizHawk.Client.Common
public bool IsPressed(string button)
{
return MyBoolButtons[button];
return _myBoolButtons[button];
}
public float GetFloat(string name)
{
return MyFloatControls[name];
return _myFloatControls[name];
}
#endregion
@ -104,7 +104,7 @@ namespace BizHawk.Client.Common
}
var val = playerSource.IsPressed(button);
MyBoolButtons[button] = val;
_myBoolButtons[button] = val;
}
foreach (var button in Definition.FloatControls)
@ -122,7 +122,7 @@ namespace BizHawk.Client.Common
var val = playerSource.GetFloat(button);
MyFloatControls[button] = val;
_myFloatControls[button] = val;
}
}
@ -133,12 +133,12 @@ namespace BizHawk.Client.Common
{
foreach (var button in Definition.BoolButtons)
{
MyBoolButtons[button] = source.IsPressed(button);
_myBoolButtons[button] = source.IsPressed(button);
}
foreach (var name in Definition.FloatControls)
{
MyFloatControls[name] = source.GetFloat(name);
_myFloatControls[name] = source.GetFloat(name);
}
}
@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
{
foreach (var button in Definition.BoolButtons)
{
MyBoolButtons[button] = Global.AutofireStickyXORAdapter.IsSticky(button);
_myBoolButtons[button] = Global.AutofireStickyXORAdapter.IsSticky(button);
}
}
@ -169,14 +169,14 @@ namespace BizHawk.Client.Common
{
if (def.BoolButtons.Contains(key))
{
MyBoolButtons[key] = trimmed[iterator] != '.';
_myBoolButtons[key] = trimmed[iterator] != '.';
iterator++;
}
else if (def.FloatControls.Contains(key))
{
var temp = trimmed.Substring(iterator, 5);
var val = int.Parse(temp.Trim());
MyFloatControls[key] = val;
_myFloatControls[key] = val;
iterator += 6;
}
@ -188,23 +188,21 @@ namespace BizHawk.Client.Common
public void SetFloat(string buttonName, float value)
{
MyFloatControls[buttonName] = value;
_myFloatControls[buttonName] = value;
}
public class Bk2ControllerDefinition : ControllerDefinition
{
public Bk2ControllerDefinition()
{
}
public Bk2ControllerDefinition(ControllerDefinition source)
: base(source)
{
}
public List<List<string>> ControlsFromLog = new List<List<string>>();
public List<List<string>> ControlsFromLog { private get; set; } = new List<List<string>>();
public override IEnumerable<IEnumerable<string>> ControlsOrdered
{

View File

@ -30,34 +30,34 @@ namespace BizHawk.Client.Common
}
private readonly Dictionary<string, string> BaseMnemonicLookupTable = new Dictionary<string, string>
{
{ "Zapper X", "zapX" },
{ "Zapper Y", "zapY" },
{ "Paddle", "Pad" },
{ "Pen", "Pen" },
{ "Mouse X", "mX" },
{ "Mouse Y", "mY" },
{ "Lightgun X", "lX" },
{ "Lightgun Y", "lY" },
{ "X Axis", "aX" },
{ "Y Axis", "aY" },
{ "LStick X", "lsX" },
{ "LStick Y", "lsY" },
{ "RStick X", "rsX" },
{ "RStick Y", "rsY" },
{ "Disc Select", "Disc" }
};
{
{ "Zapper X", "zapX" },
{ "Zapper Y", "zapY" },
{ "Paddle", "Pad" },
{ "Pen", "Pen" },
{ "Mouse X", "mX" },
{ "Mouse Y", "mY" },
{ "Lightgun X", "lX" },
{ "Lightgun Y", "lY" },
{ "X Axis", "aX" },
{ "Y Axis", "aY" },
{ "LStick X", "lsX" },
{ "LStick Y", "lsY" },
{ "RStick X", "rsX" },
{ "RStick Y", "rsY" },
{ "Disc Select", "Disc" }
};
private readonly Dictionary<string, Dictionary<string, string>> SystemOverrides = new Dictionary<string, Dictionary<string, string>>
{
{
"A78",
new Dictionary<string, string>
{
"A78",
new Dictionary<string, string>
{
{ "VPos", "X" },
{ "HPos", "Y" }
}
},
};
{ "VPos", "X" },
{ "HPos", "Y" }
}
},
};
}
}

View File

@ -11,8 +11,8 @@ namespace BizHawk.Client.Common
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
private readonly Bk2FloatConstants FloatLookup = new Bk2FloatConstants();
private readonly string _logKey;
private IController _source;
private readonly string _logKey = "";
public Bk2LogEntryGenerator(string logKey)
{

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
// ReSharper disable StyleCop.SA1509
namespace BizHawk.Client.Common
{
public class Bk2MnemonicConstants
@ -14,14 +15,14 @@ namespace BizHawk.Client.Common
key = key.Substring(3);
}
if (SystemOverrides.ContainsKey(Global.Emulator.SystemId) && SystemOverrides[Global.Emulator.SystemId].ContainsKey(key))
if (_systemOverrides.ContainsKey(Global.Emulator.SystemId) && _systemOverrides[Global.Emulator.SystemId].ContainsKey(key))
{
return SystemOverrides[Global.Emulator.SystemId][key];
return _systemOverrides[Global.Emulator.SystemId][key];
}
if (BaseMnemonicLookupTable.ContainsKey(key))
if (_baseMnemonicLookupTable.ContainsKey(key))
{
return BaseMnemonicLookupTable[key];
return _baseMnemonicLookupTable[key];
}
if (key.Length == 1)
@ -33,336 +34,304 @@ namespace BizHawk.Client.Common
}
}
private readonly Dictionary<string, char> BaseMnemonicLookupTable = new Dictionary<string, char>
{
{ "Power", 'P' },
{ "Reset", 'r' },
{ "Pause", 'p' },
{ "Rotate", 'R' },
private readonly Dictionary<string, char> _baseMnemonicLookupTable = new Dictionary<string, char>
{
["Power"] = 'P',
["Reset"] = 'r',
["Pause"] = 'p',
["Rotate"] = 'R',
{ "Up", 'U' },
{ "Down", 'D' },
{ "Left", 'L' },
{ "Right", 'R' },
["Up"] = 'U',
["Down"] = 'D',
["Left"] = 'L',
["Right"] = 'R',
{ "A", 'A' },
{ "B", 'B' },
{ "C", 'C' },
["A"] = 'A',
["B"] = 'B',
["C"] = 'C',
{ "X", 'X' },
{ "Y", 'Y' },
{ "Z", 'Z' },
["X"] = 'X',
["Y"] = 'Y',
["Z"] = 'Z',
{ "Select", 's' },
{ "Start", 'S' },
{ "Run", 'R' },
["Select"] = 's',
["Start"] = 'S',
["Run"] = 'R',
{ "L", 'l' },
{ "R", 'r' },
["L"] = 'l',
["R"] = 'r',
{ "L1", 'l' },
{ "R1", 'r' },
["L1"] = 'l',
["R1"] = 'r',
{ "L2", 'L' },
{ "R2", 'R' },
["L2"] = 'L',
["R2"] = 'R',
{ "L3", '<' },
{ "R3", '>' },
["L3"] = '<',
["R3"] = '>',
{ "Button", 'B' },
{ "B1", '1' },
{ "B2", '2' },
["Button"] = 'B',
["B1"] = '1',
["B2"] = '2',
{ "Trigger", '1' },
{ "Trigger 1", '1' },
{ "Trigger 2", '2' },
["Trigger"] = '1',
["Trigger 1"] = '1',
["Trigger 2"] = '2',
{ "Mouse Left", 'l' },
{ "Mouse Right", 'r' },
{ "Mouse Center", 'c' },
{ "Mouse Start", 's' },
["Mouse Left"] = 'l',
["Mouse Right"] = 'r',
["Mouse Center"] = 'c',
["Mouse Start"] = 's',
{ "Mode", 'M' },
{ "MODE", 'M' },
["Mode"] = 'M',
["MODE"] = 'M',
{ "Fire", 'F' },
{ "Lightgun Trigger", 'T' },
{ "Lightgun Start", 'S' },
{ "Lightgun B", 'B' },
{ "Lightgun C", 'C' },
{ "Microphone", 'M' },
["Fire"] = 'F',
["Lightgun Trigger"] = 'T',
["Lightgun Start"] = 'S',
["Lightgun B"] = 'B',
["Lightgun C"] = 'C',
["Microphone"] = 'M',
{ "Star", '*' },
{ "Pound", '#' },
["Star"] = '*',
["Pound"] = '#',
{ "X1", '1' },
{ "X2", '2' },
{ "X3", '3' },
{ "X4", '4' },
["X1"] = '1',
["X2"] = '2',
["X3"] = '3',
["X4"] = '4',
{ "Y1", '1' },
{ "Y2", '2' },
{ "Y3", '3' },
{ "Y4", '4' },
["Y1"] = '1',
["Y2"] = '2',
["Y3"] = '3',
["Y4"] = '4',
{ "Triangle", 'T' },
{ "Circle", 'O' },
{ "Cross", 'X' },
{ "Square", 'Q' },
["Triangle"] = 'T',
["Circle"] = 'O',
["Cross"] = 'X',
["Square"] = 'Q',
{ "Toggle Left Difficulty", 'l' },
{ "Toggle Right Difficulty", 'r' },
["Toggle Left Difficulty"] = 'l',
["Toggle Right Difficulty"] = 'r',
{ "Open", 'O' },
{ "Close", 'C' },
{ "Pedal", 'P' }
};
["Open"] = 'O',
["Close"] = 'C',
["Pedal"] = 'P'
};
private readonly Dictionary<string, Dictionary<string, char>> SystemOverrides = new Dictionary<string, Dictionary<string, char>>
private readonly Dictionary<string, Dictionary<string, char>> _systemOverrides = new Dictionary<string, Dictionary<string, char>>
{
["NES"] = new Dictionary<string, char>
{
{
"NES",
new Dictionary<string, char>
{
{ "FDS Eject", 'E' },
{ "FDS Insert 0", '0' },
{ "FDS Insert 1", '1' },
{ "Insert Coin P1", 'c' },
{ "Insert Coin P2", 'C' },
{ "Service Switch", 'w' },
["FDS Eject"] = 'E',
["FDS Insert 0"] = '0',
["FDS Insert 1"] = '1',
["Insert Coin P1"] = 'c',
["Insert Coin P2"] = 'C',
["Service Switch"] = 'w',
{ "PP1", '1' },
{ "PP2", '2' },
{ "PP3", '3' },
{ "PP4", '4' },
["PP1"] = '1',
["PP2"] = '2',
["PP3"] = '3',
["PP4"] = '4',
{ "PP5", '5' },
{ "PP6", '6' },
{ "PP7", '7' },
{ "PP8", '8' },
["PP5"] = '5',
["PP6"] = '6',
["PP7"] = '7',
["PP8"] = '8',
{ "PP9", '9' },
{ "PP10", 'A' },
{ "PP11", 'B' },
{ "PP12", 'C' },
{ "Click", 'C' },
{ "Touch", 'T' },
}
},
{
"SNES",
new Dictionary<string, char>
{
{ "Cursor", 'c' },
{ "Turbo", 't' },
{ "Toggle Multitap", 't' },
["PP9"] = '9',
["PP10"] = 'A',
["PP11"] = 'B',
["PP12"] = 'C',
["Click"] = 'C',
["Touch"] = 'T',
},
["SNES"] = new Dictionary<string, char>
{
["Cursor"] = 'c',
["Turbo"] = 't',
["Toggle Multitap"] = 't',
{ "B0", '0' },
{ "B1", '1' },
{ "B2", '2' },
{ "B3", '3' },
{ "B4", '4' },
{ "B5", '5' },
{ "B6", '6' },
{ "B7", '7' },
{ "B8", '8' },
{ "B9", '9' },
{ "B10", 'a' },
["B0"] = '0',
["B1"] = '1',
["B2"] = '2',
["B3"] = '3',
["B4"] = '4',
["B5"] = '5',
["B6"] = '6',
["B7"] = '7',
["B8"] = '8',
["B9"] = '9',
["B10"] = 'a',
["B11"] = 'b',
["B12"] = 'c',
["B13"] = 'd',
["B14"] = 'e',
["B15"] = 'f',
["B16"] = 'g',
["B17"] = 'h',
["B18"] = 'i',
["B19"] = 'j',
["B20"] = 'k',
["B21"] = 'l',
["B22"] = 'm',
["B23"] = 'n',
["B24"] = 'o',
["B25"] = 'p',
["B26"] = 'q',
["B27"] = 'r',
["B28"] = 's',
["B29"] = 't',
["B30"] = 'u',
["B31"] = 'v'
},
["TI83"] = new Dictionary<string, char>
{
["UP"] = 'U',
["DOWN"] = 'D',
["LEFT"] = 'L',
["RIGHT"] = 'R',
["DOT"] = '`',
["ON"] = 'O',
["ENTER"] = '=',
["PLUS"] = '+',
["MINUS"] = '_',
["MULTIPLY"] = '*',
["DIVIDE"] = '/',
["CLEAR"] = 'c',
["EXP"] = '^',
["DASH"] = '-',
["PARAOPEN"] = '(',
["PARACLOSE"] = ')',
["TAN"] = 'T',
["VARS"] = 'V',
["COS"] = 'C',
["PRGM"] = 'P',
["STAT"] = 's',
["MATRIX"] = 'm',
["X"] = 'X',
["STO"] = '>',
["LN"] = 'n',
["LOG"] = 'L',
["SQUARED"] = '2',
["NEG1"] = '1',
["MATH"] = 'H',
["ALPHA"] = 'A',
["GRAPH"] = 'G',
["TRACE"] = 't',
["ZOOM"] = 'Z',
["WINDOW"] = 'W',
["Y"] = 'Y',
["2ND"] = '&',
["MODE"] = 'O',
["DEL"] = 'D',
["COMMA"] = ',',
["SIN"] = 'S'
},
["C64"] = new Dictionary<string, char>
{
["L"] = 'L',
["R"] = 'R',
["F1"] = '1',
["F3"] = '3',
["F5"] = '5',
["F7"] = '7',
["Left Arrow"] = 'l',
["Plus"] = '+',
["Minus"] = '-',
["Pound"] = 'l',
["Clear/Home"] = 'c',
["Insert/Delete"] = 'i',
["Control"] = 'c',
["At"] = '@',
["Asterisk"] = '*',
["Up Arrow"] = 'u',
["Restore"] = 'r',
["Run/Stop"] = 's',
["Lck"] = 'k',
["Colon"] = ':',
["Semicolon"] = ';',
["Equal"] = '=',
["Return"] = 'e',
["Commodore"] = 'o',
["Left Shift"] = 's',
["Comma"] = ',',
["Period"] = '>',
["Slash"] = '/',
["Right Shift"] = 's',
["Cursor Up/Down"] = 'u',
["Cursor Left/Right"] = 'l',
["Space"] = '_'
},
["N64"] = new Dictionary<string, char>
{
["C Up"] = 'u',
["C Down"] = 'd',
["C Left"] = 'l',
["C Right"] = 'r',
{ "B11", 'b' },
{ "B12", 'c' },
{ "B13", 'd' },
{ "B14", 'e' },
{ "B15", 'f' },
{ "B16", 'g' },
{ "B17", 'h' },
{ "B18", 'i' },
{ "B19", 'j' },
{ "B20", 'k' },
["A Up"] = 'U',
["A Down"] = 'D',
["A Left"] = 'L',
["A Right"] = 'R',
{ "B21", 'l' },
{ "B22", 'm' },
{ "B23", 'n' },
{ "B24", 'o' },
{ "B25", 'p' },
{ "B26", 'q' },
{ "B27", 'r' },
{ "B28", 's' },
{ "B29", 't' },
{ "B30", 'u' },
{ "B31", 'v' }
}
},
{
"TI83",
new Dictionary<string, char>
{
{ "UP", 'U' },
{ "DOWN", 'D' },
{ "LEFT", 'L' },
{ "RIGHT", 'R' },
{ "DOT", '`' },
{ "ON", 'O' },
{ "ENTER", '=' },
{ "PLUS", '+' },
{ "MINUS", '_' },
{ "MULTIPLY", '*' },
{ "DIVIDE", '/' },
{ "CLEAR", 'c' },
{ "EXP", '^' },
{ "DASH", '-' },
{ "PARAOPEN", '(' },
{ "PARACLOSE", ')' },
{ "TAN", 'T' },
{ "VARS", 'V' },
{ "COS", 'C' },
{ "PRGM", 'P' },
{ "STAT", 's' },
{ "MATRIX", 'm' },
{ "X", 'X' },
{ "STO", '>' },
{ "LN", 'n' },
{ "LOG", 'L' },
{ "SQUARED", '2' },
{ "NEG1", '1' },
{ "MATH", 'H' },
{ "ALPHA", 'A' },
{ "GRAPH", 'G' },
{ "TRACE", 't' },
{ "ZOOM", 'Z' },
{ "WINDOW", 'W' },
{ "Y", 'Y' },
{ "2ND", '&' },
{ "MODE", 'O' },
{ "DEL", 'D' },
{ "COMMA", ',' },
{ "SIN", 'S' }
}
},
{
"C64",
new Dictionary<string, char>
{
{ "L", 'L' },
{ "R", 'R' },
{ "F1", '1' },
{ "F3", '3' },
{ "F5", '5' },
{ "F7", '7' },
{ "Left Arrow", 'l' },
{ "Plus", '+' },
{ "Minus", '-' },
{ "Pound", 'l' },
{ "Clear/Home", 'c' },
{ "Insert/Delete", 'i' },
{ "Control", 'c' },
{ "At", '@' },
{ "Asterisk", '*' },
{ "Up Arrow", 'u' },
{ "Restore", 'r' },
{ "Run/Stop", 's' },
{ "Lck", 'k' },
{ "Colon", ':' },
{ "Semicolon", ';' },
{ "Equal", '=' },
{ "Return", 'e' },
{ "Commodore", 'o' },
{ "Left Shift", 's' },
{ "Comma", ',' },
{ "Period", '>' },
{ "Slash", '/' },
{ "Right Shift", 's' },
{ "Cursor Up/Down", 'u' },
{ "Cursor Left/Right", 'l' },
{ "Space", '_' }
}
},
{
"N64",
new Dictionary<string, char>
{
{ "C Up", 'u' },
{ "C Down", 'd' },
{ "C Left", 'l' },
{ "C Right", 'r' },
{ "A Up", 'U' },
{ "A Down", 'D' },
{ "A Left", 'L' },
{ "A Right", 'R' },
{ "DPad U", 'U' },
{ "DPad D", 'D' },
{ "DPad L", 'L' },
{ "DPad R", 'R' },
}
},
{
"DGB",
new Dictionary<string, char>
{
{ "Toggle Cable", 'L' },
}
},
{
"Lynx",
new Dictionary<string, char>
{
{ "Option 1", '1' },
{ "Option 2", '2' }
}
},
{
"AppleII",
new Dictionary<string, char>
{
{ "Tab", 't' },
{ "Return", 'e' },
{ "Escape", 'x' },
{ "Delete", 'b' },
{ "Space", 's' },
{ "Control", 'c' },
{ "Shift", '^' },
{ "Caps Lock", 'C' },
{ "Next Disk", '>' },
{ "Previous Disk", '<' },
{ "White Apple", 'w' },
{ "Black Apple", 'b' },
{ "L", 'L' },
{ "R", 'R' }
}
},
{
"INTV",
new Dictionary<string, char>
{
{ "Clear", 'C' },
{ "Enter", 'E' },
{ "Top", 'T' },
{ "NNE", 'n' },
{ "NE", '/' },
{ "ENE", 'e' },
{ "ESE", 'e' },
{ "SE", '\\' },
{ "SSE", 's' },
{ "SSW", 's' },
{ "SW", '/' },
{ "WSW", 'w' },
{ "WNW", 'w' },
{ "NW", '\\' },
{ "NNW", 'n' }
}
},
{
"Coleco",
new Dictionary<string, char>
{
{ "Yellow", 'Y' },
{ "Red", 'R' },
{ "Blue", 'B' },
{ "Purple", 'P' }
}
}
};
["DPad U"] = 'U',
["DPad D"] = 'D',
["DPad L"] = 'L',
["DPad R"] = 'R',
},
["DGB"] = new Dictionary<string, char>
{
["Toggle Cable"] = 'L'
},
["Lynx"] = new Dictionary<string, char>
{
["Option 1"] = '1',
["Option 2"] = '2'
},
["AppleII"] = new Dictionary<string, char>
{
["Tab"] = 't' ,
["Return"] = 'e' ,
["Escape"] = 'x' ,
["Delete"] = 'b' ,
["Space"] = 's' ,
["Control"] = 'c' ,
["Shift"] = '^' ,
["Caps Lock"] = 'C' ,
["Next Disk"] = '>' ,
["Previous Disk"] = '<' ,
["White Apple"] = 'w' ,
["Black Apple"] = 'b' ,
["L"] = 'L' ,
["R"] = 'R'
},
["INTV"] = new Dictionary<string, char>
{
["Clear"] = 'C' ,
["Enter"] = 'E' ,
["Top"] = 'T' ,
["NNE"] = 'n' ,
["NE"] = '/' ,
["ENE"] = 'e' ,
["ESE"] = 'e' ,
["SE"] = '\\' ,
["SSE"] = 's' ,
["SSW"] = 's' ,
["SW"] = '/' ,
["WSW"] = 'w' ,
["WNW"] = 'w' ,
["NW"] = '\\' ,
["NNW"] = 'n'
},
["Coleco"] = new Dictionary<string, char>
{
["Yellow"] = 'Y',
["Red"] = 'R',
["Blue"] = 'B',
["Purple"] = 'P'
}
};
}
}

View File

@ -42,7 +42,7 @@ namespace BizHawk.Client.Common
void CopyTo(int index, string[] array, int arrayIndex, int count);
}
class ListStringLog : List<string>, IStringLog
internal class ListStringLog : List<string>, IStringLog
{
public IStringLog Clone()
{
@ -60,7 +60,7 @@ namespace BizHawk.Client.Common
/// It should be faster than those alternatives, but wasteful of disk space.
/// It should also be easier to add new IList<string>-like methods than dealing with a database
/// </summary>
class StreamStringLog : IStringLog
internal class StreamStringLog : IStringLog
{
List<long> Offsets = new List<long>();
long cursor = 0;
@ -165,7 +165,7 @@ namespace BizHawk.Client.Common
}
}
class Enumerator : IEnumerator<string>
private class Enumerator : IEnumerator<string>
{
public StreamStringLog log;
int index = -1;