mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-16 05:36:03 -05:00
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer. Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis. Performance has also been slightly improved; no allocation is done anymore when updating the image.
57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace NHSE.Injection;
|
|
|
|
public sealed record AutoInjector(IDataInjector Injector, Action<InjectionResult> DoRead, Action<InjectionResult> DoWrite)
|
|
{
|
|
public bool AutoInjectEnabled { private get; set; }
|
|
|
|
public bool ValidateEnabled
|
|
{
|
|
get => Injector.ValidateEnabled;
|
|
set => Injector.ValidateEnabled = value;
|
|
}
|
|
|
|
public void Validate() => Injector.Validate();
|
|
|
|
public InjectionResult Read(bool force = false)
|
|
{
|
|
if ((!AutoInjectEnabled && !force) || !Injector.Connected)
|
|
return InjectionResult.Skipped;
|
|
|
|
try
|
|
{
|
|
var result = Injector.Read();
|
|
DoRead(result);
|
|
return result;
|
|
}
|
|
catch (IndexOutOfRangeException ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
return InjectionResult.FailConnectionError;
|
|
}
|
|
}
|
|
|
|
public InjectionResult Write(bool force = false)
|
|
{
|
|
if ((!AutoInjectEnabled && !force) || !Injector.Connected)
|
|
return InjectionResult.Skipped;
|
|
try
|
|
{
|
|
var result = Injector.Write();
|
|
DoWrite(result);
|
|
return result;
|
|
}
|
|
catch (IndexOutOfRangeException ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
return InjectionResult.FailConnectionError;
|
|
}
|
|
}
|
|
|
|
public void SetWriteOffset(in uint offset)
|
|
{
|
|
Injector.WriteOffset = offset;
|
|
}
|
|
} |