mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-17 06:06:10 -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.
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace NHSE.Core;
|
|
|
|
public sealed class RecipeBook(Memory<byte> raw)
|
|
{
|
|
private const int BitFlagArraySize = 0x100;
|
|
private const int BitFlagArrayCount = 4;
|
|
public const int SIZE = BitFlagArraySize * BitFlagArrayCount;
|
|
public const ushort RecipeCount = BitFlagArraySize * 8;
|
|
|
|
private Span<byte> Data => raw.Span;
|
|
|
|
public void Save(Span<byte> data) => Data.CopyTo(data);
|
|
|
|
public bool GetIsKnown(int recipe) => FlagUtil.GetFlag(Data, 0 * BitFlagArraySize, recipe);
|
|
public void SetIsKnown(int recipe, bool value = true) => FlagUtil.SetFlag(Data, 0 * BitFlagArraySize, recipe, value);
|
|
|
|
public bool GetIsMade(int recipe) => FlagUtil.GetFlag(Data, 1 * BitFlagArraySize, recipe);
|
|
public void SetIsMade(int recipe, bool value = true) => FlagUtil.SetFlag(Data, 1 * BitFlagArraySize, recipe, value);
|
|
|
|
public bool GetIsNew(int recipe) => FlagUtil.GetFlag(Data, 2 * BitFlagArraySize, recipe);
|
|
public void SetIsNew(int recipe, bool value = true) => FlagUtil.SetFlag(Data, 2 * BitFlagArraySize, recipe, value);
|
|
|
|
public bool GetIsFavorite(int recipe) => FlagUtil.GetFlag(Data, 3 * BitFlagArraySize, recipe);
|
|
public void SetIsFavorite(int recipe, bool value = true) => FlagUtil.SetFlag(Data, 3 * BitFlagArraySize, recipe, value);
|
|
|
|
public void GiveAll(IReadOnlyDictionary<ushort,ushort> recipes, bool isNew = true)
|
|
{
|
|
foreach (var entry in recipes)
|
|
{
|
|
var index = entry.Key;
|
|
if (index is RecipeList.BridgeConstructionKit or RecipeList.CampsiteConstructionKit)
|
|
continue;
|
|
|
|
bool alreadyHave = GetIsKnown(index);
|
|
if (alreadyHave)
|
|
continue;
|
|
|
|
SetIsKnown(index);
|
|
SetIsNew(index, isNew);
|
|
}
|
|
}
|
|
|
|
public void ClearAll()
|
|
{
|
|
for (int i = 0; i < RecipeCount; i++)
|
|
{
|
|
SetIsKnown(i, false);
|
|
SetIsNew(i, false);
|
|
SetIsMade(i, false);
|
|
SetIsFavorite(i, false);
|
|
}
|
|
}
|
|
|
|
public void CraftAll()
|
|
{
|
|
for (int i = 0; i < RecipeCount; i++)
|
|
{
|
|
bool alreadyHave = GetIsKnown(i);
|
|
if (!alreadyHave)
|
|
continue;
|
|
SetIsMade(i);
|
|
SetIsNew(i, false);
|
|
}
|
|
}
|
|
} |