Preserve current state before big refactor

This commit is contained in:
2025-02-05 20:45:49 -08:00
parent 4910ff7770
commit badc6d2375
65 changed files with 2356 additions and 113 deletions

View File

@@ -0,0 +1,108 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
namespace Laura.DeployToSteamOS;
[Tool]
public partial class DeployDock : PanelContainer
{
private int _selectedId = 10000;
[Export] private OptionButton _deployTargetButton;
[Export] private Button _deployButton;
[Export] private AddDeviceWindow _addDeviceWindow;
[Export] private DeployWindow _deployWindow;
public override void _EnterTree()
{
_addDeviceWindow.OnDevicesChanged += OnDevicesChanged;
}
public override void _ExitTree()
{
_addDeviceWindow.OnDevicesChanged -= OnDevicesChanged;
}
public override void _Ready()
{
UpdateDropdown();
}
public void OnDeployTargetItemSelected(int index)
{
var itemId = _deployTargetButton.GetItemId(index);
if (_selectedId == itemId) return;
if (itemId <= 10000)
{
_selectedId = itemId;
}
else if (itemId == 10001)
{
_addDeviceWindow.Show();
}
_deployTargetButton.Select(_deployTargetButton.GetItemIndex(_selectedId));
_deployButton.Disabled = _selectedId >= 10000;
}
public void Deploy()
{
var device = SettingsManager.Instance.Devices.ElementAtOrDefault(_selectedId);
if (device == null)
{
GD.PrintErr("[DeployToSteamOS] Unknown deploy target.");
return;
}
// TODO: Detect Export Presets and stop if no Linux preset named "Steamdeck" exists
_deployWindow.Deploy(device);
}
private void OnDevicesChanged(List<SteamOSDevkitManager.Device> devices)
{
// Adding Devices
var devicesToAdd = devices.Where(device => !SettingsManager.Instance.Devices.Exists(x => x.IPAdress == device.IPAdress && x.Login == device.Login)).ToList();
foreach (var device in devicesToAdd)
{
SettingsManager.Instance.Devices.Add(device);
}
// Removing Devices
var devicesToRemove = SettingsManager.Instance.Devices.Where(savedDevice => !devices.Exists(x => x.IPAdress == savedDevice.IPAdress && x.Login == savedDevice.Login)).ToList();
foreach (var savedDevice in devicesToRemove)
{
SettingsManager.Instance.Devices.Remove(savedDevice);
}
SettingsManager.Instance.Save();
UpdateDropdown();
}
private async void UpdateDropdown()
{
// Hack to prevent console error
// Godot apparently calls this before the settings are loaded
while (SettingsManager.Instance == null)
{
await Task.Delay(10);
}
_deployTargetButton.Clear();
_deployTargetButton.AddItem("None", 10000);
for (var index = 0; index < SettingsManager.Instance.Devices.Count; index++)
{
var savedDevice = SettingsManager.Instance.Devices.ElementAtOrDefault(index);
if(savedDevice == null) continue;
_deployTargetButton.AddItem($"{savedDevice.DisplayName} ({savedDevice.Login}@{savedDevice.IPAdress})", index);
}
_deployTargetButton.AddSeparator();
_deployTargetButton.AddItem("Add devkit device", 10001);
}
}

View File

@@ -0,0 +1 @@
uid://0kau18vff4u2

View File

@@ -0,0 +1,54 @@
[gd_scene load_steps=6 format=3 uid="uid://kdbpdei4v1ub"]
[ext_resource type="Script" path="res://addons/deploy_to_steamos/deploy_dock/DeployDock.cs" id="1_atc6e"]
[ext_resource type="Texture2D" uid="uid://s1tcpal4iir4" path="res://addons/deploy_to_steamos/icon.svg" id="2_rpj28"]
[ext_resource type="PackedScene" uid="uid://6be5afncp3nr" path="res://addons/deploy_to_steamos/add_device_window/add_device_window.tscn" id="3_qfyb3"]
[ext_resource type="PackedScene" uid="uid://ds2umdqybfls8" path="res://addons/deploy_to_steamos/deploy_window/deploy_window.tscn" id="4_8y8co"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ebqha"]
content_margin_left = 10.0
[node name="DeployDock" type="PanelContainer" node_paths=PackedStringArray("_deployTargetButton", "_deployButton", "_addDeviceWindow", "_deployWindow")]
offset_right = 337.0
offset_bottom = 32.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxEmpty_ebqha")
script = ExtResource("1_atc6e")
_deployTargetButton = NodePath("HBoxContainer/DeployTargetButton")
_deployButton = NodePath("HBoxContainer/DeployButton")
_addDeviceWindow = NodePath("AddDeviceWindow")
_deployWindow = NodePath("DeployWindow")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="DeployTargetButton" type="OptionButton" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
item_count = 3
selected = 0
popup/item_0/text = "None"
popup/item_0/id = 10000
popup/item_1/text = ""
popup/item_1/id = -1
popup/item_1/separator = true
popup/item_2/text = "Add devkit device"
popup/item_2/id = 10001
[node name="DeployButton" type="Button" parent="HBoxContainer"]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
disabled = true
icon = ExtResource("2_rpj28")
icon_alignment = 1
expand_icon = true
[node name="AddDeviceWindow" parent="." instance=ExtResource("3_qfyb3")]
visible = false
[node name="DeployWindow" parent="." instance=ExtResource("4_8y8co")]
visible = false
[connection signal="item_selected" from="HBoxContainer/DeployTargetButton" to="." method="OnDeployTargetItemSelected"]
[connection signal="pressed" from="HBoxContainer/DeployButton" to="." method="Deploy"]