tested version with most of the final functionality. Still a few known issues, like dragging to a row that extends to multiple lines

This commit is contained in:
2024-04-24 18:18:03 -05:00
parent f67885d217
commit e25e7da40f
25 changed files with 568 additions and 56 deletions

47
game.cs
View File

@@ -3,6 +3,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
@@ -16,6 +17,14 @@ public partial class game : Control
return _SettingsPopup;
}
}
private create_menu_popup _CreateMenuPopup;
private create_menu_popup CreateMenuPopup
{ get
{
_CreateMenuPopup ??= GetNode<create_menu_popup>("%CreateMenuPopup");
return _CreateMenuPopup;
}
}
[Export]
private Vector2 _CardSize = new(200, 200);
public Vector2 CardSize
@@ -77,10 +86,24 @@ public partial class game : Control
}
else
{
CreateMenuPopup.ClosePopup();
SettingsPopup.ShowPopup();
}
GetViewport().SetInputAsHandled();
}
else if (@event.IsActionPressed("CreationMenu"))
{
if (CreateMenuPopup.Visible)
{
CreateMenuPopup.ClosePopup();
}
else
{
SettingsPopup.ClosePopup();
CreateMenuPopup.ShowPopup();
}
GetViewport().SetInputAsHandled();
}
}
public void Clear()
{
@@ -109,6 +132,7 @@ public partial class game : Control
var node = GetNode<VBoxContainer>("%RowContainer");
node.AddChild(row);
node.MoveChild(row, index);
PropogateCardSize();
}
public void RemoveRow(string id)
{
@@ -175,17 +199,25 @@ public partial class game : Control
}
public void ImportGame(string filename)
{
GD.Print($"Importing from {filename}");
Serializer.LoadFromSerial(this,
File.ReadAllText(filename)
using var reader = new StreamReader(
new DeflateStream(
new FileStream(filename, FileMode.Open),
CompressionMode.Decompress
)
);
var s = reader.ReadToEnd();
Serializer.LoadFromSerial(this, s);
}
public void ExportGame(string filename, ExportSettings es)
{
GD.Print($"Exporting to {filename}");
File.WriteAllText(filename,
Serializer.CreateGameJson(this, es)
using var writer = new StreamWriter(
new DeflateStream(
new FileStream(filename, FileMode.OpenOrCreate),
CompressionLevel.Optimal
)
);
var json = Serializer.CreateGameJson(this, es);
writer.Write(json);
}
#region Commands
public void MoveCard(string cardId, string targetRowId, int? toIndex = null)
@@ -244,8 +276,7 @@ public partial class game : Control
}
public void CreateRow(Color? color = null, string title = null)
{
var scn = GD.Load<PackedScene>("res://row.tscn");
var r = scn.Instantiate() as row;
var r = row.MakeRow(GetTree());
if (!string.IsNullOrWhiteSpace(title))
r.RowText = title;
if (color is Color color1)