Files
PCK-Studio/PckStudio.Core/ResourceLocation.cs
Miku-666 8dfe9cf5b0 3d skin renderer (#50)
* Add 'Validate Skin Dimension' setting

* AddNewSkin - Fix cape box not showing after skin selection

* Extended ResourceLocation for better atlas handling

* ModelImporter - Add block bench export for models inside models.bin

* ModelIporter - Rename 'GetPivot' to 'GetSkinBoxPivot'

* ModelImporter - Fix ANIM2BOX to properly support slim skin models

* ModelImporter - Update BedrockModel json class

* ModelImporter - Update 'FixTexture' to be more generic

* Update ModelContainer API inside OMI-Lib

* Update skin vertex shader to not swap yz

* Update CubeMesh class

* SkinRenderer - Move framebuffer and error checking function to SceneViewport

* SceneViewport - Change OnUpdate parameter

* SkinRenderer - Fix Highlight part having wrong transform

* SkinRenderer - Move call to 'SwapBuffers' into SceneViewport.OnUpdate

* AppSettingsForm - Update API to be more flexible

* SkinBOXExtensions - Update 'GetUVGraphicsPath'

* SkinRenderer - Update 'OnUpdate' function

* SkinRenderer - Add 'LockMousePosition' option

* CustomSkinEditor - Update HighlightlingColor when selecting a part

* CustomSkinEditor - Add render settings

* CustomSkinEditor - Small non-technical changes

* SkinRenderer - Small non-technical changes

* CustomSkinEditor - Load render settings when 'OnLoad' is called

* SkinRenderer - Fix centering leg0/1

* SkinRenderer - Update 'ReInitialzeSkinData' to upload new data to shader

* Rename 'ModelImporter' -> 'SkinModelImporter' and add api interface to add custom import/export providers

* CubeGroupMesh - Fix overlay parts not showing proerly

* SkinRenderer - Fix part highlighting respecting inflate

* Split up model and skin importer into seperate classes and improved api

* IModelImportProvider - Add 'SupportImport' and 'SupportExport' property fields

* ModelImporter - Rename 'SimpleSkinImportProvider' to 'InternalImportProvider'

* modelTextureLocations.json - Add todo

* SkinModelImporter - Move 'ModelTextureLocations' to GameModelImporter

* CustomSkinEditor - Add SettingsManager for RenderSettings

* ModelImporter::Import - Check if file exists

* Rename 'modelTextureLocations' to 'modelMetaData'

* GameModelImporter - Change blockbench name when exporting

* SettingsManager - Add functionality to create internal settings object and add settings to it

* GameModelImporter - Fully implemented game-model export to block bench

* AppSettingsForm - Fix re-adding settings description to default settings

* AppSettingsForm - Add settings description to 'ValidateImageDimension'

* GameModelImporter - Add copyright notice and remove unnecessary using statements

* ModelImporter - Add copyright notice and remove unnecessary using statements

* BlockBenchModel - Fix Texture class json deserialization

* SkinModelImporter - Add 'TryConvertToSkinBoxType' function

* modelMetaData - Remove comments

* SkinModelImporter - Fix 'GetSkinBoxPivot' function

* SkinModelImporter - Add null check in 'FixTexture' function

* SkinModelImporter - Add offset detection when importing skin model

* CustomSkinEditor - Add 'export template' button

* GameModelImporter - Rename 'ModelTextureLocations' -> 'ModelMetaData'

* ModelImporter - Add summary to 'SupportedModelFileFormatsFilter' property

* GameModelImporter - Change function signature of 'CreateElement'

* GameModelImporter - Add options to create root outline

* GameModelImporter - Update Debug message in 'TraverseChildren'

* MainForm - Small code refactor

* Rename class 'Meta' ->'BlockBenchFormatInfo' and update BlockBenchModel.Create function signature

* MainForm - Update 'GetModelTextures' local function

* GameModelImporter - Check model metadata before conversion

* GameModelInfo - Mark class as sealed

* SkinModelImporter - Check if blockbench model uses box uv

* BlockBenchModel - Add export property to class 'Element'

* CustomSkinEditor - Remove unused 'PreviewImage' property

* CustomSkinEditor - Change highlight color on texture

* SkinModelImporter - Fix Block Bench Model import

* modelMetaData - Add meta data for 1.14 models

* SkinModelImporter - Update 'TryConvertToSkinBoxType' function

* SkinModelExporter - Fix model export for bbmodel and bedrock model

* SkinRenderer - Fix order of applying anim animations to match the game

* SkinModelImporter - Fix exception thrown in 'FixTexture'

* CustomSkinEditor - Add Anim editor button and fix anim not being updated when exporting

* SkinModelImporter - Fix offset detection when importing

* SkinModelImporter - Swap box bottom texture when texture is available

* GameModelImporter - Sort using statements

* SkinModelImporter - Small code clean up inside 'ImportBedrockJson'

* SkinModelImporter - Update 'AddBone' function inside 'ExportBedrockJson'

* SkinModelImporter - Fix bottom texture swaping being done bofre parts where imported

* SkinMoelImporter - Rename 'GetSkinBoxPivot' to 'GetSkinPartPivot'

* SceneViewport - Rename 'Init' to 'Initialize'

* SkinModelImporter - Add texture import in 'ImportBedrockJson'

* SkinModelImporter - Fix becrock model import

* Skin-/GameModelImporter - Rename 'fileName' parameter to 'filepath'

* Add ModelEditor

* modelMetaData - Add cavespider texture location

* GameModelImporter - Update 'ExportBlockBenchModel' function

* GameModelImporter - Mark 'ModelExportSettings' as sealed

* ModelEditor -Add Save tool menu item & add TrySetTexture Delegate

* ModelEditor - Add model node icons

* Update CubeMesh & rename CubeGroupMesh to CubeMeshCollection

* ModelEditor - Rename 'GetModelNodes' & 'GetModelPartNodeChildren'

* Update GenericMesh & mesh rendering

* Move Cube conversion into SkinBOXExtensions

* GenericMesh - Made 'Transform' property abstract

* SceneViewport - Add shaderLibrary and api to it

* Rename 'skin...' shaders to 'texturedCube...'

* Update modelMetaData part hierarchy structure

* ShaderProgram - Add 'SetUniform2' overload for System.Drawing.Size

* ModelEditor - Create factory methods for custom model treenodes

* modelMetaData - Add 'slime.armor' texture location & pattern texture locations for 'tropicalfish_-a/-b'

* Move Debug & Camera control into SceneViewport

* Update BoundingBox

* Add ModelRenderer

* ShaderProgram - Update GetUniformLocation to retrive all active uniforms when linking program

* ModelEditor - Add option to show bounding box of the model

* SceneViewport - Add OnPaint override to clear color and depth buffer and enable depth testing

* Update OMI submodule

* Update  Texture base class to accept slot when calling Bind

* Plain color fragment shader - Update uniform names to be PascalCase

* SceneViewport - Add 'ResetCamera' virtual function

* CustomSkinEditor - Add missing render setting 'Show Armor'

* ModelRenderer - Fix centering model after selecting

* Move 'SceneViewport.GetBounds' to 'BoundingBox.GetEnclosingBoundingBox'

* CubeMeshCollection - Implemented 'GetBounds'

* SkinRenderer - Add option to show skins bounding box

* ModelEditor - Update 'GetModelImageIndex'

* SceneViewport - Disable blend when rendering debug graphics

* ModelEditor - Remove 'Model' property in favor to 'LoadModel' function

* JsonModelMetaData - Initialize 'RootParts' to empty array

* BoundingBox - Fix exception when empty enumerable was passed

* CubeMesh - Remove 'SetName' and add constructor with 'name' parameter

* SkinBOX - Change class to record & make member properties getter only

* BoundingBox - Move 'Abs' function into extension class

* SceneViewport - Change 'Transform' to 'GetTransform'

* BoundingBox - Make 'GetVertices' static & add GetTransform

* SkinRenderer - Fix bounds calculation when offset is set & fix part highlighting

* CubeMesh - Move translation & scaling into 'GetTransform'

* CubeMeshCollection - Update 'Contains' overload function & 'SetVisible'

* ModelRenderer - Fix pivot point rendering

* ModelRenderer - Add part highlighting

* modelMetaData - Add missing part to dolphin

* modelMetaData - Add missing parts to dragon

* CubeMesh - Fix 'GetTransform' function

* ModelRenderer - Fix model rotation, pivot & translation issues

* ModelRenderer - Add offset to render transform & camera

* ModelRenderer - Tried fixing alpha rendering issues

* modelMetaData - Add missing part to dragon & add comment

* Add 'ITryGetSet.cs' and useful wrappers for it

* ModelRenderer - Rename 'HighlightInfo.Pivot' to 'HighlightInfo.Translation'

* ITryGetSet - mark classes and interfaces public

* ModelEditor - Add material render support

* ModelRenderer - Add 'TryGetModelMetaData' method

* Fix rendering invisible vertecies

* ModelRenderer - Simplefied populating 'metaData.RootParts' property

* ModelRenderer - Add 'modelOffset' field

* ModelRenderer - Update 'SetModelMaterial'

* ModelRenderer - Add simple way of rendering a 2nd layer of a model(the bed model only for now)

* ModelRenderer - Fix pivot points not working on horse model properly

* ResourceLocation - Add 'Unknown' ResourceLocation instance & improved 'ResourceLocation.GetFromPath'

* ResourceCategory - Add 'MobEntityTextures' & 'ItemEntityTextures'

* Add default model handling (defaults unfinished)

* Add Default Bed model

* Add default chicken model

* Add default cow model

* AddSkinPrompt - Fix Custom skin editor not having anim flag properly set

* SceneViewport - Fix Designer crashing when trying to call 'OnPaint'

* Update OMI submodule

* SceneViewport - Call 'base.OnMouseUp' before our own code

* BlockBenchModel - Fix 'Texture.Name' being null

* ItemSelectionPopUp - Fix 'okBtn_Click' condition

* MainForm - Add export function for default models

* MainForm - Fix model selector ignoring cancel button

* MainForm - Remove unnecessary wrapper for 'entityMaterials.TryGetValue'

* ModelEditor - Add remove model to context menu

* ModelEditor - Add 'GetModelContainer' function

* GameModelImporter - Add import functionality

* MainForm - Add texture when exporting default models

* Add default model for: redcow, pig, snowgolem & dragon head

* Add SkinModel & SkinIdentifier class

* Refactor Skin.cs
- Move texture from 'SkinModel' to Skin.cs
- Move 'Id' from SkinMetaData into it's own class(SkinIdentifier.cs)
- Create SkinModelInfo class for keeping skin conversion simple

* Skin.cs - Rename 'ANIM' property to 'Anim'

* Move 'hasInvalidEntries' into 'MaterialExtensions.HasInvalidEntries'

* Add ISaveContext

* PckAssetExt - Rename parameter names for 'GetSkin'

* Add Editor.cs

* Update most editors to use new Editor class and save context

* CustomSkinEditor - Use Editor as base class

* SkinMetaData - Change to Immutable data type

* PckAssetExtension - [SetSkin] Change adding loc key to setting loc key

* ImageDeserializer - Add format check when deserializing

* MainForm - [HandleSkinFile] Rename some varibale names

* ModelEditor - Use Editor as base class

* Move static variables from 'ModelPartSpecifics' to 'GameConstants'

* Texture.cs - Add IDisposable interface

* PckAssetExtensions - [SetSkin] Add null check for loc file

* AnimationEditor - Fix auto save check

* TextureAtlasEditor - Refactor animation access control

* TextureAtlasEditor - Sort using directives

* MainForm - [HandleTextureFile] Add Debug message when animation has no frames to save

* AddSkinPrompt - Update save context for custom skin editor

* Editor - Move autosave check in 'OnFormClosing'

* ModelRenderer - Update designer specifics

* Merge 'multi-pck-files-feature' into '3dSkinRenderer'

* [WIP] Sub-pck in new tab with savecontext etc.

* SceneViewport - Change base refresh rate to 60 fps

* CustomSkinEditor - Move max offset value into a constant

* ModelEditor - Add highlighting of sinfgle model boxes

* MainForm - Add constant for max pck id value

* CustomSkinEditor - Remove fps slider and re-ordered ui

* EditorForm - Remove abstract from class declaration

* EditorControl - Made virtual funtion throw `NotImplementedException`

* CustomSkinEditor - Fix naming violations

* CustomSkinEditor - Move initialization of render settings into a seperate funtion & remove `show armor` setting

* Move Common functionality to Core project & rendering and Model support as well

* Change namespace of EditorForm & EditorControl

* Add Constant 'NDEBUG' to Core, Rendering & ModelSupport project

* PckStudio.csproj - Remove `defaultModels.json` & `modelMetaData.json`
- files were moved to PckStuido.ModelSupport

* PckStudio.csproj - Remove unused `ApplicationBuildInfo.cs`

* PckStudio.Core - Add NamedData.cs

* PckStudio - Move some Resources to Core

* Add Altas class & refactored Atlas editor

* Update OMI Submodule

* TextureAtlasEditor - Fix clear button not reseting color

* Fix PackInfo.cs - OMI.Endianess -> OMI.ByteOrder

* TextureAtlas - Impl extraction&import of large tiles

* PckStudio.Core - Remove duplicated resources

* LOCEditor - Added menu item for copying loc id

* Core - Move 'MAX_PACK_ID' into GameConstants

* TextureAtlasEditor - small refactor + TODOs

* Update OMI submodule ref
2025-11-11 21:53:32 +01:00

209 lines
14 KiB
C#

/* Copyright (c) 2024-present miku-666
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1.The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using PckStudio.Core.Json;
using PckStudio.Json;
namespace PckStudio.Core
{
public sealed class ResourceLocation
{
private static List<ResourceLocation> ResourceGroups = new List<ResourceLocation>();
private static readonly ResourceLocation Unknown = new ResourceLocation(string.Empty, ResourceCategory.Unknown, -1);
private static AtlasGroup[] _particaleAtlasGroups =
{
new AtlasGroupAnimation("generic" , row: 0, column: 0, frameCount: 8, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("splash" , row: 3, column: 1, frameCount: 4, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("drip" , row: 0, column: 7, frameCount: 3, ImageLayoutDirection.Horizontal, 4),
new AtlasGroupAnimation("effect" , row: 0, column: 8, frameCount: 8, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("splash_effect" , row: 0, column: 9, frameCount: 8, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("firework_spark" , row: 0, column: 10, frameCount: 8, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("glitter" , row: 0, column: 11, frameCount: 8, ImageLayoutDirection.Horizontal, 2),
new AtlasGroupAnimation("BE_explosion" , row: 0, column: 12, frameCount: 16, ImageLayoutDirection.Horizontal),
new AtlasGroupLargeTile("flash" , row: 4, column: 2, rowSpan: 4, columnSpan: 4),
new AtlasGroupLargeTileAnimation("bubble_pop", row: 6, column: 6, rowSpan: 2, columnSpan: 2, frameCount: 5, ImageLayoutDirection.Horizontal, 2),
};
private static AtlasGroup[] _terrainAtlasGroups =
{
new AtlasGroupLargeTile("Oak Door" , row: 1, column: 5, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Iron Door" , row: 2, column: 5, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Acacia Door" , row: 0, column: 23, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Birch Door" , row: 1, column: 23, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Dark Oak Door", row: 2, column: 23, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Jungle Door" , row: 3, column: 23, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Spruce Door" , row: 4, column: 23, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Large Fern" , row: 0, column: 20, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Double Tall Grass", row: 1, column: 20, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Poeny" , row: 2, column: 20, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Rose Bush" , row: 3, column: 20, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Lilac" , row: 4, column: 20, rowSpan: 1, columnSpan: 2),
new AtlasGroupAnimation("Wheat" , row: 8, column: 5, frameCount: 8, ImageLayoutDirection.Horizontal, 5),
new AtlasGroupAnimation("Potatoes" , row: 9, column: 16, frameCount: 4, ImageLayoutDirection.Horizontal, 5),
new AtlasGroupAnimation("Carrots" , row: 8, column: 12, frameCount: 4, ImageLayoutDirection.Horizontal, 5),
new AtlasGroupAnimation("Beetroots" , row: 0, column: 25, frameCount: 4, ImageLayoutDirection.Horizontal, 5),
new AtlasGroupAnimation("Nether Wart", row: 2, column: 14, frameCount: 3, ImageLayoutDirection.Horizontal, 5),
new AtlasGroupAnimation("Destroy" , row: 0, column: 15, frameCount: 10, ImageLayoutDirection.Horizontal, 3),
};
private static AtlasGroup[] _itemsAtlasGroups =
{
new AtlasGroupAnimation("Bow Pulling", row: 5, column: 6, frameCount: 3, ImageLayoutDirection.Vertical, 6),
};
private static AtlasGroup[] _paintingAtlasGroups =
{
new AtlasGroupLargeTile("The Pool" , row: 0, column: 2, rowSpan: 2, columnSpan: 1),
new AtlasGroupLargeTile("Bonjour Monsiuer Courbet", row: 2, column: 2, rowSpan: 2, columnSpan: 1),
new AtlasGroupLargeTile("Seaside" , row: 4, column: 2, rowSpan: 2, columnSpan: 1),
new AtlasGroupLargeTile("sunset_dense" , row: 6, column: 2, rowSpan: 2, columnSpan: 1),
new AtlasGroupLargeTile("Creebet" , row: 8, column: 2, rowSpan: 2, columnSpan: 1),
new AtlasGroupLargeTile("Wanderer" , row: 0, column: 4, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Graham" , row: 1, column: 4, rowSpan: 1, columnSpan: 2),
new AtlasGroupLargeTile("Fighters" , row: 0, column: 6, rowSpan: 4, columnSpan: 2),
new AtlasGroupLargeTile("Match" , row: 0, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("Bust" , row: 2, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("The stage is set" , row: 4, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("The Void" , row: 6, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("Skull and Roses" , row: 8, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("Wither" , row: 10, column: 8, rowSpan: 2, columnSpan: 2),
new AtlasGroupLargeTile("Mortal Coil" , row: 12, column: 4, rowSpan: 4, columnSpan: 3),
new AtlasGroupLargeTile("Kong" , row: 12, column: 7, rowSpan: 4, columnSpan: 3),
new AtlasGroupLargeTile("Back Texture" , row: 12, column: 0, rowSpan: 4, columnSpan: 4),
new AtlasGroupLargeTile("Pointer" , row: 0, column: 12, rowSpan: 4, columnSpan: 4),
new AtlasGroupLargeTile("Pigscene" , row: 4, column: 12, rowSpan: 4, columnSpan: 4),
new AtlasGroupLargeTile("Skull On Fire" , row: 8, column: 12, rowSpan: 4, columnSpan: 4),
};
private static readonly Dictionary<string, ResourceLocation> _categoryLookUp = new Dictionary<string, ResourceLocation>()
{
["textures/items"] = new ResourceLocation("textures/items", ResourceCategory.ItemAnimation, 16, isGroup: true),
["textures/blocks"] = new ResourceLocation("textures/blocks", ResourceCategory.BlockAnimation, 16, isGroup: true),
["mob"] = new ResourceLocation("mob", ResourceCategory.MobEntityTextures, 1, isGroup: true),
["item"] = new ResourceLocation("item", ResourceCategory.ItemEntityTextures, 1, isGroup: true),
["terrain.png"] = new ResourceLocation("terrain.png", ResourceCategory.BlockAtlas, 16, tilesInfo: Tiles.BlockTileInfos, atlasGroups: _terrainAtlasGroups),
["items.png"] = new ResourceLocation("items.png", ResourceCategory.ItemAtlas, 16, tilesInfo: Tiles.ItemTileInfos, atlasGroups: _itemsAtlasGroups),
["particles.png"] = new ResourceLocation("particles.png", ResourceCategory.ParticleAtlas, 16, tilesInfo: Tiles.ParticleTileInfos, atlasGroups: _particaleAtlasGroups),
//============ TODO ============//
["item/banner/Banner_Atlas.png"] = new ResourceLocation("item/banner/Banner_Atlas.png", ResourceCategory.BannerAtlas, new Size(6, 7), TillingMode.WidthAndHeight, tilesInfo: Tiles.BannerTileInfos),
//==============================//
["art/kz.png"] = new ResourceLocation("art/kz.png", ResourceCategory.PaintingAtlas, 16, tilesInfo: Tiles.PaintingTileInfos, atlasGroups: _paintingAtlasGroups),
["misc/explosion.png"] = new ResourceLocation("misc/explosion.png", ResourceCategory.ExplosionAtlas, 16, tilesInfo: Tiles.ExplosionTileInfos),
["item/xporb.png"] = new ResourceLocation("item/xporb.png", ResourceCategory.ExperienceOrbAtlas, 4, tilesInfo: Tiles.ExperienceOrbTileInfos),
["terrain/moon_phases.png"] = new ResourceLocation("terrain/moon_phases.png", ResourceCategory.MoonPhaseAtlas, 4, tilesInfo: Tiles.MoonPhaseTileInfos),
["misc/mapicons.png"] = new ResourceLocation("misc/mapicons.png", ResourceCategory.MapIconAtlas, 4, tilesInfo: Tiles.MapIconTileInfos),
["misc/additionalmapicons.png"] = new ResourceLocation("misc/additionalmapicons.png", ResourceCategory.AdditionalMapIconsAtlas, 4, tilesInfo: Tiles.AdditionalMapIconTileInfos),
};
public static string GetPathFromCategory(ResourceCategory category)
{
return category switch
{
ResourceCategory.ItemAnimation => _categoryLookUp["textures/items"].ToString(),
ResourceCategory.BlockAnimation => _categoryLookUp["textures/blocks"].ToString(),
ResourceCategory.MobEntityTextures => _categoryLookUp["mob"].ToString(),
ResourceCategory.ItemEntityTextures => _categoryLookUp["item"].ToString(),
ResourceCategory.BlockAtlas => _categoryLookUp["terrain.png"].ToString(),
ResourceCategory.ItemAtlas => _categoryLookUp["items.png"].ToString(),
ResourceCategory.ParticleAtlas => _categoryLookUp["particles.png"].ToString(),
ResourceCategory.BannerAtlas => _categoryLookUp["item/banner/Banner_Atlas.png"].ToString(),
ResourceCategory.PaintingAtlas => _categoryLookUp["art/kz.png"].ToString(),
ResourceCategory.ExplosionAtlas => _categoryLookUp["misc/explosion.png"].ToString(),
ResourceCategory.ExperienceOrbAtlas => _categoryLookUp["item/xporb.png"].ToString(),
ResourceCategory.MoonPhaseAtlas => _categoryLookUp["terrain/moon_phases.png"].ToString(),
ResourceCategory.MapIconAtlas => _categoryLookUp["misc/mapicons.png"].ToString(),
ResourceCategory.AdditionalMapIconsAtlas => _categoryLookUp["misc/additionalmapicons.png"].ToString(),
_ => string.Empty
};
}
public static ResourceCategory GetCategoryFromPath(string path) => GetFromPath(path).Category;
public static ResourceLocation GetFromPath(string path)
{
if (string.IsNullOrWhiteSpace(path) || !path.StartsWith("res/"))
return Unknown;
string categoryPath = path.Substring("res/".Length);
if (_categoryLookUp.ContainsKey(categoryPath))
return _categoryLookUp[categoryPath];
return ResourceGroups.Where(group => categoryPath.StartsWith(group.Path)).FirstOrDefault() ?? Unknown;
}
public enum TillingMode
{
Width,
Height,
WidthAndHeight
}
public string Path { get; }
public ResourceCategory Category { get; }
public Size TillingFactor { get; }
public TillingMode Tilling { get; }
public bool IsGroup { get; }
public IEnumerable<JsonTileInfo> TilesInfo { get; }
public IEnumerable<AtlasGroup> AtlasGroups { get; }
public Size GetTileArea(Size imgSize)
{
return Tilling 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),
_ => Size.Empty,
};
}
private ResourceLocation(string path, ResourceCategory category, int tillingFactor, TillingMode tilling = TillingMode.Width, bool isGroup = false, IEnumerable<JsonTileInfo> tilesInfo = default, IEnumerable<AtlasGroup> atlasGroups = default)
: this(path, category, new Size(tillingFactor, tillingFactor), tilling, isGroup, tilesInfo, atlasGroups)
{
}
private ResourceLocation(string path, ResourceCategory category, Size tillingFactor, TillingMode tilling = TillingMode.Width, bool isGroup = false, IEnumerable<JsonTileInfo> tilesInfo = default, IEnumerable<AtlasGroup> atlasGroups = default)
{
Path = path;
Category = category;
TillingFactor = new Size(Math.Max(1, tillingFactor.Width), Math.Max(1, tillingFactor.Height));
Tilling = tilling;
IsGroup = isGroup;
TilesInfo = tilesInfo ?? Enumerable.Empty<JsonTileInfo>();
AtlasGroups = atlasGroups ?? Enumerable.Empty<AtlasGroup>();
if (isGroup)
ResourceGroups.Add(this);
}
public override string ToString()
{
return "res/" + Path;
}
}
}