finish snap notes

This commit is contained in:
msk
2023-10-11 02:47:31 -07:00
parent 033ec8ab30
commit b282dd21cd
5 changed files with 237 additions and 55 deletions
+44 -2
View File
@@ -1,15 +1,57 @@
using Godot;
using System;
using System.Linq;
using WacK;
public partial class SnapArrows : HBoxContainer
{
private TextureRect[] arrows = new TextureRect[20];
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
var c = GetChildren();
for(int i = 0; i < 20; ++i)
{
arrows[i] = (TextureRect) c[i];
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
/// <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;
}
}
// shrink
var s = Size;
s.X = 0;
Size = s;
var (posPx, sizePx) = Util.PixelizeNote(pos, size);
var noteCtrPos = posPx + sizePx / 2;
// reposition
var p = Position;
p.X = -Size.X / 2 + noteCtrPos;
Position = p;
}
}