Skip to content

Commit

Permalink
Update EnvironmentArea (formerly NoWeatherArea) to 901
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-zk committed Aug 14, 2024
1 parent db477fd commit d400ffe
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 51 deletions.
4 changes: 2 additions & 2 deletions TruckLib/ScsMap/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum ItemType
Service = 0x07,
CutPlane = 0x08,
Mover = 0x09,
NoWeatherArea = 0x0B,
EnvironmentArea = 0x0B,
CityArea = 0x0C,
Hinge = 0x0D,
AnimatedModel = 0x0F,
Expand Down Expand Up @@ -316,7 +316,7 @@ public enum EasingFunction
}

/// <summary>
/// Fog behavior in a <see cref="NoWeatherArea">No Weather Area</see>.
/// Fog behavior in a <see cref="EnvironmentArea">No Weather Area</see>.
/// </summary>
public enum FogMask
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace TruckLib.ScsMap
{
/// <summary>
/// Defines a rectangular area in which weather effects are disabled.
/// Defines a rectangular area in which
/// </summary>
public class NoWeatherArea : SingleNodeItem
public class EnvironmentArea : SingleNodeItem
{
/// <inheritdoc/>
public override ItemType ItemType => ItemType.NoWeatherArea;
public override ItemType ItemType => ItemType.EnvironmentArea;

/// <inheritdoc/>
public override ItemFile DefaultItemFile => ItemFile.Aux;
Expand All @@ -34,9 +34,25 @@ public class NoWeatherArea : SingleNodeItem

public FogMask FogBehavior { get; set; }

public NoWeatherArea() : base() { }
/// <summary>
/// Unit name of the climate profile, as defined in <c>/def/climate.sii</c>.
/// </summary>
public Token Climate { get; set; }

/// <summary>
/// Unit name of the reflection cube, as defined in <c>/def/relightable_cubemaps.sii</c>(?).
/// </summary>
public Token ReflectionCube { get; set; }

public bool Precipitation
{
get => !Kdop.Flags[0];
set => Kdop.Flags[0] = !value;
}

public EnvironmentArea() : base() { }

internal NoWeatherArea(bool initFields) : base(initFields)
internal EnvironmentArea(bool initFields) : base(initFields)
{
if (initFields) Init();
}
Expand All @@ -45,24 +61,26 @@ internal NoWeatherArea(bool initFields) : base(initFields)
protected override void Init()
{
base.Init();
Width = 200;
Height = 200;
}

/// <summary>
/// Adds a NoWeatherArea to the map.
/// Adds an environment area to the map.
/// </summary>
/// <param name="map">The map.</param>
/// <param name="position">The position of the center of the area.</param>
/// <param name="width">The width of the area.</param>
/// <param name="height">The height of the area.</param>
/// <returns>The newly created NoWeatherArea.</returns>
public static NoWeatherArea Add(IItemContainer map, Vector3 position, float width, float height)
/// <returns>The newly created environment area.</returns>
public static EnvironmentArea Add(IItemContainer map, Vector3 position, float width, float height)
{
var nwa = Add<NoWeatherArea>(map, position);
var ea = Add<EnvironmentArea>(map, position);

nwa.Width = width;
nwa.Height = height;
ea.Width = width;
ea.Height = height;

return nwa;
return ea;
}
}
}
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TruckLib.ScsMap
/// </summary>
public class Header : IBinarySerializable
{
private const int supportedVersion = 900;
private const int supportedVersion = 901;
/// <summary>
/// Version number of the map format.
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions TruckLib/ScsMap/Serialization/EnvironmentAreaSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace TruckLib.ScsMap.Serialization
{
class EnvironmentAreaSerializer : MapItemSerializer
{
private const float sizeFactor = 2f;

public override MapItem Deserialize(BinaryReader r)
{
var ea = new EnvironmentArea(false);
ReadKdopItem(r, ea);

ea.Width = r.ReadSingle() * sizeFactor;
ea.Height = r.ReadSingle() * sizeFactor;
ea.FogBehavior = (FogMask)r.ReadInt32();
ea.Climate = r.ReadToken();
ea.ReflectionCube = r.ReadToken();
ea.Node = new UnresolvedNode(r.ReadUInt64());

return ea;
}

public override void Serialize(BinaryWriter w, MapItem item)
{
var ea = item as EnvironmentArea;
WriteKdopItem(w, ea);
w.Write(ea.Width / sizeFactor);
w.Write(ea.Height / sizeFactor);
w.Write((int)ea.FogBehavior);
w.Write(ea.Climate);
w.Write(ea.ReflectionCube);
w.Write(ea.Node.Uid);
}
}
}
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/Serialization/MapItemSerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static MapItemSerializer Create(ItemType type)
ItemType.MapOverlay => new MapOverlaySerializer(),
ItemType.Model => new ModelSerializer(),
ItemType.Mover => new MoverSerializer(),
ItemType.NoWeatherArea => new NoWeatherAreaSerializer(),
ItemType.EnvironmentArea => new EnvironmentAreaSerializer(),
ItemType.Prefab => new PrefabSerializer(),
ItemType.Road => new RoadSerializer(),
ItemType.Service => new ServiceSerializer(),
Expand Down
35 changes: 0 additions & 35 deletions TruckLib/ScsMap/Serialization/NoWeatherAreaSerializer.cs

This file was deleted.

0 comments on commit d400ffe

Please sign in to comment.