mirror of
https://github.com/kwsch/NHSE.git
synced 2026-03-22 09:44:49 -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.
42 lines
2.1 KiB
C#
42 lines
2.1 KiB
C#
namespace NHSE.Core;
|
|
|
|
public static class MapTileManagerUtil
|
|
{
|
|
/// <summary>
|
|
/// Retrieves a <see cref="MapTileManager"/> from the provided <see cref="MainSave"/>.
|
|
/// </summary>
|
|
public static MapTileManager FromSaveFile(MainSave sav) => new()
|
|
{
|
|
ConfigTerrain = LayerPositionConfig.Create(7, 6, 16, 1, 1, 1),
|
|
ConfigBuildings = LayerPositionConfig.Create(9, 7, 16, 1, 0, 0),
|
|
ConfigItems = LayerPositionConfig.Create(sav.FieldItemAcreWidth, sav.FieldItemAcreHeight, 32, 1,
|
|
(byte)((9 - sav.FieldItemAcreWidth) / 2), 1),
|
|
|
|
LayerTerrain = new LayerTerrain(sav.GetTerrainTiles(), sav.GetAcreBytes()),
|
|
LayerBuildings = new LayerBuilding { Buildings = sav.Buildings },
|
|
FieldItems = new LayerFieldItemSet
|
|
{
|
|
Layer0 = new LayerFieldItem(sav.GetFieldItemLayer0(), sav.FieldItemAcreWidth, sav.FieldItemAcreHeight),
|
|
Layer1 = new LayerFieldItem(sav.GetFieldItemLayer1(), sav.FieldItemAcreWidth, sav.FieldItemAcreHeight),
|
|
},
|
|
LayerItemFlag0 = new LayerFieldItemFlag(sav.FieldItemFlag0Data, sav.FieldItemAcreWidth, sav.FieldItemAcreHeight),
|
|
LayerItemFlag1 = new LayerFieldItemFlag(sav.FieldItemFlag1Data, sav.FieldItemAcreWidth, sav.FieldItemAcreHeight),
|
|
Plaza = new MapStatePlaza { X = sav.EventPlazaLeftUpX, Z = sav.EventPlazaLeftUpZ },
|
|
};
|
|
|
|
/// <summary>
|
|
/// Sets the values from the provided <see cref="MapTileManager"/> into the provided <see cref="MainSave"/>.
|
|
/// </summary>
|
|
public static void SetManager(this MapTileManager mgr, MainSave sav)
|
|
{
|
|
sav.Buildings = mgr.LayerBuildings.Buildings;
|
|
sav.SetTerrainTiles(mgr.LayerTerrain.Tiles);
|
|
sav.SetFieldItemLayer0(mgr.FieldItems.Layer0.Tiles);
|
|
sav.SetFieldItemLayer1(mgr.FieldItems.Layer1.Tiles);
|
|
mgr.LayerItemFlag0.Save(sav.FieldItemFlag0Data.Span);
|
|
mgr.LayerItemFlag1.Save(sav.FieldItemFlag1Data.Span);
|
|
sav.SetAcreBytes(mgr.LayerTerrain.BaseAcres.Span);
|
|
sav.EventPlazaLeftUpX = mgr.Plaza.X;
|
|
sav.EventPlazaLeftUpZ = mgr.Plaza.Z;
|
|
}
|
|
} |