Finish item mapping; add item help collection

This commit is contained in:
jeffman 2015-03-25 11:55:09 -04:00
parent c2aae18a60
commit 5c955ac907
8 changed files with 609 additions and 563 deletions

View File

@ -110,7 +110,7 @@ namespace ScriptTool
address += code.ComputeLength(rom, address); address += code.ComputeLength(rom, address);
/*if (code.IsEnd) /*if (newLines && code.IsEnd && !suppressNextEnd)
{ {
builder.Append("(" + address.ToString("X") + ")"); builder.Append("(" + address.ToString("X") + ")");
}*/ }*/

View File

@ -220,12 +220,12 @@ namespace ScriptTool
var tptTuple = M12TextTables.ReadTptRefs(m12Rom); var tptTuple = M12TextTables.ReadTptRefs(m12Rom);
allRefs.Add(Tuple.Create("m12-tpt-primary", tptTuple.Item1)); allRefs.Add(Tuple.Create("m12-tpt-primary", tptTuple.Item1));
allRefs.Add(Tuple.Create("m12-tpt-secondary", tptTuple.Item2)); allRefs.Add(Tuple.Create("m12-tpt-secondary", tptTuple.Item2));
allRefs.Add(Tuple.Create("m12-psihelp", M12TextTables.ReadPsiHelpRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-psi-help", M12TextTables.ReadPsiHelpRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-battle-actions", M12TextTables.ReadBattleActionRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-battle-actions", M12TextTables.ReadBattleActionRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-itemhelp", M12TextTables.ReadItemHelpRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-item-help", M12TextTables.ReadItemHelpRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-movements", M12TextTables.ReadMovementRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-movements", M12TextTables.ReadMovementRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-objects", M12TextTables.ReadObjectRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-objects", M12TextTables.ReadObjectRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-phonelist", M12TextTables.ReadPhoneRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-phone-list", M12TextTables.ReadPhoneRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-unknown", M12TextTables.ReadUnknownRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-unknown", M12TextTables.ReadUnknownRefs(m12Rom)));
allRefs.Add(Tuple.Create("m12-enemy-encounters", M12TextTables.ReadEnemyEncounters(m12Rom))); allRefs.Add(Tuple.Create("m12-enemy-encounters", M12TextTables.ReadEnemyEncounters(m12Rom)));
allRefs.Add(Tuple.Create("m12-prayers", M12TextTables.ReadPrayerRefs(m12Rom))); allRefs.Add(Tuple.Create("m12-prayers", M12TextTables.ReadPrayerRefs(m12Rom)));

View File

@ -77,6 +77,9 @@
<None Include="eb-codelist.json"> <None Include="eb-codelist.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Include="item-map.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="m12-char-lookup.json"> <None Include="m12-char-lookup.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace ScriptToolGui namespace ScriptToolGui
{ {
class IndexMapping : IEnumerable<IndexPair> class IndexMapping : IEnumerable<IndexPair>, ICollection<IndexPair>
{ {
public IList<IndexPair> Pairs { get; private set; } public ICollection<IndexPair> Pairs { get; private set; }
public IndexMapping() public IndexMapping()
{ {
@ -29,5 +29,40 @@ namespace ScriptToolGui
{ {
return GetEnumerator(); return GetEnumerator();
} }
public void Add(IndexPair item)
{
Pairs.Add(item);
}
public void Clear()
{
Pairs.Clear();
}
public bool Contains(IndexPair item)
{
return Pairs.Contains(item);
}
public void CopyTo(IndexPair[] array, int arrayIndex)
{
Pairs.CopyTo(array, arrayIndex);
}
public int Count
{
get { return Pairs.Count; }
}
public bool IsReadOnly
{
get { return Pairs.IsReadOnly; }
}
public bool Remove(IndexPair item)
{
return Pairs.Remove(item);
}
} }
} }

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace ScriptToolGui namespace ScriptToolGui
{ {
struct IndexPair class IndexPair
{ {
public readonly int First; public int First { get; private set; }
public readonly int Second; public int Second { get; private set; }
public IndexPair(int first, int second) public IndexPair(int first, int second)
{ {

View File

@ -41,6 +41,7 @@ namespace ScriptToolGui
// Matched reference pairs // Matched reference pairs
MatchedGroupCollection tptGroups = new MatchedGroupCollection("TPT"); MatchedGroupCollection tptGroups = new MatchedGroupCollection("TPT");
MatchedGroupCollection battleActionGroups = new MatchedGroupCollection("Battle actions"); MatchedGroupCollection battleActionGroups = new MatchedGroupCollection("Battle actions");
MatchedGroupCollection itemHelpGroups = new MatchedGroupCollection("Item help");
List<MatchedGroup> matchedGroups = new List<MatchedGroup>(); List<MatchedGroup> matchedGroups = new List<MatchedGroup>();
IList<MatchedGroupCollection> matchedCollections = new List<MatchedGroupCollection>(); IList<MatchedGroupCollection> matchedCollections = new List<MatchedGroupCollection>();
@ -48,6 +49,7 @@ namespace ScriptToolGui
IDictionary<Game, int> currentIndex; IDictionary<Game, int> currentIndex;
NavigationEntry previousNavigationState = null; NavigationEntry previousNavigationState = null;
Stack<NavigationEntry> navigationStack = new Stack<NavigationEntry>(); Stack<NavigationEntry> navigationStack = new Stack<NavigationEntry>();
MatchedGroupCollection currentCollection = null;
static MainForm() static MainForm()
{ {
@ -55,11 +57,21 @@ namespace ScriptToolGui
ebCharLookup = JsonConvert.DeserializeObject<Dictionary<byte, string>>(File.ReadAllText("eb-char-lookup.json")); ebCharLookup = JsonConvert.DeserializeObject<Dictionary<byte, string>>(File.ReadAllText("eb-char-lookup.json"));
} }
string ReadEbString(byte[] rom, int address, int length)
{
var sb = new StringBuilder();
for(int i=0;i<length && rom[address] != 0; i++)
{
sb.Append((char)(rom[address++] - 0x30));
}
return sb.ToString();
}
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
ImportAllStringRefs(workingFolder); ImportAllStringRefs();
ImportAllStrings(workingFolder); ImportAllStrings(workingFolder);
InitLookups(); InitLookups();
@ -74,8 +86,7 @@ namespace ScriptToolGui
{ {
collectionSelector.Items.Clear(); collectionSelector.Items.Clear();
collectionSelector.Items.Add(tptGroups); collectionSelector.Items.AddRange(matchedCollections.ToArray());
collectionSelector.Items.Add(battleActionGroups);
} }
private void PopulateGroupSelector(MatchedGroupCollection collection) private void PopulateGroupSelector(MatchedGroupCollection collection)
@ -109,47 +120,60 @@ namespace ScriptToolGui
}; };
} }
private void ImportAllStringRefs(string folder) private void ImportAllStringRefs()
{ {
// TPT // TPT
var m12PrimaryTptRefs = ImportStringRefs(Path.Combine(folder, "m12-tpt-primary.json")); var m12PrimaryTptRefs = ImportStringRefs("m12-tpt-primary.json");
var ebPrimaryTptRefs = ImportStringRefs(Path.Combine(folder, "eb-tpt-primary.json")); var ebPrimaryTptRefs = ImportStringRefs("eb-tpt-primary.json");
var m12SecondaryTptRefs = ImportStringRefs(Path.Combine(folder, "m12-tpt-secondary.json")); var m12SecondaryTptRefs = ImportStringRefs("m12-tpt-secondary.json");
var ebSecondaryTptRefs = ImportStringRefs(Path.Combine(folder, "eb-tpt-secondary.json")); var ebSecondaryTptRefs = ImportStringRefs("eb-tpt-secondary.json");
tptGroups.Groups.AddRange(MatchRefs(ebPrimaryTptRefs, m12PrimaryTptRefs)); tptGroups.Groups.AddRange(MatchRefs(ebPrimaryTptRefs, m12PrimaryTptRefs));
tptGroups.Groups.AddRange(MatchRefs(ebSecondaryTptRefs, m12SecondaryTptRefs)); tptGroups.Groups.AddRange(MatchRefs(ebSecondaryTptRefs, m12SecondaryTptRefs));
tptGroups.Groups.Sort((g1, g2) => g1.Index.CompareTo(g2.Index)); tptGroups.Groups.Sort((g1, g2) => g1.Refs[Game.Eb].Index.CompareTo(g2.Refs[Game.Eb].Index));
matchedGroups.AddRange(tptGroups); matchedGroups.AddRange(tptGroups);
// Battle actions // Battle actions
var m12BattleActionRefs = ImportStringRefs(Path.Combine(folder, "m12-battle-actions.json")); var m12BattleActionRefs = ImportStringRefs("m12-battle-actions.json");
var ebBattleActionRefs = ImportStringRefs(Path.Combine(folder, "eb-battle-actions.json")); var ebBattleActionRefs = ImportStringRefs("eb-battle-actions.json");
battleActionGroups.Groups.AddRange(MatchRefs(ebBattleActionRefs, m12BattleActionRefs)); battleActionGroups.Groups.AddRange(MatchRefs(ebBattleActionRefs, m12BattleActionRefs));
battleActionGroups.Groups.Sort((g1, g2) => g1.Index.CompareTo(g2.Index)); battleActionGroups.Groups.Sort((g1, g2) => g1.Refs[Game.Eb].Index.CompareTo(g2.Refs[Game.Eb].Index));
matchedGroups.AddRange(battleActionGroups); matchedGroups.AddRange(battleActionGroups);
// Item help // Item help
itemMapping = JsonConvert.DeserializeObject<IndexMapping>(File.ReadAllText("item-map.json"));
var m12ItemHelpRefs = ImportStringRefs("m12-item-help.json");
var ebItemHelpRefs = ImportStringRefs("eb-item-help.json");
var itemHelpMappingGroups = itemMapping.Select(p => new MatchedGroup(
ebItemHelpRefs.First(e => e.Index == p.First),
m12ItemHelpRefs.First(m => m.Index == p.Second),
m12ItemHelpRefs.First(m => m.Index == p.Second)))
.OrderBy(g => g.Refs[Game.Eb].Index)
.ToArray();
itemHelpGroups.Groups.AddRange(itemHelpMappingGroups);
matchedGroups.AddRange(itemHelpGroups);
matchedGroups.Sort((g1, g2) => g1.Refs[Game.Eb].Index.CompareTo(g2.Refs[Game.Eb].Index));
matchedGroups.Sort((g1, g2) => g1.Index.CompareTo(g2.Index));
matchedCollections.Add(tptGroups); matchedCollections.Add(tptGroups);
matchedCollections.Add(battleActionGroups); matchedCollections.Add(battleActionGroups);
matchedCollections.Add(itemHelpGroups);
} }
private MatchedGroup[] MatchRefs(MainStringRef[] ebRefs, MainStringRef[] m12Refs) private MatchedGroup[] MatchRefs(MainStringRef[] ebRefs, MainStringRef[] m12Refs)
{ {
return ebRefs.Join(m12Refs, e => e.Index, m => m.Index, (e, m) => new { e, m }) return ebRefs.Join(m12Refs, e => e.Index, m => m.Index,
(e, m) => new { e, m })
.Select(p => new MatchedGroup(p.e, p.m, p.m)) .Select(p => new MatchedGroup(p.e, p.m, p.m))
.ToArray(); .ToArray();
} }
private MainStringRef[] ImportStringRefs(string fileName) private MainStringRef[] ImportStringRefs(string fileName)
{ {
string jsonString = File.ReadAllText(fileName); string jsonString = File.ReadAllText(Path.Combine(workingFolder, fileName));
return JsonConvert.DeserializeObject<MainStringRef[]>(jsonString); return JsonConvert.DeserializeObject<MainStringRef[]>(jsonString);
} }
@ -499,6 +523,13 @@ namespace ScriptToolGui
else else
{ {
var collection = (MatchedGroupCollection)collectionSelector.SelectedItem; var collection = (MatchedGroupCollection)collectionSelector.SelectedItem;
// Take no action if we haven't actually changed the collection
// (otherwise, the group selector would jump to 0, probably unwanted)
if (collection == currentCollection)
return;
currentCollection = collection;
PopulateGroupSelector(collection); PopulateGroupSelector(collection);
groupSelector.SelectedIndex = 0; groupSelector.SelectedIndex = 0;

View File

@ -10,7 +10,6 @@ namespace ScriptToolGui
class MatchedGroup class MatchedGroup
{ {
public IDictionary<Game, MainStringRef> Refs { get; private set; } public IDictionary<Game, MainStringRef> Refs { get; private set; }
public int Index { get; private set; }
public MatchedGroup() public MatchedGroup()
{ {
@ -20,22 +19,16 @@ namespace ScriptToolGui
public MatchedGroup(MainStringRef ebRef, MainStringRef m12Ref, MainStringRef m12EnglishRef) public MatchedGroup(MainStringRef ebRef, MainStringRef m12Ref, MainStringRef m12EnglishRef)
: this() : this()
{ {
if (ebRef.Index != m12Ref.Index)
{
}
Refs.Add(Game.Eb, ebRef); Refs.Add(Game.Eb, ebRef);
Refs.Add(Game.M12, m12Ref); Refs.Add(Game.M12, m12Ref);
Refs.Add(Game.M12English, m12EnglishRef); Refs.Add(Game.M12English, m12EnglishRef);
Index = ebRef.Index;
} }
public override string ToString() public override string ToString()
{ {
return String.Format("[{0:X3}] EB: {1} / M12: {2}", Index.ToString("X3"), return String.Format("[{0:X3}] EB: {1} / [{2:X3}] M12: {3}",
Refs[Game.Eb].Label, Refs[Game.M12].Label); Refs[Game.Eb].Index, Refs[Game.Eb].Label,
Refs[Game.M12].Index, Refs[Game.M12].Label);
} }
} }
} }