Skip to content

Commit

Permalink
Merge pull request #33 from BigBang1112/dev
Browse files Browse the repository at this point in the history
GBX.NET 0.14.1
  • Loading branch information
BigBang1112 committed Dec 3, 2021
2 parents 7a12408 + fb7b59a commit d627d3d
Show file tree
Hide file tree
Showing 45 changed files with 1,439 additions and 1,030 deletions.
4 changes: 1 addition & 3 deletions Benchmarks/GBX.NET.Benchmarks/LzoBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public void Setup()

MapCompressed.Seek(0, SeekOrigin.Begin);

var map = GameBox.ParseNode(MapCompressed)!;
map.GBX!.Header.CompressionOfBody = GameBoxCompression.Uncompressed;
map.Save(MapUncompressed);
GameBox.Decompress(MapCompressed, MapUncompressed);

MapCompressed.Seek(0, SeekOrigin.Begin);
MapUncompressed.Seek(0, SeekOrigin.Begin);
Expand Down
2 changes: 1 addition & 1 deletion Src/GBX.NET.Imaging/CGameCtnChallengeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void ExportThumbnail(this CGameCtnChallenge node, Stream stream, I
/// <param name="format">Image format to use.</param>
public static void ExportThumbnail(this CGameCtnChallenge node, string fileName, ImageFormat format)
{
using var fs = File.OpenWrite(fileName);
using var fs = File.Create(fileName);
ExportThumbnail(node, fs, format);
}

Expand Down
2 changes: 1 addition & 1 deletion Src/GBX.NET.Imaging/CGameCtnCollectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void ExportIcon(this CGameCtnCollector node, Stream stream)
/// <param name="format">Image format to use.</param>
public static void ExportIcon(this CGameCtnCollector node, string fileName, ImageFormat format)
{
using var fs = File.OpenWrite(fileName);
using var fs = File.Create(fileName);
ExportIcon(node, fs, format);
}

Expand Down
4 changes: 2 additions & 2 deletions Src/GBX.NET.Imaging/GBX.NET.Imaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Copyright>Copyright © Petr 'BigBang1112' Pivoňka</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>

<Version>1.0.1</Version>
<PackageReleaseNotes>Update to C# 10.</PackageReleaseNotes>
<Version>1.0.2</Version>
<PackageReleaseNotes>Replace File.OpenWrite with File.Create</PackageReleaseNotes>

<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0;net48</TargetFrameworks>
<LangVersion>10</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ public partial class CControlEffectSimiBuilder
{
public class TM2 : GameBuilder<ICControlEffectSimiBuilder, CControlEffectSimi>
{
public int ColorBlendMode { get; set; }
public bool IsContinousEffect { get; set; }
public bool IsInterpolated { get; set; }

public TM2(ICControlEffectSimiBuilder baseBuilder, CControlEffectSimi node) : base(baseBuilder, node) { }

public TM2 WithColorBlendMode(int colorBlendMode)
{
ColorBlendMode = colorBlendMode;
return this;
}

public TM2 ContinousEffect()
{
IsContinousEffect = true;
return this;
}

public TM2 Interpolated()
{
IsInterpolated = true;
return this;
}

public override CControlEffectSimi Build()
{
Node.CreateChunk<CControlEffectSimi.Chunk07010005>();
Node.ColorBlendMode = ColorBlendMode;
Node.IsContinousEffect = IsContinousEffect;
Node.IsInterpolated = IsInterpolated;
return Node;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ public partial class CControlEffectSimiBuilder
{
public class TM2020 : GameBuilder<ICControlEffectSimiBuilder, CControlEffectSimi>
{
public int ColorBlendMode { get; set; }
public bool IsContinousEffect { get; set; }
public bool IsInterpolated { get; set; }

public TM2020(ICControlEffectSimiBuilder baseBuilder, CControlEffectSimi node) : base(baseBuilder, node) { }

public TM2020 WithColorBlendMode(int colorBlendMode)
{
ColorBlendMode = colorBlendMode;
return this;
}

public TM2020 ContinousEffect()
{
IsContinousEffect = true;
return this;
}

public TM2020 Interpolated()
{
IsInterpolated = true;
return this;
}

public override CControlEffectSimi Build()
{
Node.CreateChunk<CControlEffectSimi.Chunk07010005>();
Node.ColorBlendMode = ColorBlendMode;
Node.IsContinousEffect = IsContinousEffect;
Node.IsInterpolated = IsInterpolated;
return Node;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@ public partial class CControlEffectSimiBuilder
{
public class TMU : GameBuilder<ICControlEffectSimiBuilder, CControlEffectSimi>
{
public int ColorBlendMode { get; set; }
public bool IsContinousEffect { get; set; }

public TMU(ICControlEffectSimiBuilder baseBuilder, CControlEffectSimi node) : base(baseBuilder, node) { }

public TMU WithColorBlendMode(int colorBlendMode)
{
ColorBlendMode = colorBlendMode;
return this;
}

public TMU ContinousEffect()
{
IsContinousEffect = true;
return this;
}

public override CControlEffectSimi Build()
{
Node.CreateChunk<CControlEffectSimi.Chunk07010004>();
Node.ColorBlendMode = ColorBlendMode;
Node.IsContinousEffect = IsContinousEffect;
return Node;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ public partial class CControlEffectSimiBuilder
{
public class TMUF : GameBuilder<ICControlEffectSimiBuilder, CControlEffectSimi>
{
public int ColorBlendMode { get; set; }
public bool IsContinousEffect { get; set; }
public bool IsInterpolated { get; set; }

public TMUF(ICControlEffectSimiBuilder baseBuilder, CControlEffectSimi node) : base(baseBuilder, node) { }

public TMUF WithColorBlendMode(int colorBlendMode)
{
ColorBlendMode = colorBlendMode;
return this;
}

public TMUF ContinousEffect()
{
IsContinousEffect = true;
return this;
}

public TMUF Interpolated()
{
IsInterpolated = true;
return this;
}

public override CControlEffectSimi Build()
{
Node.CreateChunk<CControlEffectSimi.Chunk07010005>();
Node.ColorBlendMode = ColorBlendMode;
Node.IsContinousEffect = IsContinousEffect;
Node.IsInterpolated = IsInterpolated;
return Node;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public partial class CControlEffectSimiBuilder : ICControlEffectSimiBuilder
{
public IList<CControlEffectSimi.Key>? Keys { get; set; }
public bool IsCentered { get; set; }

public CControlEffectSimiBuilder WithKeys(IList<CControlEffectSimi.Key> keys)
{
Expand All @@ -16,6 +17,12 @@ public CControlEffectSimiBuilder WithKeys(params CControlEffectSimi.Key[] keys)
return this;
}

public CControlEffectSimiBuilder Centered()
{
IsCentered = true;
return this;
}

public TMSX ForTMSX() => new(this, NewNode());
public TMU ForTMU() => new(this, NewNode());
public TMUF ForTMUF() => new(this, NewNode());
Expand All @@ -37,6 +44,7 @@ internal CControlEffectSimi NewNode()
{
var node = NodeCacheManager.GetNodeInstance<CControlEffectSimi>(0x07010000);
node.Keys = Keys ?? new List<CControlEffectSimi.Key>();
node.Centered = IsCentered;
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public partial class CGameCtnMediaBlockSoundBuilder
public class TM2 : GameBuilder<ICGameCtnMediaBlockSoundBuilder, CGameCtnMediaBlockSound>
{
public bool IsMusic { get; set; }
public bool StopWithClip { get; set; }
public bool StopWithClip { get; set; } = true;
public bool AudioToSpeech { get; set; }
public int AudioToSpeechTarget { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public partial class CGameCtnMediaBlockSoundBuilder : ICGameCtnMediaBlockSoundBu
{
public FileRef? Sound { get; set; }
public IList<CGameCtnMediaBlockSound.Key>? Keys { get; set; }
public int PlayCount { get; set; }
public int PlayCount { get; set; } = 1;
public bool IsLooping { get; set; }

public CGameCtnMediaBlockSoundBuilder WithSound(FileRef sound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal CGameCtnMediaBlockText NewNode()
{
var node = NodeCacheManager.GetNodeInstance<CGameCtnMediaBlockText>(0x030A8000);
node.Text = Text ?? string.Empty;
node.Effect = Effect!;
node.Color = Color;
node.CreateChunk<CGameCtnMediaBlockText.Chunk030A8001>();
node.CreateChunk<CGameCtnMediaBlockText.Chunk030A8002>();
return node;
Expand Down
93 changes: 11 additions & 82 deletions Src/GBX.NET/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ public static uint Remap(uint chunkID, IDRemap remap = IDRemap.Latest)
{
case IDRemap.Latest:
{
uint newClassPart = classPart;
var newClassPart = classPart;
while (NodeCacheManager.Mappings.TryGetValue(newClassPart, out uint newID))
newClassPart = newID;
return newClassPart + chunkPart;
}
case IDRemap.TrackMania2006:
{
return classPart == 0x03078000 // Not ideal solution
var olderClassId = NodeCacheManager.Mappings.LastOrDefault(x => x.Value == classPart).Key;

if (olderClassId == default)
return chunkID;

var newId = classPart == 0x03078000 // Not ideal solution
? 0x24061000 + chunkPart
: NodeCacheManager.Mappings.LastOrDefault(x => x.Value == classPart).Key + chunkPart;
: olderClassId + chunkPart;

return newId;
}
default:
return chunkID;
Expand Down Expand Up @@ -92,82 +99,4 @@ void IChunk.ReadWrite(CMwNod n, GameBoxReaderWriter rw)
{
throw new NotSupportedException();
}
}

public abstract class Chunk<T> : Chunk, IChunk where T : CMwNod
{
[IgnoreDataMember]
public new T Node
{
get => (T)base.Node;
internal set => base.Node = value;
}

public bool IsHeader => this is IHeaderChunk;
public bool IsBody => !IsHeader;

protected Chunk() : base(null!)
{

}

protected Chunk(T node) : base(node)
{

}

void IChunk.Read(CMwNod n, GameBoxReader r)
{
Read((T)n, r);
}

void IChunk.Write(CMwNod n, GameBoxWriter w)
{
Write((T)n, w);
}

void IChunk.ReadWrite(CMwNod n, GameBoxReaderWriter rw)
{
ReadWrite((T)n, rw);
}

public virtual void Read(T n, GameBoxReader r)
{
throw new NotImplementedException($"Chunk 0x{ID & 0xFFF:x3} from class {Node.ClassName} doesn't support Read.");
}

public virtual void Write(T n, GameBoxWriter w)
{
throw new NotImplementedException($"Chunk 0x{ID & 0xFFF:x3} from class {Node.ClassName} doesn't support Write.");
}

public virtual void ReadWrite(T n, GameBoxReaderWriter rw)
{
if (rw.Reader != null)
Read(n, rw.Reader);
else if (rw.Writer != null)
Write(n, rw.Writer);
}

public byte[] ToByteArray()
{
if (this is ILookbackable l)
{
l.IdWritten = false;
l.IdStrings.Clear();
}

using var ms = new MemoryStream();
using var w = CreateWriter(ms);
var rw = new GameBoxReaderWriter(w);
ReadWrite(Node, rw);
return ms.ToArray();
}

public override string ToString()
{
var desc = GetType().GetCustomAttribute<ChunkAttribute>()?.Description;
var version = (this as IVersionable)?.Version;
return $"{typeof(T).Name} chunk 0x{ID:X8}{(string.IsNullOrEmpty(desc) ? "" : $" ({desc})")}{(version is null ? "" : $" [v{version}]")}";
}
}
}
Loading

0 comments on commit d627d3d

Please sign in to comment.