Add backbone for card creation and implement Camera minigame mechanics
This commit is contained in:
203
Assets/Scripts/Data/CardSystem/CardVisualConfig.cs
Normal file
203
Assets/Scripts/Data/CardSystem/CardVisualConfig.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptableObject containing visual configuration for card display
|
||||
/// Maps card rarities to colors and zones to colors/shapes
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "CardVisualConfig", menuName = "Apple Hills/Card System/Visual Config")]
|
||||
public class CardVisualConfig : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class RarityColorMapping
|
||||
{
|
||||
public CardRarity rarity;
|
||||
public Color color = Color.white;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ZoneVisualMapping
|
||||
{
|
||||
public CardZone zone;
|
||||
public Color color = Color.white;
|
||||
public Sprite backgroundShape;
|
||||
}
|
||||
|
||||
[Header("Rarity Configuration")]
|
||||
[Tooltip("Color mappings for different card rarities")]
|
||||
[SerializeField] private List<RarityColorMapping> rarityColors = new List<RarityColorMapping>();
|
||||
|
||||
[Header("Zone Configuration")]
|
||||
[Tooltip("Visual mappings for different card zones")]
|
||||
[SerializeField] private List<ZoneVisualMapping> zoneVisuals = new List<ZoneVisualMapping>();
|
||||
|
||||
private Dictionary<CardRarity, Color> _rarityColorLookup;
|
||||
private Dictionary<CardZone, Color> _zoneColorLookup;
|
||||
private Dictionary<CardZone, Sprite> _zoneShapeLookup;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the lookup dictionaries when the asset is loaded
|
||||
/// </summary>
|
||||
private void OnEnable()
|
||||
{
|
||||
InitializeLookups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the lookup dictionaries from the serialized lists
|
||||
/// </summary>
|
||||
private void InitializeLookups()
|
||||
{
|
||||
// Build rarity color lookup
|
||||
_rarityColorLookup = new Dictionary<CardRarity, Color>();
|
||||
foreach (var mapping in rarityColors)
|
||||
{
|
||||
_rarityColorLookup[mapping.rarity] = mapping.color;
|
||||
}
|
||||
|
||||
// Build zone color and shape lookups
|
||||
_zoneColorLookup = new Dictionary<CardZone, Color>();
|
||||
_zoneShapeLookup = new Dictionary<CardZone, Sprite>();
|
||||
|
||||
foreach (var mapping in zoneVisuals)
|
||||
{
|
||||
_zoneColorLookup[mapping.zone] = mapping.color;
|
||||
_zoneShapeLookup[mapping.zone] = mapping.backgroundShape;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the color for a specific card rarity
|
||||
/// </summary>
|
||||
public Color GetRarityColor(CardRarity rarity)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_rarityColorLookup == null)
|
||||
{
|
||||
InitializeLookups();
|
||||
}
|
||||
|
||||
// Return the color if found, otherwise white
|
||||
if (_rarityColorLookup.TryGetValue(rarity, out Color color))
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"[CardVisualConfig] No color mapping found for rarity {rarity}, using default");
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the color for a specific card zone
|
||||
/// </summary>
|
||||
public Color GetZoneColor(CardZone zone)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_zoneColorLookup == null)
|
||||
{
|
||||
InitializeLookups();
|
||||
}
|
||||
|
||||
// Return the color if found, otherwise white
|
||||
if (_zoneColorLookup.TryGetValue(zone, out Color color))
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"[CardVisualConfig] No color mapping found for zone {zone}, using default");
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the background shape sprite for a specific zone
|
||||
/// </summary>
|
||||
public Sprite GetZoneShape(CardZone zone)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_zoneShapeLookup == null)
|
||||
{
|
||||
InitializeLookups();
|
||||
}
|
||||
|
||||
// Return the sprite if found, otherwise null
|
||||
if (_zoneShapeLookup.TryGetValue(zone, out Sprite sprite))
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"[CardVisualConfig] No shape mapping found for zone {zone}");
|
||||
return null;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Editor-only utility to reset the config with default values
|
||||
/// </summary>
|
||||
public void ResetWithDefaults()
|
||||
{
|
||||
// Clear existing mappings
|
||||
rarityColors.Clear();
|
||||
zoneVisuals.Clear();
|
||||
|
||||
// Add default rarity colors
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Common, color = Color.gray });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Uncommon, color = Color.green });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Rare, color = Color.blue });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Epic, color = new Color(0.5f, 0, 0.5f) });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Legendary, color = Color.yellow });
|
||||
|
||||
// Add default zone colors
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.AppleHills,
|
||||
color = new Color(0.8f, 0.9f, 0.8f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Quarry,
|
||||
color = new Color(0.85f, 0.8f, 0.7f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Forest,
|
||||
color = new Color(0.6f, 0.8f, 0.6f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Mountain,
|
||||
color = new Color(0.7f, 0.7f, 0.9f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Beach,
|
||||
color = new Color(0.9f, 0.85f, 0.7f)
|
||||
});
|
||||
|
||||
// Initialize the lookups
|
||||
InitializeLookups();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(CardVisualConfig))]
|
||||
public class CardVisualConfigEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
CardVisualConfig config = (CardVisualConfig)target;
|
||||
|
||||
UnityEditor.EditorGUILayout.Space();
|
||||
if (GUILayout.Button("Reset with Defaults"))
|
||||
{
|
||||
config.ResetWithDefaults();
|
||||
UnityEditor.EditorUtility.SetDirty(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user