using Godot; using System; using Babushka.scripts.CSharp.Common.Minigame; using Godot.Collections; public partial class RegionVisual : Node { [Export] private Sprite2D _sliceSprite; [Export] private Label _textLabel; [Export] private Node2D _labelPivot; [Export(PropertyHint.DictionaryType)] private Dictionary _fillColors = new(); public override void _EnterTree() { //_sliceSprite.Material = new Material() } public void Setup(Vector2 normalAngles, Color color, string regionText, MinigameController.RegionTheme regionTheme) { var mat = (_sliceSprite.Material as ShaderMaterial)!; mat.SetShaderParameter("angles", normalAngles); mat.SetShaderParameter("fillColor", GetFillColor(regionTheme)); var averageAngleRadians = (normalAngles.X + normalAngles.Y) * float.Pi; // '/ 2' from the average and '* 2' from the radians cancel out _labelPivot.Rotation = averageAngleRadians; _textLabel.Rotation = -averageAngleRadians; _textLabel.Text = regionText; } private Color GetFillColor(MinigameController.RegionTheme theme) { if (_fillColors.TryGetValue(theme, out var color)) return color; throw new InvalidOperationException($"No fill color for theme {theme}"); } }