refactoring

This commit is contained in:
msk
2023-10-11 02:57:24 -07:00
parent b282dd21cd
commit 3685a9e680
3 changed files with 48 additions and 59 deletions
+43 -40
View File
@@ -3,55 +3,58 @@ using System;
using System.Linq;
using WacK;
public partial class SnapArrows : HBoxContainer
namespace WacK.Things.TunnelObjects
{
private TextureRect[] arrows = new TextureRect[20];
// Called when the node enters the scene tree for the first time.
public override void _Ready()
public partial class SnapArrows : HBoxContainer
{
var c = GetChildren();
for(int i = 0; i < 20; ++i)
{
arrows[i] = (TextureRect) c[i];
}
}
private TextureRect[] arrows = new TextureRect[20];
/// <summary>
/// Make sure to run as CallDeferred if constructing!
/// </summary>
/// <param name="pos"></param>
/// <param name="size"></param>
/// <param name="isIn"></param>
public void Init(int pos, int size, bool isIn)
{
var nVis = Math.Clamp(size / 3, 1, 20);
for(int i = 0; i < arrows.Count(); ++i)
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
if (i < nVis)
var c = GetChildren();
for(int i = 0; i < 20; ++i)
{
arrows[i].Visible = true;
((ShaderMaterial)arrows[i].Material)
.SetShaderParameter("isIn", isIn);
}
else
{
arrows[i].Visible = false;
arrows[i] = (TextureRect) c[i];
}
}
// shrink
var s = Size;
s.X = 0;
Size = s;
/// <summary>
/// Make sure to run as CallDeferred if constructing!
/// </summary>
/// <param name="pos"></param>
/// <param name="size"></param>
/// <param name="isIn"></param>
public void Init(int pos, int size, bool isIn)
{
var nVis = Math.Clamp(size / 3, 1, 20);
for(int i = 0; i < arrows.Count(); ++i)
{
if (i < nVis)
{
arrows[i].Visible = true;
((ShaderMaterial)arrows[i].Material)
.SetShaderParameter("isIn", isIn);
}
else
{
arrows[i].Visible = false;
}
}
var (posPx, sizePx) = Util.PixelizeNote(pos, size);
var noteCtrPos = posPx + sizePx / 2;
// shrink
var s = Size;
s.X = 0;
Size = s;
// reposition
var p = Position;
p.X = -Size.X / 2 + noteCtrPos;
Position = p;
var (posPx, sizePx) = Util.PixelizeNote(pos, size);
var noteCtrPos = posPx + sizePx / 2;
// reposition
var p = Position;
p.X = -Size.X / 2 + noteCtrPos;
Position = p;
}
}
}