Skip to content

Commit

Permalink
Move resourcepack stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyvv committed Oct 13, 2021
1 parent aa23494 commit 7d999cf
Show file tree
Hide file tree
Showing 28 changed files with 432 additions and 343 deletions.
10 changes: 10 additions & 0 deletions src/Alex.ResourcePackLib/Abstraction/IColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Alex.ResourcePackLib.Abstraction
{
public interface IColor
{
byte R { get; set; }
byte G { get; set; }
byte B { get; set; }
uint PackedValue { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/Alex.ResourcePackLib/Bedrock/MCPackModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Alex.ResourcePackLib.IO.Abstract;

namespace Alex.ResourcePackLib.Bedrock
{
public class MCPackModule
{
public virtual string Name
{
get
{
return Entry.Name;
}
}

protected IFilesystem Entry { get; }
protected MCPackModule(IFilesystem entry)
{
Entry = entry;
}

internal virtual bool Load()
{
return false;
}
}
}
19 changes: 19 additions & 0 deletions src/Alex.ResourcePackLib/Bedrock/ResourceModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Alex.ResourcePackLib.IO.Abstract;

namespace Alex.ResourcePackLib.Bedrock
{
public class ResourceModule : MCPackModule
{
/// <inheritdoc />
public ResourceModule(IFilesystem entry) : base(entry)
{

}

/// <inheritdoc />
internal override bool Load()
{
return base.Load();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Alex.Common.Resources;
using Alex.Common.Utils;
using Alex.ResourcePackLib.Abstraction;
using Alex.ResourcePackLib.IO;
using Alex.ResourcePackLib.IO.Abstract;
using Alex.ResourcePackLib.Json;
using Alex.ResourcePackLib.Json.Bedrock;
using Alex.ResourcePackLib.Json.Models.Entities;
using Alex.ResourcePackLib.Json.Textures;
using NLog;
using NLog.Fluent;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;

namespace Alex.ResourcePackLib
namespace Alex.ResourcePackLib.Bedrock
{
public class MCPackModule
{
public virtual string Name
{
get
{
return Entry.Name;
}
}

protected IFilesystem Entry { get; }
protected MCPackModule(IFilesystem entry)
{
Entry = entry;
}

internal virtual bool Load()
{
return false;
}
}

public class MCSkinPack : MCPackModule, ITextureProvider
public class SkinModule : MCPackModule, ITextureProvider
{
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

Expand All @@ -65,7 +40,7 @@ public override string Name {
public IReadOnlyDictionary<string, EntityModel> EntityModels { get; private set; }

/// <inheritdoc />
internal MCSkinPack(IFilesystem entry) : base(entry)
internal SkinModule(IFilesystem entry) : base(entry)
{

}
Expand All @@ -75,8 +50,6 @@ internal override bool Load()
{
try
{
List<LoadedSkin> skins = new List<LoadedSkin>();

var archive = Entry;
//using (var archive = new ZipFileSystem(Entry.Open(), Entry.Name))
{
Expand All @@ -91,34 +64,6 @@ internal override bool Load()
if (geometryEntry != null)
{
ProcessGeometryJson(geometryEntry);
/*Dictionary<string, EntityModel> models =
MCJsonConvert.DeserializeObject<Dictionary<string, EntityModel>>(
geometryEntry.ReadAsString());
foreach (var skin in Info.Skins)
{
EntityModel model;
if (!models.TryGetValue(skin.Geometry, out model))
continue;
var textureEntry = archive.GetEntry(skin.Texture);
if (textureEntry == null)
continue;
Image<Rgba32> img;
using (var s = textureEntry.Open())
{
//img = new Bitmap(s);
img = Image.Load<Rgba32>(s.ReadToSpan(textureEntry.Length), PngDecoder);
}
LoadedSkin loaded = new LoadedSkin(skin.LocalizationName, model, img);
skins.Add(loaded);
//skin.
}*/
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions src/Alex.ResourcePackLib/Exceptions/UnknownModuleException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Alex.ResourcePackLib.Exceptions
{
public class UnknownModuleException : Exception
{
public UnknownModuleException(string message) : base(message)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Alex.MoLang.Parser;
using Alex.MoLang.Runtime;
using Alex.ResourcePackLib.Json.Bedrock.Entity;
using Alex.ResourcePackLib.Json.Bedrock.MoLang;
using Microsoft.Xna.Framework;
using Newtonsoft.Json;

namespace Alex.ResourcePackLib.Json.Bedrock.Particles.Components
Expand Down Expand Up @@ -59,62 +57,4 @@ public override void Update(IParticle particle, MoLangRuntime runtime)
}
}
}

public class ParticleUV
{
[JsonProperty("texture_width")]
public float TextureWidth { get; set; }

[JsonProperty("texture_height")]
public float TextureHeight { get; set; }

[JsonProperty("uv")]
public MoLangVector2Expression Uv { get; set; } = null;

[JsonProperty("uv_size")]
public MoLangVector2Expression Size { get; set; } = null;

[JsonProperty("flipbook")]
public Flipbook Flipbook { get; set; }

public Vector2 GetUv(MoLangRuntime runtime)
{
if (Flipbook?.Base != null)
{
return Flipbook.Base.Evaluate(runtime, Vector2.Zero);
}

return Uv?.Evaluate(runtime, Vector2.Zero) ?? Vector2.Zero;
}

public Vector2 GetSize(MoLangRuntime runtime)
{
if (Flipbook?.Size != null)
{
return Flipbook.Size.Value;
}

return (Size?.Evaluate(runtime, Vector2.One) ?? (Vector2.One));
}
}

public class Flipbook
{
[JsonProperty("base_UV")]
public MoLangVector2Expression Base { get; set; }

[JsonProperty("size_UV")]
public Vector2? Size { get; set; } = null;

[JsonProperty("step_UV")]
public Vector2 Step { get; set; } = Vector2.Zero;

[JsonProperty("frames_per_second")] public float? FPS { get; set; } = 8;

[JsonProperty("max_frame")] public IExpression[] MaxFrame { get; set; }

[JsonProperty("stretch_to_lifetime")] public bool StretchToLifetime { get; set; }

[JsonProperty("loop")] public bool Loop { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Alex.MoLang.Parser;
using Alex.ResourcePackLib.Json.Bedrock.MoLang;
using Microsoft.Xna.Framework;
using Newtonsoft.Json;

namespace Alex.ResourcePackLib.Json.Bedrock.Particles.Components
{
public class Flipbook
{
[JsonProperty("base_UV")]
public MoLangVector2Expression Base { get; set; }

[JsonProperty("size_UV")]
public Vector2? Size { get; set; } = null;

[JsonProperty("step_UV")]
public Vector2 Step { get; set; } = Vector2.Zero;

[JsonProperty("frames_per_second")] public float? FPS { get; set; } = 8;

[JsonProperty("max_frame")] public IExpression[] MaxFrame { get; set; }

[JsonProperty("stretch_to_lifetime")] public bool StretchToLifetime { get; set; }

[JsonProperty("loop")] public bool Loop { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Alex.MoLang.Runtime;
using Alex.ResourcePackLib.Json.Bedrock.MoLang;
using Microsoft.Xna.Framework;
using Newtonsoft.Json;

namespace Alex.ResourcePackLib.Json.Bedrock.Particles.Components
{
public class ParticleUV
{
[JsonProperty("texture_width")]
public float TextureWidth { get; set; }

[JsonProperty("texture_height")]
public float TextureHeight { get; set; }

[JsonProperty("uv")]
public MoLangVector2Expression Uv { get; set; } = null;

[JsonProperty("uv_size")]
public MoLangVector2Expression Size { get; set; } = null;

[JsonProperty("flipbook")]
public Flipbook Flipbook { get; set; }

public Vector2 GetUv(MoLangRuntime runtime)
{
if (Flipbook?.Base != null)
{
return Flipbook.Base.Evaluate(runtime, Vector2.Zero);
}

return Uv?.Evaluate(runtime, Vector2.Zero) ?? Vector2.Zero;
}

public Vector2 GetSize(MoLangRuntime runtime)
{
if (Flipbook?.Size != null)
{
return Flipbook.Size.Value;
}

return (Size?.Evaluate(runtime, Vector2.One) ?? (Vector2.One));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Color GetValue(MoLangRuntime runtime)

if (_expression != null)
return new Color(_expression.Evaluate(runtime, new Vector4(1, 1, 1, 1f)));

if (_gradientColors != null)
return _gradientColors.GetValue(runtime);

Expand Down
5 changes: 4 additions & 1 deletion src/Alex.ResourcePackLib/Json/Models/Entities/EntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public class EntityModel
{
foreach (var bone in baseEntity.Bones)
{
bones.Add(bone.Name, bone.Clone());
if (!bones.TryAdd(bone.Name, bone.Clone()))
{
Log.Warn($"Duplicate bone: {bone.Name}");
}
}
}

Expand Down
Loading

0 comments on commit 7d999cf

Please sign in to comment.