Beispiel #1
0
    public static ScriptTextEvent Parse(string[] parts)
    {
        var textId   = ushort.Parse(parts[1]);
        var location = parts.Length > 2 ? (TextLocation)Enum.Parse(typeof(TextLocation), parts[2]) : TextLocation.NoPortrait;

        if (parts.Length <= 3)
        {
            return(new ScriptTextEvent(textId, location, CharacterId.None));
        }

        if (int.TryParse(parts[3], out var id))
        {
            if (id <= 0)
            {
                return(new ScriptTextEvent(textId, location, CharacterId.None));
            }

            var type = MapTextEvent.AssetTypeForTextLocation(location);
            return(new ScriptTextEvent(textId, location, new CharacterId(type, id)));
        }

        var charId = CharacterId.Parse(parts[3]);

        return(new ScriptTextEvent(textId, location, charId));
    }
Beispiel #2
0
    public ScriptTextEvent(ushort textId, TextLocation location, CharacterId characterId)
    {
        TextId   = textId;
        Location = location;

        var expectedType = MapTextEvent.AssetTypeForTextLocation(location);

        if (characterId.Type != expectedType && !characterId.IsNone)
        {
            throw new FormatException(
                      "Tried to construct a text event with location " +
                      $"{location} and a character id of type {characterId.Type}, but a {expectedType} was expected");
        }

        Speaker = characterId;
    }