Skip to content
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
105 changes: 72 additions & 33 deletions Source/Data/CodeNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public CodeNote(uint address, string note)

public string Summary { get; private set; }

public IEnumerable<KeyValuePair<Token, Token>> Values
{
get { return _values ?? Enumerable.Empty<KeyValuePair<Token, Token>>(); }
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private List<KeyValuePair<Token, Token>> _values;

private class PointerData
Expand Down Expand Up @@ -499,46 +504,68 @@ private static TokenType NextToken(Tokenizer tokenizer, out Token token)
private static string TrimSize(string line, bool keepPointer)
{
int endIndex = -1;
var startIndex = line.IndexOf('[');
if (startIndex != -1)
{
endIndex = line.IndexOf(']', startIndex);
}
else
do
{
startIndex = line.IndexOf('(');
var startIndex = line.IndexOf('[', endIndex + 1);
if (startIndex != -1)
endIndex = line.IndexOf(')');
}
{
endIndex = line.IndexOf(']', startIndex);
}
else
{
startIndex = line.IndexOf('(', endIndex + 1);
if (startIndex != -1)
endIndex = line.IndexOf(')', startIndex);
else
endIndex = -1;
}

if (endIndex == -1)
return line;
if (endIndex == -1)
return line;

var tokenizer = Tokenizer.CreateTokenizer(line.ToLower(), startIndex, endIndex - startIndex);
Token token;
bool isPointer = false;
while (tokenizer.NextChar != '\0')
{
var tokenType = NextToken(tokenizer, out token);
if (tokenType == TokenType.Other)
var tokenizer = Tokenizer.CreateTokenizer(line.ToLower(), startIndex, endIndex - startIndex);
Token token;
bool isPointer = false;
bool foundSize = false;
while (tokenizer.NextChar != '\0')
{
if (token.CompareTo("pointer", StringComparison.InvariantCultureIgnoreCase) == 0)
isPointer = true;
var tokenType = NextToken(tokenizer, out token);
if (tokenType == TokenType.Other)
{
if (token.CompareTo("pointer", StringComparison.InvariantCultureIgnoreCase) == 0)
{
isPointer = true;
}
else
{
foundSize = false;
break;
}
}
else
return line;
{
foundSize = true;
}
}
};

while (startIndex > 0 && Char.IsWhiteSpace(line[startIndex - 1]))
--startIndex;
while (endIndex < line.Length - 1 && Char.IsWhiteSpace(line[endIndex + 1]))
++endIndex;

line = line.Remove(startIndex, endIndex - startIndex + 1);
if (isPointer && keepPointer)
line = "[pointer] " + line;
if (foundSize)
{
while (startIndex > 0 && Char.IsWhiteSpace(line[startIndex - 1]))
--startIndex;
while (endIndex < line.Length - 1 && Char.IsWhiteSpace(line[endIndex + 1]))
++endIndex;

var removeCount = endIndex - startIndex + 1;
line = line.Remove(startIndex, removeCount);
if (isPointer && keepPointer)
{
line = "[pointer] " + line;
removeCount -= 10;
}

return line;
endIndex -= removeCount;
}
} while (true);
}

private void ExtractValuesFromSummary()
Expand All @@ -548,7 +575,11 @@ private void ExtractValuesFromSummary()

var commaIndex = Summary.IndexOfAny(new[] { ',', ';' });
if (commaIndex == -1)
{
if (CheckValue(new Token(Summary, 0, Summary.Length)))
Summary = "Unlabelled";
return;
}

var newSummary = Summary;
Tokenizer tokenizer = null;
Expand Down Expand Up @@ -609,7 +640,7 @@ private void ExtractValuesFromSummary()
}
}

Summary = newSummary;
Summary = String.IsNullOrEmpty(newSummary) ? "Unlabelled" : newSummary;
}

private static bool IsHexDigit(char c)
Expand Down Expand Up @@ -662,7 +693,7 @@ private static bool IsValue(Token token)
return false;
}

private void CheckValue(Token clause)
private bool CheckValue(Token clause)
{
int prefixIndex = 0;
while (prefixIndex < clause.Length && !Char.IsLetterOrDigit(clause[prefixIndex]) && clause[prefixIndex] != '[')
Expand Down Expand Up @@ -711,10 +742,18 @@ private void CheckValue(Token clause)
var right = clause.SubToken(separator + separatorLength).Trim();

if (IsValue(left))
{
AddValue(left, right);
return true;
}
else if (IsValue(right))
{
AddValue(right, left);
return true;
}
}

return false;
}

private void AddValue(Token value, Token note)
Expand Down
189 changes: 188 additions & 1 deletion Source/Data/RichPresence.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics;
using Jamiras.Components;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace RATools.Data
{
Expand Down Expand Up @@ -39,9 +42,193 @@ public string Script
value = value.Trim();

_script = value;
_macros = null;
_displayStrings = null;
Description = string.Format("{0}/{1} characters", _script.Length, ScriptMaxLength);
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _script;

public class MacroDefinition
{
public MacroDefinition(string name, ValueFormat formatType)
: this(name, formatType, null)
{
}

public MacroDefinition(string name, ValueFormat formatType, Dictionary<string, string> lookupEntries)
{
Name = name;
FormatType = formatType;
LookupEntries = lookupEntries;
}

public string Name { get; private set; }
public ValueFormat FormatType { get; private set; }
public Dictionary<string, string> LookupEntries { get; private set; }

public override string ToString()
{
if (LookupEntries != null)
return String.Format("\"{0}\" ({1} Entries)", Name, LookupEntries.Count);

return String.Format("\"{0}\" ({1})", Name, FormatType);
}
}

public IEnumerable<MacroDefinition> Macros
{
get
{
if (_macros == null)
Parse();

return _macros;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private List<MacroDefinition> _macros;

[DebuggerDisplay("{Text}")]
public class DisplayString
{
public DisplayString(Trigger condition, string text, IEnumerable<Macro> macros)
{
Condition = condition;
Text = text;
Macros = macros;
}

public Trigger Condition { get; private set; }
public string Text { get; private set; }

[DebuggerDisplay("@{Name,nq}({Value})")]
public class Macro
{
public Macro(string name, Value value)
{
Name = name;
Value = value;
}
public string Name { get; private set; }
public Value Value { get; private set; }
}

public IEnumerable<Macro> Macros { get; private set; }
}

public IEnumerable<DisplayString> DisplayStrings
{
get
{
if (_macros == null)
Parse();

return _displayStrings;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private List<DisplayString> _displayStrings;

private enum Part
{
None,
Format,
Lookup,
Display,
}

private void Parse()
{
_macros = new List<MacroDefinition>();
_displayStrings = new List<DisplayString>();

string macroName = null;
Part part = Part.None;
Dictionary<string, string> lookups = null;

var tokenizer = Tokenizer.CreateTokenizer(_script);
while (tokenizer.NextChar != '\0')
{
var line = tokenizer.ReadTo('\n');
tokenizer.Advance();
if (line.StartsWith("//"))
continue;

if (line.EndsWith("\r"))
line = line.SubToken(0, line.Length - 1);

if (line.Length == 0)
continue;

if (line.StartsWith("Format:"))
{
macroName = line.Substring(7);
part = Part.Format;
}
else if (line.StartsWith("FormatType="))
{
if (part == Part.Format)
{
var formatType = Leaderboard.ParseFormat(line.Substring(11));
_macros.Add(new MacroDefinition(macroName, formatType));
}
part = Part.None;
}
else if (line.StartsWith("Lookup:"))
{
macroName = line.Substring(7);
lookups = new Dictionary<string, string>();
_macros.Add(new MacroDefinition(macroName, ValueFormat.None, lookups));
part = Part.Lookup;
}
else if (line.StartsWith("Display:"))
{
part = Part.Display;
}
else if (part == Part.Lookup)
{
var index = line.IndexOf('=');
if (index > 0)
lookups.Add(line.Substring(0, index), line.Substring(index + 1));
}
else if (part == Part.Display)
{
Trigger condition = null;
int index = 0;

if (line.StartsWith("?"))
{
index = line.IndexOf('?', 1);
if (index != -1)
condition = Trigger.Deserialize(line.Substring(1, index - 1));

++index;
}

var macros = new List<DisplayString.Macro>();
var text = line.Substring(index);
while ((index = line.IndexOf('@', index)) != -1)
{
var leftParen = line.IndexOf('(', index + 1);
if (leftParen == -1)
break;

var rightParen = line.IndexOf(')', leftParen + 1);
if (rightParen == -1)
break;

macroName = line.Substring(index + 1, leftParen - index - 1);
var value = Value.Deserialize(line.Substring(leftParen + 1, rightParen - leftParen - 1));
macros.Add(new DisplayString.Macro(macroName, value));

index = rightParen + 1;
}

_displayStrings.Add(new DisplayString(condition, text, macros.ToArray()));
}
}
}
}
}
13 changes: 13 additions & 0 deletions Source/Data/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public Trigger(IEnumerable<Requirement> core, IEnumerable<IEnumerable<Requiremen
/// </summary>
public IEnumerable<RequirementGroup> Alts { get; private set; }


public IEnumerable<RequirementGroup> Groups
{
get
{
if (Core != null)
yield return Core;

foreach (var group in Alts)
yield return group;
}
}

public override bool Equals(object obj)
{
var that = obj as Trigger;
Expand Down
Loading
Loading