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);
var (posPx, sizePx) = Util.PixelizeNote(pos, size);
var noteCtrPos = posPx + sizePx / 2;
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;
}
}
// reposition
var p = Position;
p.X = -Size.X / 2 + noteCtrPos;
Position = p;
// 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;
}
}
}
+2 -6
View File
@@ -13,12 +13,7 @@ namespace WacK.Things.TunnelObjects
shader = (ShaderMaterial) Material;
}
public void SetCW(bool isCW)
{
shader.SetShaderParameter("isCw", isCW);
}
public void SetPosSize(int pos, int size)
public void Init(int pos, int size, bool isCW)
{
var p = Position;
var s = Size;
@@ -39,6 +34,7 @@ namespace WacK.Things.TunnelObjects
Position = p;
Size = s;
shader.SetShaderParameter("TileMult", s.Y / 64);
shader.SetShaderParameter("isCw", isCW);
}
}
}
+3 -13
View File
@@ -14,14 +14,6 @@ namespace WacK.Things.TunnelObjects
{
this.noteData = noteData;
SetPosSize((int)noteData.pos, (int)noteData.size);
// handle swipe arrow color
if (noteData.type == NotePlayType.SwipeCW)
{
var n = (SwipeArrow) FindChild("SwipeArrow");
// n.SetCW(noteData.type == NotePlayType.SwipeCW);
n.CallDeferred("SetCW", noteData.type == NotePlayType.SwipeCW);
}
}
public void SetPosSize(int pos, int size)
@@ -44,19 +36,17 @@ namespace WacK.Things.TunnelObjects
nSize.X = sizePx;
noteBase.SetDeferred("size", nSize);
// handle swipe arrow pos & size
// handle swipe arrow
if (noteData.type == NotePlayType.SwipeCW || noteData.type == NotePlayType.SwipeCCW)
{
var n = (SwipeArrow) FindChild("SwipeArrow");
// n.SetPosSize(pos, size);
n.CallDeferred("SetPosSize", pos, size);
n.CallDeferred("Init", pos, size, noteData.type == NotePlayType.SwipeCW);
}
// handle snap arrow pos & size
// handle snap arrow
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);
}
}