Add DeployToSteamOS and Procedural Dungeon Generation addons

This commit is contained in:
2024-08-22 16:51:05 -07:00
parent 6a6be038e8
commit 5c81398c83
108 changed files with 17406 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
using System.Collections.Generic;
using Godot;
namespace Laura.DeployToSteamOS;
[Tool]
public partial class AddDeviceWindow : Window
{
private bool _isVisible;
private bool _isUpdatingDevices;
private float _scanCooldown;
private List<SteamOSDevkitManager.Device> _scannedDevices = new();
private List<SteamOSDevkitManager.Device> _pairedDevices = new();
public delegate void DevicesChangedDelegate(List<SteamOSDevkitManager.Device> devices);
public event DevicesChangedDelegate OnDevicesChanged;
[ExportGroup("References")]
[Export] private VBoxContainer _devicesContainer;
[Export] private PackedScene _deviceItemPrefab;
[Export] private Button _refreshButton;
public override void _Process(double delta)
{
if (!Visible) return;
_scanCooldown -= (float)delta;
if (_scanCooldown < 0f)
{
_scanCooldown = 10f;
UpdateDevices();
UpdateDeviceList();
}
_refreshButton.Disabled = _isUpdatingDevices;
}
private async void UpdateDevices()
{
if (!Visible || _isUpdatingDevices) return;
_isUpdatingDevices = true;
var devices = await SteamOSDevkitManager.ScanDevices();
if (devices != _scannedDevices)
{
foreach (var device in devices)
{
if (
_scannedDevices.Exists(x => x.IPAdress == device.IPAdress && x.Login == device.Login)
|| _pairedDevices.Exists(x => x.IPAdress == device.IPAdress && x.Login == device.Login)
) continue;
_scannedDevices.Add(device);
}
UpdateDeviceList();
}
_isUpdatingDevices = false;
}
public void UpdateDeviceList()
{
// Clear List
foreach (var childNode in _devicesContainer.GetChildren())
{
childNode.QueueFree();
}
var devices = new List<SteamOSDevkitManager.Device>();
devices.AddRange(_pairedDevices);
foreach (var scannedDevice in _scannedDevices)
{
if (devices.Exists(x => x.IPAdress == scannedDevice.IPAdress && x.Login == scannedDevice.Login))
{
continue;
}
devices.Add(scannedDevice);
}
foreach (var scannedDevice in devices)
{
var deviceItem = _deviceItemPrefab.Instantiate<DeviceItemPrefab>();
deviceItem.SetUI(scannedDevice);
deviceItem.OnDevicePair += device =>
{
// TODO: Connect to device and run a random ssh command to check communication
if (!_pairedDevices.Exists(x => x.IPAdress == device.IPAdress && x.Login == device.Login))
{
_pairedDevices.Add(device);
}
UpdateDeviceList();
};
deviceItem.OnDeviceUnpair += device =>
{
_pairedDevices.Remove(device);
UpdateDeviceList();
};
_devicesContainer.AddChild(deviceItem);
}
}
public void Close()
{
Hide();
if (_pairedDevices != SettingsManager.Instance.Devices)
{
OnDevicesChanged?.Invoke(_pairedDevices);
}
}
public void OnVisibilityChanged()
{
if (Visible)
{
_isVisible = true;
// Prepopulate device list with saved devices
_pairedDevices = new List<SteamOSDevkitManager.Device>(SettingsManager.Instance.Devices);
UpdateDeviceList();
}
else
{
_isVisible = false;
}
}
}

View File

@@ -0,0 +1,42 @@
using Godot;
namespace Laura.DeployToSteamOS;
[Tool]
public partial class DeviceItemPrefab : PanelContainer
{
private SteamOSDevkitManager.Device _device;
public delegate void DeviceDelegate(SteamOSDevkitManager.Device device);
public event DeviceDelegate OnDevicePair;
public event DeviceDelegate OnDeviceUnpair;
[ExportGroup("References")]
[Export] private Label _deviceNameLabel;
[Export] private Label _deviceConnectionLabel;
[Export] private Button _devicePairButton;
[Export] private Button _deviceUnpairButton;
public void SetUI(SteamOSDevkitManager.Device device)
{
_device = device;
_deviceNameLabel.Text = device.DisplayName;
_deviceConnectionLabel.Text = $"{device.Login}@{device.IPAdress}";
if (SettingsManager.Instance.Devices.Exists(x => x.IPAdress == device.IPAdress && x.Login == device.Login))
{
_devicePairButton.Visible = false;
_deviceUnpairButton.Visible = true;
}
}
public void Pair()
{
OnDevicePair?.Invoke(_device);
}
public void Unpair()
{
OnDeviceUnpair?.Invoke(_device);
}
}

View File

@@ -0,0 +1,107 @@
[gd_scene load_steps=7 format=3 uid="uid://6be5afncp3nr"]
[ext_resource type="Script" path="res://addons/deploy_to_steamos/add_device_window/AddDeviceWindow.cs" id="1_3tepc"]
[ext_resource type="PackedScene" uid="uid://p64nkj5ii2xt" path="res://addons/deploy_to_steamos/add_device_window/device_item_prefab.tscn" id="2_dka1k"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mam6h"]
content_margin_left = 0.0
content_margin_top = 0.0
content_margin_right = 0.0
content_margin_bottom = 0.0
bg_color = Color(0.0666667, 0.0666667, 0.0666667, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_imdn0"]
content_margin_left = 30.0
content_margin_top = 10.0
content_margin_right = 30.0
content_margin_bottom = 10.0
bg_color = Color(0.2, 0.0823529, 0.121569, 1)
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_74135"]
content_margin_left = 15.0
content_margin_top = 15.0
content_margin_right = 15.0
content_margin_bottom = 15.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ne8al"]
content_margin_left = 30.0
content_margin_top = 10.0
content_margin_right = 30.0
content_margin_bottom = 10.0
bg_color = Color(0.133333, 0.133333, 0.133333, 1)
[node name="AddDeviceWindow" type="Window" node_paths=PackedStringArray("_devicesContainer", "_refreshButton")]
title = "Add devkit device"
initial_position = 1
size = Vector2i(650, 500)
transient = true
exclusive = true
min_size = Vector2i(650, 500)
script = ExtResource("1_3tepc")
_devicesContainer = NodePath("PanelContainer/VBoxContainer/ScrollContainer/ContentContainer/DevicesContainer")
_deviceItemPrefab = ExtResource("2_dka1k")
_refreshButton = NodePath("PanelContainer/VBoxContainer/ActionsContainer/HBoxContainer/RefreshButton")
[node name="PanelContainer" type="PanelContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_mam6h")
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 0
[node name="InfoContainer" type="PanelContainer" parent="PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_imdn0")
[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/InfoContainer"]
custom_minimum_size = Vector2(0, 10)
layout_mode = 2
theme_override_colors/font_color = Color(1, 0.788235, 0.858824, 1)
theme_override_font_sizes/font_size = 11
text = "Please keep in mind that you need to connect to your devkit device at least once through the official SteamOS devkit client to install the devkit tools to your device and create the necessary authentication keys."
autowrap_mode = 3
[node name="ScrollContainer" type="ScrollContainer" parent="PanelContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="ContentContainer" type="PanelContainer" parent="PanelContainer/VBoxContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 0
theme_override_styles/panel = SubResource("StyleBoxEmpty_74135")
[node name="DevicesContainer" type="VBoxContainer" parent="PanelContainer/VBoxContainer/ScrollContainer/ContentContainer"]
layout_mode = 2
theme_override_constants/separation = 10
[node name="ActionsContainer" type="PanelContainer" parent="PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_ne8al")
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer/ActionsContainer"]
layout_mode = 2
theme_override_constants/separation = 10
alignment = 2
[node name="RefreshButton" type="Button" parent="PanelContainer/VBoxContainer/ActionsContainer/HBoxContainer"]
layout_mode = 2
text = "Refresh"
[node name="CloseButton" type="Button" parent="PanelContainer/VBoxContainer/ActionsContainer/HBoxContainer"]
layout_mode = 2
text = "Close"
[connection signal="close_requested" from="." to="." method="Close"]
[connection signal="visibility_changed" from="." to="." method="OnVisibilityChanged"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/ActionsContainer/HBoxContainer/RefreshButton" to="." method="UpdateDevices"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/ActionsContainer/HBoxContainer/CloseButton" to="." method="Close"]

View File

@@ -0,0 +1,63 @@
[gd_scene load_steps=3 format=3 uid="uid://p64nkj5ii2xt"]
[ext_resource type="Script" path="res://addons/deploy_to_steamos/add_device_window/DeviceItemPrefab.cs" id="1_q77lw"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6g2hd"]
content_margin_left = 15.0
content_margin_top = 10.0
content_margin_right = 15.0
content_margin_bottom = 10.0
bg_color = Color(0.133333, 0.133333, 0.133333, 1)
corner_radius_top_left = 4
corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4
[node name="DeviceItemPrefab" type="PanelContainer" node_paths=PackedStringArray("_deviceNameLabel", "_deviceConnectionLabel", "_devicePairButton", "_deviceUnpairButton")]
offset_right = 532.0
offset_bottom = 51.0
theme_override_styles/panel = SubResource("StyleBoxFlat_6g2hd")
script = ExtResource("1_q77lw")
_deviceNameLabel = NodePath("HBoxContainer/VBoxContainer/DeviceNameLabel")
_deviceConnectionLabel = NodePath("HBoxContainer/VBoxContainer/DeviceConnectionLabel")
_devicePairButton = NodePath("HBoxContainer/PairButton")
_deviceUnpairButton = NodePath("HBoxContainer/UnpairButton")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/separation = 5
alignment = 1
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/separation = -5
[node name="DeviceNameLabel" type="Label" parent="HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "steamdeck"
[node name="DeviceConnectionLabel" type="Label" parent="HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_colors/font_color = Color(1, 1, 1, 0.490196)
theme_override_font_sizes/font_size = 12
text = "deck@127.0.0.1"
[node name="PairButton" type="Button" parent="HBoxContainer"]
layout_mode = 2
size_flags_vertical = 4
theme_override_constants/icon_max_width = 20
text = "Pair"
[node name="UnpairButton" type="Button" parent="HBoxContainer"]
visible = false
layout_mode = 2
size_flags_vertical = 4
theme_override_constants/icon_max_width = 20
text = "Unpair"
[connection signal="pressed" from="HBoxContainer/PairButton" to="." method="Pair"]
[connection signal="pressed" from="HBoxContainer/UnpairButton" to="." method="Unpair"]