public void DeserializeTextUnknown(string text, byte[] expected) { var commands = MsgSerializer.DeserializeText(text); var actual = Encoders.InternationalSystem.Encode(commands.ToList()); Assert.Equal(expected, actual); }
public void DeserializeTextPositionCommand(byte[] expected, string text) { var commands = MsgSerializer.DeserializeText(text).ToList(); var actual = Encoders.InternationalSystem.Encode(commands); Assert.Equal(expected, actual); }
public void DeserializeNewLine() { var commands = MsgSerializer.DeserializeText("hello\nworld!").ToArray(); Assert.Equal(MessageCommand.PrintText, commands[0].Command); Assert.Equal("hello\nworld!", commands[0].Text); }
public void DeserializePlainText(string value, byte[] expected) { var entries = MsgSerializer.DeserializeText(value); using (var stream = new MemoryStream()) { var actual = Encoders.InternationalSystem.Encode(entries.ToList()); Assert.Equal(expected, actual); } }
public void DeserializeTabulation() { var commands = MsgSerializer.DeserializeText("hello\tworld!").ToArray(); Assert.Equal(MessageCommand.PrintText, commands[0].Command); Assert.Equal("hello", commands[0].Text); Assert.Equal(MessageCommand.Tabulation, commands[1].Command); Assert.Equal(MessageCommand.PrintText, commands[2].Command); Assert.Equal("world!", commands[2].Text); }
public void SetMessage(ushort id, string text) { var message = _messages?.FirstOrDefault(x => x.Id == (id & 0x7fff)); if (message == null) { return; } message.Data = Encoders.InternationalSystem.Encode(MsgSerializer.DeserializeText(text).ToList()); }
public void DeserializeCorrectNumberOfMsgEntries(string value, int expectedEntries, string expectedText) { var entries = MsgSerializer.DeserializeText(value).ToList(); Assert.Equal(expectedEntries, entries.Count); var index = 0; foreach (var word in expectedText.Split(';')) { if (entries[index].Command == MessageCommand.PrintText) { Assert.Equal(entries[index].Text, word); } index++; } }
private static void PatchKh2Msg(Context context, List <AssetFile> sources, Stream stream) { var msgs = Msg.IsValid(stream) ? Msg.Read(stream) : new List <Msg.Entry>(); foreach (var source in sources) { if (string.IsNullOrEmpty(source.Language)) { throw new Exception($"No language specified in '{source.Name}'"); } var content = File.ReadAllText(context.GetSourceModAssetPath(source.Name)); var patchedMsgs = new Deserializer().Deserialize <List <Dictionary <string, string> > >(content); foreach (var msg in patchedMsgs) { if (!msg.TryGetValue("id", out var strId)) { throw new Exception($"Source '{source.Name}' contains a message without an ID"); } if (!ushort.TryParse(strId, out var id)) { if (strId.Length > 2 && strId[1] == 'x') { if (!ushort.TryParse(strId.Substring(2), NumberStyles.HexNumber, null, out id)) { throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); } } else { throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); } } if (!msg.TryGetValue(source.Language, out var text)) { continue; } var encoder = source.Language switch { "jp" => Encoders.JapaneseSystem, "tr" => Encoders.TurkishSystem, _ => Encoders.InternationalSystem, }; var data = encoder.Encode(MsgSerializer.DeserializeText(text ?? string.Empty).ToList()); var originalMsg = msgs.FirstOrDefault(x => x.Id == id); if (originalMsg == null) { msgs.Add(new Msg.Entry { Id = id, Data = data }); } else { originalMsg.Data = data; } } } Msg.WriteOptimized(stream.SetPosition(0), msgs); }
public void Draw(DrawContext drawContext, string message) => Draw(drawContext, MsgSerializer.DeserializeText(message));
public void ThrowsExceptionForParseError(string value) { Assert.Throws <ParseException>(() => MsgSerializer.DeserializeText(value)); }
public void SetString(ushort id, string text) => _messages[id] = Encoder.Encode(MsgSerializer.DeserializeText(text).ToList());