mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-24 07:07:44 -05:00
Add item type enum & mapping, and better item color generator
Item fetches the kind of item it is, then picks out a color for the kind of item items of the same kind will have the same color, rather than randomly mapped colors :D
This commit is contained in:
parent
d69a3123e7
commit
f5ffb2477f
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
||||
|
|
@ -7,13 +7,15 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\text\en\text_villager_en.txt" />
|
||||
<None Remove="Resources\byte\item_kind.bin" />
|
||||
<None Remove="Resources\text\en\text_item_en.txt" />
|
||||
<None Remove="Resources\text\en\text_villager_en.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\text\en\text_villager_en.txt" />
|
||||
<EmbeddedResource Include="Resources\byte\item_kind.bin" />
|
||||
<EmbeddedResource Include="Resources\text\en\text_item_en.txt" />
|
||||
<EmbeddedResource Include="Resources\text\en\text_villager_en.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
BIN
NHSE.Core/Resources/byte/item_kind.bin
Normal file
BIN
NHSE.Core/Resources/byte/item_kind.bin
Normal file
Binary file not shown.
15
NHSE.Core/Structures/Item/ItemExtensions.cs
Normal file
15
NHSE.Core/Structures/Item/ItemExtensions.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
namespace NHSE.Core
|
||||
{
|
||||
public static class ItemInfo
|
||||
{
|
||||
private static readonly byte[] ItemKinds = ResourceUtil.GetBinaryResource("item_kind.bin");
|
||||
|
||||
public static ItemKind GetItemKind(Item item)
|
||||
{
|
||||
var id = item.ItemId;
|
||||
if (id > ItemKinds.Length)
|
||||
return ItemKind.Unknown;
|
||||
return (ItemKind)ItemKinds[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
144
NHSE.Core/Structures/Item/ItemKind.cs
Normal file
144
NHSE.Core/Structures/Item/ItemKind.cs
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
namespace NHSE.Core
|
||||
{
|
||||
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
|
||||
public enum ItemKind : byte
|
||||
#pragma warning restore CA1027 // Mark enums with FlagsAttribute
|
||||
{
|
||||
Bottoms_Long,
|
||||
Bottoms_Middle,
|
||||
Bottoms_Short,
|
||||
Ftr_1x1_Chair,
|
||||
Ftr_1x1_Floor,
|
||||
Ftr_2x1_Bed,
|
||||
Ftr_2x1_Floor,
|
||||
Ftr_2x2_Floor,
|
||||
Kind_Accessory,
|
||||
Kind_AutumnLeaf,
|
||||
Kind_Axe,
|
||||
Kind_Bag,
|
||||
Kind_BdayCupcake,
|
||||
Kind_BridgeItem,
|
||||
Kind_Bromide,
|
||||
Kind_Cap,
|
||||
Kind_ChangeStick,
|
||||
Kind_CliffMaker,
|
||||
Kind_CraftMaterial,
|
||||
Kind_CraftPhoneCase,
|
||||
Kind_CraftRemake,
|
||||
Kind_DIYRecipe,
|
||||
Kind_DoorDeco,
|
||||
Kind_DummyCardboard,
|
||||
Kind_DummyDIYRecipe,
|
||||
Kind_DummyFtr,
|
||||
Kind_DummyHowtoBook,
|
||||
Kind_DummyPresentbox,
|
||||
Kind_DummyRecipe,
|
||||
Kind_DummyWrapping,
|
||||
Kind_EventObjFtr,
|
||||
Kind_Fence,
|
||||
Kind_Fish,
|
||||
Kind_FishBait,
|
||||
Kind_FishToy,
|
||||
Kind_FishingRod,
|
||||
Kind_Flower,
|
||||
Kind_FlowerBud,
|
||||
Kind_FlowerSeed,
|
||||
Kind_Fossil,
|
||||
Kind_FossilUnknown,
|
||||
Kind_Fruit,
|
||||
Kind_Ftr,
|
||||
Kind_Giftbox,
|
||||
Kind_GroundMaker,
|
||||
Kind_Helmet,
|
||||
Kind_Honeycomb,
|
||||
Kind_HousePost,
|
||||
Kind_HousingKit,
|
||||
Kind_HousingKitBirdge,
|
||||
Kind_HousingKitRcoQuest,
|
||||
Kind_Insect,
|
||||
Kind_InsectToy,
|
||||
Kind_JohnnyQuest,
|
||||
Kind_JohnnyQuestDust,
|
||||
Kind_Ladder,
|
||||
Kind_LicenseItem,
|
||||
Kind_LostQuest,
|
||||
Kind_LostQuestDust,
|
||||
Kind_Medicine,
|
||||
Kind_MessageBottle,
|
||||
Kind_MilePlaneTicket,
|
||||
Kind_Money,
|
||||
Kind_Mushroom,
|
||||
Kind_Music,
|
||||
Kind_MusicMiss,
|
||||
Kind_MyDesignObject,
|
||||
Kind_MyDesignTexture,
|
||||
Kind_Net,
|
||||
Kind_NnpcRoomMarker,
|
||||
Kind_NpcOutfit,
|
||||
Kind_Ocarina,
|
||||
Kind_Ore,
|
||||
Kind_Panflute,
|
||||
Kind_PartyPopper,
|
||||
Kind_PhotoStudioList,
|
||||
Kind_PinataStick,
|
||||
Kind_PitFallSeed,
|
||||
Kind_PlayerDemoOutfit,
|
||||
Kind_Poster,
|
||||
Kind_QuestWrapping,
|
||||
Kind_RiverMaker,
|
||||
Kind_RollanTicket,
|
||||
Kind_RoomFloor,
|
||||
Kind_RoomWall,
|
||||
Kind_Rug,
|
||||
Kind_RugMyDesign,
|
||||
Kind_Sakurapetal,
|
||||
Kind_SequenceOnly,
|
||||
Kind_ShellDrift,
|
||||
Kind_ShellFish,
|
||||
Kind_Shovel,
|
||||
Kind_Slingshot,
|
||||
Kind_SlopeItem,
|
||||
Kind_SmartPhone,
|
||||
Kind_SnowCrystal,
|
||||
Kind_Socks,
|
||||
Kind_StarPiece,
|
||||
Kind_StickLight,
|
||||
Kind_TailorTicket,
|
||||
Kind_Tambourine,
|
||||
Kind_Timer,
|
||||
Kind_Trash,
|
||||
Kind_TreasureQuest,
|
||||
Kind_TreasureQuestDust,
|
||||
Kind_Tree,
|
||||
Kind_TreeSeedling,
|
||||
Kind_Turnip,
|
||||
Kind_TurnipExpired,
|
||||
Kind_Uchiwa,
|
||||
Kind_Umbrella,
|
||||
Kind_Vegetable,
|
||||
Kind_Watering,
|
||||
Kind_Weed,
|
||||
Kind_WoodenStickTool,
|
||||
Kind_WrappingPaper,
|
||||
Kind_YutaroWisp,
|
||||
Onepiece_Dress,
|
||||
Onepiece_Long,
|
||||
Onepiece_Middle,
|
||||
Onepiece_Short,
|
||||
Shoes_Boots,
|
||||
Shoes_Pumps,
|
||||
Top_Long,
|
||||
Top_Middle,
|
||||
Top_Short,
|
||||
UnitIcon_FlwAnemone,
|
||||
UnitIcon_FlwCosmos,
|
||||
UnitIcon_FlwHyacinth,
|
||||
UnitIcon_FlwLily,
|
||||
UnitIcon_FlwMum,
|
||||
UnitIcon_FlwPansy,
|
||||
UnitIcon_FlwRose,
|
||||
UnitIcon_FlwTulip,
|
||||
|
||||
Unknown = byte.MaxValue,
|
||||
}
|
||||
}
|
||||
|
|
@ -6,5 +6,5 @@ public enum ItemType
|
|||
Reserved = 1,
|
||||
Present = 2,
|
||||
Delivery = 3
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
NHSE.Parsing/GameBCSVDumper.cs
Normal file
43
NHSE.Parsing/GameBCSVDumper.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using NHSE.Core;
|
||||
|
||||
namespace NHSE.Parsing
|
||||
{
|
||||
public static class GameBCSVDumper
|
||||
{
|
||||
public static byte[] GetItemTypeArray(string pathBCSV)
|
||||
{
|
||||
var data = File.ReadAllBytes(pathBCSV);
|
||||
var bcsv = new BCSV(data);
|
||||
|
||||
var dict = bcsv.GetFieldDictionary();
|
||||
var fType = dict[0xFC275E86];
|
||||
var fID = dict[0x54706054];
|
||||
|
||||
var types = new Dictionary<ushort, ItemKind>();
|
||||
ushort max = 0;
|
||||
for (int i = 0; i < bcsv.EntryCount; i++)
|
||||
{
|
||||
var id = bcsv.ReadValue(i, fID);
|
||||
var ival = ushort.Parse(id);
|
||||
var type = bcsv.ReadValue(i, fType).TrimEnd('\0');
|
||||
|
||||
if (!Enum.TryParse<ItemKind>(type, out var k))
|
||||
throw new InvalidEnumArgumentException($"{type} is not a known enum value @ index {i}.");
|
||||
types.Add(ival, k);
|
||||
|
||||
if (ival > max)
|
||||
max = ival;
|
||||
}
|
||||
|
||||
byte[] result = new byte[max + 1];
|
||||
foreach (var kvp in types)
|
||||
result[kvp.Key] = (byte) kvp.Value;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,4 +5,8 @@
|
|||
<LangVersion>8</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NHSE.Core\NHSE.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Drawing;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using NHSE.Core;
|
||||
using NHSE.Sprites.Properties;
|
||||
|
||||
|
|
@ -21,11 +22,7 @@ public class ItemSpriteDrawer : IGridItem
|
|||
|
||||
public Image CreateFake(Item item, Font font)
|
||||
{
|
||||
var scramble = item.ItemId * 17;
|
||||
var b = scramble & 0xFF;
|
||||
var g = (scramble >> 8) & 0xFF;
|
||||
var color = Color.FromArgb(b, g, b);
|
||||
|
||||
var color = GetItemColor(item);
|
||||
var bmp = new Bitmap(Width, Height);
|
||||
using Graphics gfx = Graphics.FromImage(bmp);
|
||||
using SolidBrush brush = new SolidBrush(color);
|
||||
|
|
@ -43,5 +40,26 @@ public Image CreateFake(Item item, Font font)
|
|||
gfx.DrawString(item.Flags2.ToString(), font, Brushes.Black, 20, 20);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private static Color GetItemColor(Item item)
|
||||
{
|
||||
var kind = ItemInfo.GetItemKind(item);
|
||||
if (kind == ItemKind.Unknown)
|
||||
return Color.LimeGreen;
|
||||
var known = Colors[(int)kind];
|
||||
var color = Color.FromKnownColor(known);
|
||||
// soften the colors a little
|
||||
return Blend(Color.White, color, 0.5d);
|
||||
}
|
||||
|
||||
public static Color Blend(Color color, Color backColor, double amount)
|
||||
{
|
||||
byte r = (byte)((color.R * amount) + (backColor.R * (1 - amount)));
|
||||
byte g = (byte)((color.G * amount) + (backColor.G * (1 - amount)));
|
||||
byte b = (byte)((color.B * amount) + (backColor.B * (1 - amount)));
|
||||
return Color.FromArgb(r, g, b);
|
||||
}
|
||||
|
||||
private static readonly KnownColor[] Colors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using FluentAssertions;
|
||||
using NHSE.Core;
|
||||
using NHSE.Parsing;
|
||||
using Xunit;
|
||||
|
||||
namespace NHSE.Tests
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user