mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-19 20:02:06 +00:00
Core - Update ResourceLocation.cs
This commit is contained in:
@@ -253,14 +253,33 @@ namespace PckStudio.Controls
|
||||
ResourceLocation resourceLocation = ResourceLocations.GetFromPath(asset.Filename);
|
||||
Debug.WriteLine("Handling Resource file: " + resourceLocation?.ToString());
|
||||
|
||||
switch (resourceLocation.Category)
|
||||
switch ((ResourceCategory)((int)resourceLocation.Category & 0xff000000))
|
||||
{
|
||||
case ResourceCategory.Unknown:
|
||||
Debug.WriteLine($"Unknown Resource Category.");
|
||||
break;
|
||||
case ResourceCategory.MobEntityTextures:
|
||||
case ResourceCategory.ItemEntityTextures:
|
||||
case ResourceCategory.Textures:
|
||||
{
|
||||
if ((resourceLocation.Category & ResourceCategory.ArmorTextures) != 0)
|
||||
{
|
||||
string assetName = Path.GetFileNameWithoutExtension(asset.Filename);
|
||||
ArmorSetDescription armorSetDescription = ArmorSetDescription.GetFromAssetName(assetName);
|
||||
Debug.WriteLineIf(!armorSetDescription.IsEmpty, armorSetDescription.Name);
|
||||
ITryGet<string, Image> tryGet = TryGet<string, Image>.FromDelegate((string path, out Image img) =>
|
||||
{
|
||||
img = null;
|
||||
if (EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset armorAsset))
|
||||
{
|
||||
img = armorAsset.GetTexture();
|
||||
Debug.WriteLine($"Got texture for: {path}");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ArmorSet armorSet = armorSetDescription.GetArmorSet(tryGetTexture: tryGet);
|
||||
break;
|
||||
}
|
||||
|
||||
string texturePath = asset.Filename.Substring(0, asset.Filename.Length - Path.GetExtension(asset.Filename).Length);
|
||||
string[] modelNames = GameModelImporter.ModelMetaData.Where(kv => kv.Value.TextureLocations.Contains(texturePath)).Select(kv => kv.Key).ToArray();
|
||||
|
||||
@@ -310,8 +329,7 @@ namespace PckStudio.Controls
|
||||
}
|
||||
break;
|
||||
|
||||
case ResourceCategory.ItemAnimation:
|
||||
case ResourceCategory.BlockAnimation:
|
||||
case ResourceCategory.Animation:
|
||||
Animation animation = asset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer);
|
||||
string internalName = Path.GetFileNameWithoutExtension(asset.Filename);
|
||||
IList<JsonTileInfo> textureInfos = resourceLocation.Category == ResourceCategory.ItemAnimation ? Tiles.ItemTileInfos : Tiles.BlockTileInfos;
|
||||
@@ -333,16 +351,7 @@ namespace PckStudio.Controls
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ResourceCategory.ParticleAtlas:
|
||||
case ResourceCategory.MoonPhaseAtlas:
|
||||
case ResourceCategory.ItemAtlas:
|
||||
case ResourceCategory.BlockAtlas:
|
||||
case ResourceCategory.BannerAtlas:
|
||||
case ResourceCategory.PaintingAtlas:
|
||||
case ResourceCategory.ExplosionAtlas:
|
||||
case ResourceCategory.ExperienceOrbAtlas:
|
||||
case ResourceCategory.MapIconAtlas:
|
||||
case ResourceCategory.AdditionalMapIconsAtlas:
|
||||
case ResourceCategory.Atlas:
|
||||
Atlas atlas = asset.GetDeserializedData(new AtlasDeserializer(resourceLocation));
|
||||
ColorContainer colorContainer = default;
|
||||
if (EditorValue.File.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out PckAsset colAsset))
|
||||
@@ -398,23 +407,6 @@ namespace PckStudio.Controls
|
||||
BuildMainTreeView();
|
||||
}
|
||||
break;
|
||||
case ResourceCategory.ArmorTextures:
|
||||
string assetName = Path.GetFileNameWithoutExtension(asset.Filename);
|
||||
ArmorSetDescription armorSetDescription = ArmorSetDescription.GetFromAssetName(assetName);
|
||||
Debug.WriteLineIf(!armorSetDescription.IsEmpty, armorSetDescription.Name);
|
||||
ITryGet<string, Image> tryGet = TryGet<string, Image>.FromDelegate((string path, out Image img) =>
|
||||
{
|
||||
img = null;
|
||||
if (EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset armorAsset))
|
||||
{
|
||||
img = armorAsset.GetTexture();
|
||||
Debug.WriteLine($"Got texture for: {path}");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ArmorSet armorSet = armorSetDescription.GetArmorSet(tryGetTexture: tryGet);
|
||||
break;
|
||||
default:
|
||||
Debug.WriteLine($"Unhandled Resource Category: {resourceLocation.Category}");
|
||||
break;
|
||||
@@ -1837,6 +1829,7 @@ namespace PckStudio.Controls
|
||||
form.Controls.Add(renderer);
|
||||
|
||||
renderer.VSync = true;
|
||||
renderer.RefreshRate = 120;
|
||||
renderer.BackColor = Color.FromArgb(30, 30, 30);
|
||||
renderer.Dock = DockStyle.Fill;
|
||||
renderer.Texture = modelTexture.Value;
|
||||
|
||||
@@ -52,8 +52,8 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
{
|
||||
(List<JsonTileInfo> textureInfos, Image[] images, string name) = key switch
|
||||
{
|
||||
ResourceCategory.BlockAnimation => (Tiles.BlockTileInfos, ((AtlasResource)ResourceLocations.GetFromCategory(ResourceCategory.BlockAtlas)).GetDefaultAtlas().GetTiles().Select(t => t.Texture).ToArray(), "Blocks"),
|
||||
ResourceCategory.ItemAnimation => (Tiles.ItemTileInfos, ((AtlasResource)ResourceLocations.GetFromCategory(ResourceCategory.ItemAtlas)).GetDefaultAtlas().GetTiles().Select(t => t.Texture).ToArray(), "Items"),
|
||||
ResourceCategory.BlockAnimation => (Tiles.BlockTileInfos, ((AtlasResource)ResourceLocations.GetFromCategory(AtlasResource.GetId(AtlasResource.AtlasType.BlockAtlas))).GetDefaultAtlas().GetTiles().Select(t => t.Texture).ToArray(), "Blocks"),
|
||||
ResourceCategory.ItemAnimation => (Tiles.ItemTileInfos, ((AtlasResource)ResourceLocations.GetFromCategory(AtlasResource.GetId(AtlasResource.AtlasType.ItemAtlas))).GetDefaultAtlas().GetTiles().Select(t => t.Texture).ToArray(), "Items"),
|
||||
_ => throw new InvalidOperationException(nameof(key))
|
||||
};
|
||||
TreeView view = filterPrompt.AddFilterPage(name, null, filterPredicate);
|
||||
|
||||
@@ -42,11 +42,19 @@ namespace PckStudio.Forms.Editor
|
||||
{
|
||||
private readonly ITryGet<string, Animation> _tryGetAnimation;
|
||||
private readonly ITryGet<string, ISaveContext<Animation>> _tryGetAnimationSaveContext;
|
||||
private readonly AtlasResource _atlasResource;
|
||||
private readonly ColorContainer _colourTable;
|
||||
private readonly ResourceCategory _resourceLocationCategory;
|
||||
private readonly Atlas _atlas;
|
||||
|
||||
private AtlasTile _selectedTile;
|
||||
private static readonly ColorDialog _colorPick = new ColorDialog
|
||||
{
|
||||
AllowFullOpen = true,
|
||||
AnyColor = true,
|
||||
SolidColorOnly = true,
|
||||
CustomColors = GameConstants.DyeColors.Select(ColorExtensions.ToBGR).ToArray()
|
||||
};
|
||||
private readonly FileObserver _fileObserver = new FileObserver();
|
||||
|
||||
public TextureAtlasEditor(Atlas atlas, ISaveContext<Atlas> saveContext, ResourceLocation resourceLocation, ColorContainer colorContainer,
|
||||
@@ -65,18 +73,19 @@ namespace PckStudio.Forms.Editor
|
||||
_colourTable = colorContainer ?? AppResourceManager.Default.GetData(Resources.tu69colours, new COLFileReader());
|
||||
_tryGetAnimation = tryGetAnimation;
|
||||
_tryGetAnimationSaveContext = tryGetAnimationSaveContext;
|
||||
_atlasResource = resourceLocation as AtlasResource;
|
||||
_resourceLocationCategory = resourceLocation.Category;
|
||||
|
||||
SelectedIndex = 0;
|
||||
|
||||
animationButton.Enabled =
|
||||
_resourceLocationCategory == ResourceCategory.BlockAtlas ||
|
||||
_resourceLocationCategory == ResourceCategory.ItemAtlas;
|
||||
_resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.BlockAtlas) ||
|
||||
_resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.ItemAtlas);
|
||||
|
||||
// this is directly based on Java's source code for handling enchanted hits
|
||||
// the particle is assigned a random grayscale color between roughly 154 and 230
|
||||
// since critical hit is the only particle with this distinction, we just need to check the atlas type
|
||||
if (_resourceLocationCategory == ResourceCategory.ParticleAtlas)
|
||||
if (_resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.ParticleAtlas))
|
||||
{
|
||||
colorSlider.Minimum = 154;
|
||||
colorSlider.Maximum = 230;
|
||||
@@ -121,22 +130,7 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private void SetImageDisplayed(int index)
|
||||
{
|
||||
tileNameLabel.Text = string.Empty;
|
||||
internalTileNameLabel.Text = string.Empty;
|
||||
|
||||
colorSlider.Visible = false;
|
||||
colorSliderLabel.Visible = false;
|
||||
variantComboBox.Visible = false;
|
||||
|
||||
variantComboBox.SelectedItem = null;
|
||||
variantComboBox.Enabled = false;
|
||||
variantComboBox.Items.Clear();
|
||||
clearColorButton.Enabled = false;
|
||||
|
||||
if (selectTilePictureBox.IsPlaying)
|
||||
selectTilePictureBox.Stop();
|
||||
selectTilePictureBox.UseBlendColor = false;
|
||||
selectTilePictureBox.Image = null;
|
||||
ResetView();
|
||||
_selectedTile = _atlas[index];
|
||||
|
||||
if (_selectedTile is null)
|
||||
@@ -146,30 +140,14 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
selectTilePictureBox.Image = _selectedTile.Texture;
|
||||
selectTilePictureBox.BlendColor = GetBlendColor();
|
||||
selectTilePictureBox.UseBlendColor = applyColorMaskToolStripMenuItem.Checked;
|
||||
|
||||
JsonTileInfo tileInfo = _selectedTile.GetUserDataOfType<JsonTileInfo>();
|
||||
|
||||
tileNameLabel.Text = $"{tileInfo?.DisplayName}";
|
||||
internalTileNameLabel.Text = $"{tileInfo?.InternalName}";
|
||||
if (animationButton.Enabled && (_resourceLocationCategory == ResourceCategory.ItemAtlas || _resourceLocationCategory == ResourceCategory.BlockAtlas))
|
||||
{
|
||||
ResourceCategory animationResourceCategory = _resourceLocationCategory == ResourceCategory.ItemAtlas ? ResourceCategory.ItemAnimation : ResourceCategory.BlockAnimation;
|
||||
|
||||
string animationAssetPath = $"{ResourceLocations.GetPathFromCategory(animationResourceCategory)}/{tileInfo.InternalName}";
|
||||
bool hasAnimation = _tryGetAnimation.TryGet(animationAssetPath, out Animation animation);
|
||||
animationButton.Text = hasAnimation ? "Edit Animation" : "Create Animation";
|
||||
|
||||
if (playAnimationsToolStripMenuItem.Checked && hasAnimation)
|
||||
{
|
||||
selectTilePictureBox.Image = animation.CreateAnimationImage(selectTilePictureBox.BlendColor);
|
||||
selectTilePictureBox.Start();
|
||||
}
|
||||
}
|
||||
|
||||
setColorButton.Enabled = tileInfo.AllowCustomColour;
|
||||
|
||||
variantComboBox.Enabled = variantComboBox.Visible = tileInfo.HasColourEntry && tileInfo.ColourEntry?.Variants?.Length > 1;
|
||||
|
||||
if (variantComboBox.Enabled)
|
||||
{
|
||||
if (tileInfo.ColourEntry.IsWaterColour)
|
||||
@@ -188,6 +166,33 @@ namespace PckStudio.Forms.Editor
|
||||
variantComboBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
CheckForAnimation();
|
||||
}
|
||||
|
||||
private void CheckForAnimation()
|
||||
{
|
||||
selectTilePictureBox.Image = _selectedTile.Texture;
|
||||
JsonTileInfo tileInfo = _selectedTile.GetUserDataOfType<JsonTileInfo>();
|
||||
if (animationButton.Enabled &&
|
||||
(_resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.ItemAtlas) ||
|
||||
_resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.BlockAtlas)))
|
||||
{
|
||||
ResourceCategory animationResourceCategory = _resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.ItemAtlas)
|
||||
? ResourceCategory.ItemAnimation
|
||||
: ResourceCategory.BlockAnimation;
|
||||
|
||||
string animationAssetPath = $"{ResourceLocations.GetPathFromCategory(animationResourceCategory)}/{tileInfo.InternalName}";
|
||||
bool hasAnimation = _tryGetAnimation.TryGet(animationAssetPath, out Animation animation);
|
||||
animationButton.Text = hasAnimation ? "Edit Animation" : "Create Animation";
|
||||
|
||||
if (playAnimationsToolStripMenuItem.Checked && hasAnimation)
|
||||
{
|
||||
selectTilePictureBox.Image = animation.CreateAnimationImage(selectTilePictureBox.BlendColor);
|
||||
selectTilePictureBox.Start();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_selectedTile.IsPartOfGroup && allowGroupsToolStripMenuItem.Checked)
|
||||
{
|
||||
AtlasGroup group = _selectedTile.GetGroup();
|
||||
@@ -212,6 +217,26 @@ namespace PckStudio.Forms.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetView()
|
||||
{
|
||||
tileNameLabel.Text = string.Empty;
|
||||
internalTileNameLabel.Text = string.Empty;
|
||||
|
||||
colorSlider.Visible = false;
|
||||
colorSliderLabel.Visible = false;
|
||||
variantComboBox.Visible = false;
|
||||
|
||||
variantComboBox.SelectedItem = null;
|
||||
variantComboBox.Enabled = false;
|
||||
variantComboBox.Items.Clear();
|
||||
clearColorButton.Enabled = false;
|
||||
|
||||
if (selectTilePictureBox.IsPlaying)
|
||||
selectTilePictureBox.Stop();
|
||||
selectTilePictureBox.UseBlendColor = false;
|
||||
selectTilePictureBox.Image = null;
|
||||
}
|
||||
|
||||
private static int GetSelectedImageIndex(
|
||||
Size pictureBoxSize,
|
||||
Size imageSize,
|
||||
@@ -333,17 +358,8 @@ namespace PckStudio.Forms.Editor
|
||||
return Color.FromArgb(colorSlider.Value, 255, 0);
|
||||
|
||||
// Similar story for critical hits, but for all values
|
||||
var final_color = Color.FromArgb(colorSlider.Value, colorSlider.Value, colorSlider.Value);
|
||||
|
||||
// Enchanted hits are modified critical hit particles
|
||||
if (_selectedTile.TryGetUserDataOfType(out JsonTileInfo tileInfo) && tileInfo.InternalName == "enchanted_hit")
|
||||
{
|
||||
// This is directly based on Java's source code for handling enchanted hits
|
||||
// it just multiplies the red by 0.3 and green by .8 of the color assigned to the critical hit particle
|
||||
final_color = Color.FromArgb((int)(final_color.R * 0.3f), (int)(final_color.R * 0.8f), final_color.B);
|
||||
return Color.FromArgb(colorSlider.Value, colorSlider.Value, colorSlider.Value);
|
||||
}
|
||||
return final_color;
|
||||
}
|
||||
|
||||
private Color FindBlendColorByKey(string colorKey)
|
||||
{
|
||||
@@ -357,6 +373,15 @@ namespace PckStudio.Forms.Editor
|
||||
return Color.White;
|
||||
}
|
||||
|
||||
// Enchanted hits are modified critical hit particles
|
||||
if (tileInfo.InternalName == "enchanted_hit")
|
||||
{
|
||||
// This is directly based on Java's source code for handling enchanted hits
|
||||
// it just multiplies the red by 0.3 and green by .8 of the color assigned to the critical hit particle
|
||||
var c = Color.FromArgb(colorSlider.Value, colorSlider.Value, colorSlider.Value);
|
||||
return Color.FromArgb((int)(c.R * 0.3f), (int)(c.R * 0.8f), c.B);
|
||||
}
|
||||
|
||||
// basic way to check for classic water colors
|
||||
if (!tileInfo.ColourEntry.IsWaterColour || colorKey.StartsWith("Water_"))
|
||||
{
|
||||
@@ -462,7 +487,7 @@ namespace PckStudio.Forms.Editor
|
||||
return;
|
||||
}
|
||||
JsonTileInfo tileInfo = _selectedTile.GetUserDataOfType<JsonTileInfo>();
|
||||
ResourceCategory animationResourceCategory = _resourceLocationCategory == ResourceCategory.ItemAtlas ? ResourceCategory.ItemAnimation : ResourceCategory.BlockAnimation;
|
||||
ResourceCategory animationResourceCategory = _resourceLocationCategory == AtlasResource.GetId(AtlasResource.AtlasType.ItemAtlas) ? ResourceCategory.ItemAnimation : ResourceCategory.BlockAnimation;
|
||||
string animationAssetPath = $"{ResourceLocations.GetPathFromCategory(animationResourceCategory)}/{tileInfo.InternalName}";
|
||||
bool hasAnimation = _tryGetAnimation.TryGet(animationAssetPath, out Animation animation);
|
||||
bool isValidAnimationSaveContext = _tryGetAnimationSaveContext.TryGet(animationAssetPath, out ISaveContext<Animation> animationSaveContext);
|
||||
@@ -541,12 +566,12 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private void applyColorMaskToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
SelectedIndex = _selectedTile.Index;
|
||||
selectTilePictureBox.UseBlendColor = applyColorMaskToolStripMenuItem.Checked;
|
||||
}
|
||||
|
||||
private void playAnimationsToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
SelectedIndex = _selectedTile.Index;
|
||||
CheckForAnimation();
|
||||
}
|
||||
|
||||
private void TextureAtlasEditor_FormClosing(object sender, FormClosingEventArgs e)
|
||||
@@ -558,18 +583,10 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private void setColorButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
ColorDialog colorPick = new ColorDialog
|
||||
{
|
||||
AllowFullOpen = true,
|
||||
AnyColor = true,
|
||||
SolidColorOnly = true,
|
||||
CustomColors = GameConstants.DyeColors.Select(ColorExtensions.ToBGR).ToArray()
|
||||
};
|
||||
|
||||
if (colorPick.ShowDialog(this) != DialogResult.OK)
|
||||
if (_colorPick.ShowDialog(this) != DialogResult.OK)
|
||||
return;
|
||||
|
||||
selectTilePictureBox.BlendColor = colorPick.Color;
|
||||
selectTilePictureBox.BlendColor = _colorPick.Color;
|
||||
variantComboBox.Enabled = false;
|
||||
clearColorButton.Enabled = true;
|
||||
}
|
||||
@@ -590,7 +607,7 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private void allowGroupsToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
SelectedIndex = _selectedTile.Index;
|
||||
CheckForAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
@@ -27,7 +28,6 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PckStudio</RootNamespace>
|
||||
<AssemblyName>PCK-Studio</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<NuGetPackageImportStamp>
|
||||
|
||||
@@ -21,6 +21,7 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using PckStudio.Core.Json;
|
||||
using static PckStudio.Core.AtlasResource;
|
||||
|
||||
namespace PckStudio.Core
|
||||
{
|
||||
@@ -28,47 +29,65 @@ namespace PckStudio.Core
|
||||
{
|
||||
public enum TillingMode
|
||||
{
|
||||
Width,
|
||||
Height,
|
||||
WidthAndHeight
|
||||
X,
|
||||
Y,
|
||||
XY
|
||||
}
|
||||
|
||||
public enum AtlasType
|
||||
{
|
||||
Invalid,
|
||||
ItemAtlas,
|
||||
BlockAtlas,
|
||||
ParticleAtlas,
|
||||
BannerAtlas,
|
||||
PaintingAtlas,
|
||||
ExplosionAtlas,
|
||||
ExperienceOrbAtlas,
|
||||
MoonPhaseAtlas,
|
||||
MapIconAtlas,
|
||||
AdditionalMapIconsAtlas,
|
||||
}
|
||||
|
||||
public IEnumerable<JsonTileInfo> TilesInfo { get; }
|
||||
public AtlasGroup[] AtlasGroups { get; }
|
||||
public readonly Image DefaultTexture;
|
||||
public Size TillingFactor { get; }
|
||||
public TillingMode Tilling { get; }
|
||||
public Size TileCount { get; }
|
||||
public TillingMode TileCountAxis { get; }
|
||||
public AtlasType Type { get; }
|
||||
|
||||
|
||||
|
||||
public AtlasResource(string path, ResourceCategory resourceCategory, int tillingFactor, Image defaultTexture, TillingMode tilling = default, IEnumerable<JsonTileInfo> tilesInfo = default, AtlasGroup[] atlasGroups = default)
|
||||
: this(path, resourceCategory, new Size(tillingFactor, tillingFactor), defaultTexture, tilling, tilesInfo, atlasGroups)
|
||||
public AtlasResource(string path, AtlasType atlasType, int tileCount, Image defaultTexture, TillingMode tilling = default, IEnumerable<JsonTileInfo> tilesInfo = default, AtlasGroup[] atlasGroups = default)
|
||||
: this(path, atlasType, new Size(tileCount, tileCount), defaultTexture, tilling, tilesInfo, atlasGroups)
|
||||
{
|
||||
}
|
||||
|
||||
public AtlasResource(string path, ResourceCategory resourceCategory, Size tillingFactor, Image defaultTexture, TillingMode tilling = default, IEnumerable<JsonTileInfo> tilesInfo = default, AtlasGroup[] atlasGroups = default)
|
||||
: base(path, resourceCategory, isGroup: false)
|
||||
public AtlasResource(string path, AtlasType atlasType, Size tillingFactor, Image defaultTexture, TillingMode tilling = default, IEnumerable<JsonTileInfo> tilesInfo = default, AtlasGroup[] atlasGroups = default)
|
||||
: base(path, GetId(atlasType), isGroup: false)
|
||||
{
|
||||
TilesInfo = tilesInfo ?? Enumerable.Empty<JsonTileInfo>();
|
||||
AtlasGroups = atlasGroups ?? Array.Empty<AtlasGroup>();
|
||||
DefaultTexture = defaultTexture;
|
||||
TillingFactor = new Size(Math.Max(1, tillingFactor.Width), Math.Max(1, tillingFactor.Height));
|
||||
Tilling = Enum.IsDefined(typeof(TillingMode), tilling) ? tilling : default;
|
||||
TileCount = new Size(Math.Max(1, tillingFactor.Width), Math.Max(1, tillingFactor.Height));
|
||||
TileCountAxis = Enum.IsDefined(typeof(TillingMode), tilling) ? tilling : default;
|
||||
Type = atlasType;
|
||||
}
|
||||
|
||||
public Atlas GetDefaultAtlas()
|
||||
{
|
||||
return Atlas.FromResourceLocation(DefaultTexture, this);
|
||||
}
|
||||
|
||||
public Size GetTileArea(Size imgSize)
|
||||
{
|
||||
return Tilling switch
|
||||
return TileCountAxis switch
|
||||
{
|
||||
TillingMode.Width => new Size(imgSize.Width / TillingFactor.Width, imgSize.Width / TillingFactor.Height),
|
||||
TillingMode.Height => new Size(imgSize.Height / TillingFactor.Width, imgSize.Height / TillingFactor.Height),
|
||||
TillingMode.WidthAndHeight => new Size(imgSize.Width / TillingFactor.Width, imgSize.Height / TillingFactor.Height),
|
||||
TillingMode.X => new Size(imgSize.Width / TileCount.Width, imgSize.Width / TileCount.Height),
|
||||
TillingMode.Y => new Size(imgSize.Height / TileCount.Width, imgSize.Height / TileCount.Height),
|
||||
TillingMode.XY => new Size(imgSize.Width / TileCount.Width, imgSize.Height / TileCount.Height),
|
||||
_ => Size.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
public static ResourceCategory GetId(AtlasType atlasType) => (ResourceCategory)((int)ResourceCategory.Atlas | (int)atlasType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,25 +24,15 @@ namespace PckStudio.Core
|
||||
public enum ResourceCategory : int
|
||||
{
|
||||
Unknown = -1,
|
||||
Animation = 0x01,
|
||||
ItemAnimation = 0x02 | Animation,
|
||||
BlockAnimation = 0x04 | Animation,
|
||||
Animation = (1 << 28),
|
||||
ItemAnimation = 1 | Animation,
|
||||
BlockAnimation = 2 | Animation,
|
||||
|
||||
Atlas = 0x08,
|
||||
ItemAtlas = 0x10 | Atlas,
|
||||
BlockAtlas = 0x20 | Atlas,
|
||||
ParticleAtlas = 0x40 | Atlas,
|
||||
BannerAtlas = 0x80 | Atlas,
|
||||
PaintingAtlas = 0x100 | Atlas,
|
||||
ExplosionAtlas = 0x200 | Atlas,
|
||||
ExperienceOrbAtlas = 0x400 | Atlas,
|
||||
MoonPhaseAtlas = 0x800 | Atlas,
|
||||
MapIconAtlas = 0x1000 | Atlas,
|
||||
AdditionalMapIconsAtlas = 0x2000 | Atlas,
|
||||
Atlas = (2 << 28),
|
||||
|
||||
Textures = 0x4000,
|
||||
MobEntityTextures = 0x8000 | Textures,
|
||||
ItemEntityTextures = 0x10000 | Textures,
|
||||
ArmorTextures = 0x20000 | Textures,
|
||||
Textures = (3 << 28),
|
||||
MobEntityTextures = 1 | Textures,
|
||||
ItemEntityTextures = 2 | Textures,
|
||||
ArmorTextures = 3 | Textures,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace PckStudio.Core
|
||||
private static List<ResourceLocation> ResourceGroups = new List<ResourceLocation>();
|
||||
private static readonly ResourceLocation Unknown = new ResourceLocation(string.Empty, ResourceCategory.Unknown);
|
||||
private static readonly Dictionary<string, ResourceLocation> _pathLookUp = new Dictionary<string, ResourceLocation>();
|
||||
private static readonly Dictionary<ResourceCategory, ResourceLocation> _categoryLookUp = new Dictionary<ResourceCategory, ResourceLocation>();
|
||||
private static readonly Dictionary<int, ResourceLocation> _categoryLookUp = new Dictionary<int, ResourceLocation>();
|
||||
|
||||
public string Path { get; }
|
||||
public string FullPath => System.IO.Path.Combine(RESOURCE_PATH_PREFIX, Path);
|
||||
@@ -49,7 +49,7 @@ namespace PckStudio.Core
|
||||
|
||||
if (Category != ResourceCategory.Unknown && !string.IsNullOrWhiteSpace(Path))
|
||||
{
|
||||
_categoryLookUp.Add(Category, this);
|
||||
_categoryLookUp.Add((int)Category, this);
|
||||
_pathLookUp.Add(Path, this);
|
||||
Debug.WriteLine($"Add ResourceLocation: {Path}({Category}).");
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace PckStudio.Core
|
||||
|
||||
public override string ToString() => FullPath;
|
||||
|
||||
internal static ResourceLocation GetFromCategory(ResourceCategory category) => _categoryLookUp.ContainsKey(category) ? _categoryLookUp[category] : Unknown;
|
||||
internal static ResourceLocation GetFromCategory(ResourceCategory category) => _categoryLookUp.ContainsKey((int)category) ? _categoryLookUp[(int)category] : Unknown;
|
||||
|
||||
internal static string GetPathFromCategory(ResourceCategory category) => GetFromCategory(category).ToString();
|
||||
|
||||
|
||||
@@ -31,16 +31,16 @@ namespace PckStudio.Core
|
||||
new GroupResource("mob", ResourceCategory.MobEntityTextures),
|
||||
new GroupResource("item", ResourceCategory.ItemEntityTextures),
|
||||
new GroupResource("armor", ResourceCategory.ArmorTextures),
|
||||
new AtlasResource("terrain.png", ResourceCategory.BlockAtlas, 16, Resources.terrain_atlas, tilesInfo: Tiles.BlockTileInfos, atlasGroups: _terrainAtlasGroups),
|
||||
new AtlasResource("items.png", ResourceCategory.ItemAtlas, 16, Resources.items_atlas, tilesInfo: Tiles.ItemTileInfos, atlasGroups: _itemsAtlasGroups),
|
||||
new AtlasResource("particles.png", ResourceCategory.ParticleAtlas, 16, Resources.particles_atlas, tilesInfo: Tiles.ParticleTileInfos, atlasGroups: _particaleAtlasGroups),
|
||||
new AtlasResource("item/banner/Banner_Atlas.png", ResourceCategory.BannerAtlas, new Size(6, 7), Resources.banners_atlas, AtlasResource.TillingMode.WidthAndHeight, tilesInfo: Tiles.BannerTileInfos),
|
||||
new AtlasResource("art/kz.png", ResourceCategory.PaintingAtlas, 16, Resources.paintings_atlas, tilesInfo: Tiles.PaintingTileInfos, atlasGroups: _paintingAtlasGroups),
|
||||
new AtlasResource("misc/explosion.png", ResourceCategory.ExplosionAtlas, 16, Resources.explosions_atlas, tilesInfo: Tiles.ExplosionTileInfos),
|
||||
new AtlasResource("item/xporb.png", ResourceCategory.ExperienceOrbAtlas, 4, Resources.experience_orbs_atlas, tilesInfo: Tiles.ExperienceOrbTileInfos),
|
||||
new AtlasResource("terrain/moon_phases.png", ResourceCategory.MoonPhaseAtlas, 4, Resources.moon_phases_atlas, tilesInfo: Tiles.MoonPhaseTileInfos),
|
||||
new AtlasResource("misc/mapicons.png", ResourceCategory.MapIconAtlas, 4, Resources.map_icons_atlas, tilesInfo: Tiles.MapIconTileInfos),
|
||||
new AtlasResource("misc/additionalmapicons.png", ResourceCategory.AdditionalMapIconsAtlas, 4, Resources.additional_map_icons_atlas, tilesInfo: Tiles.AdditionalMapIconTileInfos),
|
||||
new AtlasResource("terrain.png", AtlasResource.AtlasType.BlockAtlas, 16, Resources.terrain_atlas, tilesInfo: Tiles.BlockTileInfos, atlasGroups: _terrainAtlasGroups),
|
||||
new AtlasResource("items.png", AtlasResource.AtlasType.ItemAtlas, 16, Resources.items_atlas, tilesInfo: Tiles.ItemTileInfos, atlasGroups: _itemsAtlasGroups),
|
||||
new AtlasResource("particles.png", AtlasResource.AtlasType.ParticleAtlas, 16, Resources.particles_atlas, tilesInfo: Tiles.ParticleTileInfos, atlasGroups: _particaleAtlasGroups),
|
||||
new AtlasResource("item/banner/Banner_Atlas.png", AtlasResource.AtlasType.BannerAtlas, new Size(6, 7), Resources.banners_atlas, AtlasResource.TillingMode.XY, tilesInfo: Tiles.BannerTileInfos),
|
||||
new AtlasResource("art/kz.png", AtlasResource.AtlasType.PaintingAtlas, 16, Resources.paintings_atlas, tilesInfo: Tiles.PaintingTileInfos, atlasGroups: _paintingAtlasGroups),
|
||||
new AtlasResource("misc/explosion.png", AtlasResource.AtlasType.ExplosionAtlas, 16, Resources.explosions_atlas, tilesInfo: Tiles.ExplosionTileInfos),
|
||||
new AtlasResource("item/xporb.png", AtlasResource.AtlasType.ExperienceOrbAtlas, 4, Resources.experience_orbs_atlas, tilesInfo: Tiles.ExperienceOrbTileInfos),
|
||||
new AtlasResource("terrain/moon_phases.png", AtlasResource.AtlasType.MoonPhaseAtlas, 4, Resources.moon_phases_atlas, tilesInfo: Tiles.MoonPhaseTileInfos),
|
||||
new AtlasResource("misc/mapicons.png", AtlasResource.AtlasType.MapIconAtlas, 4, Resources.map_icons_atlas, tilesInfo: Tiles.MapIconTileInfos),
|
||||
new AtlasResource("misc/additionalmapicons.png", AtlasResource.AtlasType.AdditionalMapIconsAtlas, 4, Resources.additional_map_icons_atlas, tilesInfo: Tiles.AdditionalMapIconTileInfos),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user