mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-26 07:25:56 -05:00
Adding this new data format required that we define its behaviors for lots of things. For now, we'll assume that the only valid thing the user can do with an end token is to extend the table.
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using HavenSoft.HexManiac.Core.Models;
|
|
using HavenSoft.HexManiac.Core.Models.Runs;
|
|
using HavenSoft.HexManiac.Core.ViewModels.DataFormats;
|
|
using System;
|
|
|
|
namespace HavenSoft.HexManiac.Core.ViewModels {
|
|
/// <summary>
|
|
/// Given a data format, decide how to best display that as text
|
|
/// </summary>
|
|
public class ConvertCellToText : IDataFormatVisitor {
|
|
private readonly IDataModel buffer;
|
|
private readonly int index;
|
|
|
|
public string Result { get; private set; }
|
|
|
|
public ConvertCellToText(IDataModel buffer, int index) {
|
|
this.buffer = buffer;
|
|
this.index = index;
|
|
}
|
|
|
|
public void Visit(Undefined dataFormat, byte data) { }
|
|
|
|
public void Visit(None dataFormat, byte data) => Result = data.ToString("X2");
|
|
|
|
public void Visit(UnderEdit dataFormat, byte data) {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Visit(Pointer pointer, byte data) {
|
|
var destination = pointer.Destination.ToString("X6");
|
|
Result = $"<{destination}>";
|
|
if (!string.IsNullOrEmpty(pointer.DestinationName)) Result = $"<{pointer.DestinationName}>";
|
|
}
|
|
|
|
public void Visit(Anchor anchor, byte data) => anchor.OriginalFormat.Visit(this, data);
|
|
|
|
public void Visit(PCS pcs, byte data) {
|
|
Result = pcs.ThisCharacter;
|
|
}
|
|
|
|
public void Visit(EscapedPCS pcs, byte data) => Visit((None)null, data);
|
|
|
|
public void Visit(ErrorPCS pcs, byte data) => Visit((None)null, data);
|
|
|
|
public void Visit(Ascii ascii, byte data) => Result = ((char)data).ToString();
|
|
|
|
public void Visit(Integer integer, byte data) => Result = integer.Value.ToString();
|
|
|
|
public void Visit(IntegerEnum integerEnum, byte data) => Result = integerEnum.Value;
|
|
|
|
public void Visit(EggSection section, byte data) => Result = section.SectionName;
|
|
|
|
public void Visit(EggItem item, byte data) => Result = item.ItemName;
|
|
|
|
public void Visit(PlmItem item, byte data) => Result = item.ToString();
|
|
|
|
public void Visit(BitArray array, byte data) => Visit((None)null, data);
|
|
|
|
public void Visit(MatchedWord word, byte data) => Visit((None)null, data);
|
|
|
|
public void Visit(EndStream endStream, byte data) => Result = new string(new[] { ArrayRun.ArrayStart, ArrayRun.ArrayEnd });
|
|
}
|
|
}
|