forgot to commit for a while

This commit is contained in:
2024-04-21 15:43:32 -05:00
parent 885bc5ad6e
commit 3ac7bf33c4
18 changed files with 1607 additions and 38 deletions

99
game.cs
View File

@@ -18,6 +18,10 @@ public partial class game : Control
PropogateCardSize();
}
}
public void SetCardSize(Vector2 size)
{
CardSize = size;
}
protected void PropogateCardSize()
{
foreach (var r in GetNode("%RowContainer").GetChildren().OfType<row>())
@@ -36,7 +40,7 @@ public partial class game : Control
{
var c = card.MakeCard(GetTree());
GD.Print(c.CardId);
c.CardName = $"Card {i}";
c.CardName = $"Card {c.CardId}";
if (GD.RandRange(0, 1) == 1)
{
//add to a row
@@ -49,7 +53,7 @@ public partial class game : Control
}
}
PropogateCardSize();
}
// public override void _UnhandledInput(InputEvent @event)
@@ -166,4 +170,95 @@ public partial class game : Control
}
return RemoveUnassignedCard(id);
}
public card FindCard(string id)
{
if (string.IsNullOrWhiteSpace(id))
return null;
foreach (var c in this.GetAllDescendents<card>())
if (c.CardId == id)
return c;
return null;
}
public row FindRow(string id)
{
foreach (var r in this.GetAllDescendents<row>())
if (r.RowId == id)
return r;
return null;
}
#region Commands
public void MoveCard(string cardId, string targetRowId, int? toIndex = null)
{
var r = FindRow(targetRowId);
if (r is null)
throw new Exception($"row {r.RowId} not found");
var c = ClaimCard(cardId);
if (c is null)
throw new Exception($"card {c.CardId} not found");
r.AddCard(c, toIndex);
}
public void MoveRow(string rowId, int toIndex)
{
var r = FindRow(rowId);
if (r is null)
throw new Exception($"row {r.RowId} not found");
//TODO what if out of range?
r.GetParent().MoveChild(r, toIndex);
}
public void DeleteCards(params string[] cardId)
{
//don't claim any cards unless all of them are found
if (!cardId.Select(FindCard).All(x => x is not null))
throw new Exception("not all cards found");
foreach (var c in cardId.Select(ClaimCard))
{
c.QueueFree();
}
}
public void DeleteRow(string rowId, bool deleteCards = false)
{
var r = FindRow(rowId);
if (r is null)
throw new Exception($"row {r.RowId} not found");
}
public void CreateCard(string title = null, Image image = null)
{
var scn = GD.Load<PackedScene>("res://card.tscn");
var c = scn.Instantiate() as card;
if (!string.IsNullOrWhiteSpace(title))
c.CardName = title;
if (image is not null)
c.SetTexture(ImageTexture.CreateFromImage(image));
AddUnassignedCard(c);
}
public void CreateRow(Color? color = null, string title = null)
{
var scn = GD.Load<PackedScene>("res://row.tscn");
var r = scn.Instantiate() as row;
if (!string.IsNullOrWhiteSpace(title))
r.RowText = title;
if (color is Color color1)
r.RowColor = color1;
}
public void RenameCard(string cardId, string newName)
{
}
public void RenameRow(string rowId, string newTitle)
{
}
public void RecolorRow(string rowId, Color color)
{
}
public void ChangeCardImage(string cardId, Image image)
{
var c = FindCard(cardId);
if (c is null)
throw new Exception($"card {c.CardId} not found");
c.SetTexture(ImageTexture.CreateFromImage(image));
}
#endregion //Commands
}