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;
}
}
+13 -3
View File
@@ -19,7 +19,8 @@ namespace WacK.Things.TunnelObjects
if (noteData.type == NotePlayType.SwipeCW)
{
var n = (SwipeArrow) FindChild("SwipeArrow");
n.SetCW(noteData.type == NotePlayType.SwipeCW);
// n.SetCW(noteData.type == NotePlayType.SwipeCW);
n.CallDeferred("SetCW", noteData.type == NotePlayType.SwipeCW);
}
}
@@ -43,11 +44,20 @@ namespace WacK.Things.TunnelObjects
nSize.X = sizePx;
noteBase.SetDeferred("size", nSize);
// handle swipe arrow size
// handle swipe arrow pos & size
if (noteData.type == NotePlayType.SwipeCW || noteData.type == NotePlayType.SwipeCCW)
{
var n = (SwipeArrow) FindChild("SwipeArrow");
n.SetPosSize(pos, size);
// n.SetPosSize(pos, size);
n.CallDeferred("SetPosSize", pos, size);
}
// handle snap arrow pos & size
if (noteData.type == NotePlayType.SnapIn || noteData.type == NotePlayType.SnapOut)
{
var n = (SnapArrows)FindChild("SnapArrows");
// n.SetPosSize(pos, size);
n.CallDeferred("Init", pos, size, noteData.type == NotePlayType.SnapIn);
}
}
}