Refactored Program.cs

- Introduce ResourceFiles.cs with constants for JSON resource paths.
- Updated Program.cs to use those constants.
- Refactored scene handling to store current scene in a variables.
- Added file existence checks and switch quit handling to sys.Environment.Exit.
- Updated .editorconfig.
This commit is contained in:
Tony Bark 2026-02-04 19:17:17 -05:00
parent 533e1bb076
commit 55044ae4b8
15 changed files with 172 additions and 64 deletions

View file

@ -13,9 +13,6 @@ indent_style = space
# C# files # C# files
[*.cs] [*.cs]
# Nullable reference types
csharp_nullable_reference_types = enable
# Naming conventions # Naming conventions
dotnet_naming_rule.async_methods_end_in_async.severity = suggestion dotnet_naming_rule.async_methods_end_in_async.severity = suggestion
dotnet_naming_rule.async_methods_end_in_async.symbols = async_methods dotnet_naming_rule.async_methods_end_in_async.symbols = async_methods
@ -27,6 +24,16 @@ dotnet_naming_symbols.async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.required_suffix = Async dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case dotnet_naming_style.end_in_async.capitalization = pascal_case
# Constants are UPPERCASE
dotnet_naming_rule.constants_should_be_upper_case.severity = suggestion
dotnet_naming_rule.constants_should_be_upper_case.symbols = constants
dotnet_naming_rule.constants_should_be_upper_case.style = constant_style
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.constant_style.capitalization = all_upper
# Formatting # Formatting
csharp_new_line_before_open_brace = all csharp_new_line_before_open_brace = all
csharp_indent_case_contents = true csharp_indent_case_contents = true

View file

@ -2,6 +2,7 @@
<Folder Name="/Solution Items/"> <Folder Name="/Solution Items/">
<File Path="Directory.Build.props" /> <File Path="Directory.Build.props" />
<File Path="global.json" /> <File Path="global.json" />
<File Path=".editorconfig" />
<File Path="README.md" /> <File Path="README.md" />
</Folder> </Folder>
<Project Path="Cyberbits/Cyberbits.csproj" /> <Project Path="Cyberbits/Cyberbits.csproj" />

View file

@ -1,10 +1,31 @@
namespace Cyberbits; namespace Cyberbits;
public class FileFetcher public static class FileFetcher
{ {
public static string LoadTextFile(string filename) public static string LoadTextFile(string filename, bool userDir = false)
{ {
using var file = FileAccess.Open($"res://{filename}", FileAccess.ModeFlags.Read); var location = "res";
return file.GetAsText();
if (userDir)
location = "user";
using var file = FileAccess.Open($"{location}://{filename}", FileAccess.ModeFlags.Read);
var contents = file.GetAsText();
file.Close();
return contents;
}
public static ConfigFile LoadConfig(string filename, bool userDir = false)
{
var config = new ConfigFile();
// Load data from a file.
var err = config.Load(LoadTextFile(filename, userDir));
if (err != Error.Ok)
sys.Environment.Exit(sys.Environment.ExitCode);
return config;
} }
} }

View file

@ -1,5 +1,10 @@
// System
global using System; global using System;
global using sys = System;
global using System.Text.Json; global using System.Text.Json;
global using System.Text.Json.Serialization; global using System.Text.Json.Serialization;
// Godot
global using Godot; global using Godot;
global using Godot.Collections;
global using Engine = twodog.Engine; global using Engine = twodog.Engine;

View file

@ -6,38 +6,40 @@ using var godot = engine.Start();
// Load a scene // Load a scene
var scene = GD.Load<PackedScene>("res://main.tscn"); var scene = GD.Load<PackedScene>("res://main.tscn");
engine.Tree.Root.AddChild(scene.Instantiate()); engine.Tree.Root.AddChild(scene.Instantiate());
var load = engine.Tree.CurrentScene;
var bitsImage = engine.Tree.CurrentScene.GetNode<TextureRect>("BitsImage"); var bitsImage = load.GetNode<TextureRect>("BitsImage");
var bitsSelection = engine.Tree.CurrentScene.GetNode<OptionButton>("BitsSelection"); // var bitsSelection = curScene.GetNode<OptionButton>("BitsSelection");
var unlockedFeat = engine.Tree.CurrentScene.GetNode<Label>("UnlockedFeat"); var unlockedFeatLbl = load.GetNode<Label>("UnlockedFeatLbl");
var genitalStyles = engine.Tree.CurrentScene.GetNode<ItemList>("GenitalList"); var cyberwareList = load.GetNode<ItemList>("CyberwareList");
var genitalList = load.GetNode<ItemList>("GenitalList");
// TODO: Figure out how to get this work. var baseContents = FileFetcher.LoadTextFile(ResourceFiles.COCK_JSON);
var baseContents = FileFetcher.LoadTextFile("data/cock.json"); var addonContents = FileFetcher.LoadTextFile(ResourceFiles.ADDONS_JSON);
var addonContents = FileFetcher.LoadTextFile("data/addon.json");
bitsSelection.ItemSelected += index => var screenSize = DisplayServer.ScreenGetSize();
{ var window = load.GetWindow();
baseContents = index switch window.Size = new Vector2I(screenSize.X - 66, screenSize.Y - 1);
{
1 => baseContents = FileFetcher.LoadTextFile("data/pussy.json"),
_ => baseContents = FileFetcher.LoadTextFile("data/cock.json")
};
};
if (!FileAccess.FileExists(baseContents)
|| !FileAccess.FileExists(addonContents))
sys.Environment.Exit(sys.Environment.ExitCode);
var bits = JsonSerializer.Deserialize<Bits>(baseContents); var bits = JsonSerializer.Deserialize<Bits>(baseContents);
var addon = JsonSerializer.Deserialize<Addon>(addonContents); var addon = JsonSerializer.Deserialize<Addon>(addonContents);
bitsImage.Texture.ResourcePath = bits.Image; bitsImage.Texture.ResourcePath = bits.Image;
unlockedFeat.Text = $"Feat: {bits?.Feat}"; unlockedFeatLbl.Text = $"Feat: {bits?.Feat}";
foreach (var selection in bits.Base) foreach (var selection in bits.Base)
genitalStyles.AddItem(selection); genitalList.AddItem(selection);
foreach (var cyberware in addon.Cyberware)
cyberwareList.AddItem(cyberware);
// Run the main loop // Run the main loop
while (!godot.Iteration()) while (!godot.Iteration())
{ {
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Q) if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Q)
break; sys.Environment.Exit(sys.Environment.ExitCode);
} }

View file

@ -0,0 +1,8 @@
namespace Cyberbits;
public struct ResourceFiles
{
public const string COCK_JSON = "resources/cock.json";
public const string PUSSY_JSON = "resources/pussy.json";
public const string ADDONS_JSON = "resources/addons.json";
}

View file

@ -0,0 +1 @@
hidpi = true

View file

@ -1,3 +0,0 @@
{
"cyberware": ["Piercings", "Datajack"]
}

View file

@ -1,7 +0,0 @@
{
"image": "res://sprites/cock.jpg",
"feat": "Aim Piss",
"base": ["Au Natural", "Les Americaines"],
"style": ["Bioware", "Cyberware"],
"cyberware": ["Piercings", "Datajack"]
}

View file

@ -1,6 +0,0 @@
{
"image": "res://sprites/pussy.jpg",
"feat": "Boom of the Mother Goddness",
"base": ["Au Natural", "Les Americaines"],
"style": ["Bioware", "Cyberware"]
}

View file

@ -14,10 +14,10 @@ metadata/_edit_lock_ = true
[node name="BitsImage" type="TextureRect" parent="." unique_id=420796857] [node name="BitsImage" type="TextureRect" parent="." unique_id=420796857]
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.01328125 anchor_left = 0.02578125
anchor_top = 0.023611112 anchor_top = 0.2125
anchor_right = 0.2625 anchor_right = 0.2921875
anchor_bottom = 0.49722221 anchor_bottom = 0.6861111
texture = ExtResource("1_ig7tw") texture = ExtResource("1_ig7tw")
expand_mode = 3 expand_mode = 3
metadata/_edit_use_anchors_ = true metadata/_edit_use_anchors_ = true
@ -25,35 +25,79 @@ metadata/_edit_use_anchors_ = true
[node name="GenitalList" type="ItemList" parent="." unique_id=1657021535] [node name="GenitalList" type="ItemList" parent="." unique_id=1657021535]
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.30078125 anchor_left = 0.3140625
anchor_top = 0.083333336 anchor_top = 0.29722223
anchor_right = 0.60859376 anchor_right = 0.5804688
anchor_bottom = 0.44722223 anchor_bottom = 0.6611111
select_mode = 2
metadata/_edit_use_anchors_ = true metadata/_edit_use_anchors_ = true
[node name="UnlockedFeat" type="Label" parent="." unique_id=1358090682] [node name="CyberwareList" type="ItemList" parent="." unique_id=1780192556]
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.421875 anchor_left = 0.5921875
anchor_top = 0.027777778 anchor_top = 0.2986111
anchor_right = 0.6039063 anchor_right = 0.78984374
anchor_bottom = 0.059722222 anchor_bottom = 0.6194445
metadata/_edit_use_anchors_ = true
[node name="UnlockedFeatLbl" type="Label" parent="." unique_id=1358090682]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.40546876
anchor_top = 0.23888889
anchor_right = 0.5726563
anchor_bottom = 0.27083334
text = "Feat:" text = "Feat:"
metadata/_edit_use_anchors_ = true metadata/_edit_use_anchors_ = true
[node name="BitsSelection" type="OptionButton" parent="." unique_id=1632883177] [node name="BitsSelection" type="OptionButton" parent="." unique_id=1632883177]
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.30078125 anchor_left = 0.315625
anchor_top = 0.019444445 anchor_top = 0.23055555
anchor_right = 0.3609375 anchor_right = 0.37578124
anchor_bottom = 0.07083334 anchor_bottom = 0.28194445
selected = 0 selected = 0
fit_to_longest_item = false fit_to_longest_item = false
allow_reselect = true
item_count = 2 item_count = 2
popup/item_0/text = "Dick" popup/item_0/text = "Dick"
popup/item_0/id = 0 popup/item_0/id = 0
popup/item_1/text = "Pussy" popup/item_1/text = "Pussy"
popup/item_1/id = 1 popup/item_1/id = 1
metadata/_edit_use_anchors_ = true metadata/_edit_use_anchors_ = true
[node name="CyberwareLbl" type="Label" parent="." unique_id=1646946419]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.5921875
anchor_top = 0.25277779
anchor_right = 0.7867187
anchor_bottom = 0.29166666
text = "Cyberware"
horizontal_alignment = 1
metadata/_edit_use_anchors_ = true
[node name="BioEssenceLbl" type="Label" parent="." unique_id=1183351215]
layout_mode = 0
offset_left = 759.0
offset_top = 458.0
offset_right = 877.0
offset_bottom = 481.0
text = "Bio-Essence: 10"
[node name="MegaDebtLbl" type="Label" parent="." unique_id=1875640511]
layout_mode = 0
offset_left = 896.0
offset_top = 458.0
offset_right = 1014.0
offset_bottom = 481.0
text = "Mega Debt: 10"
[node name="ActionRatingLbl" type="Label" parent="." unique_id=865651652]
layout_mode = 0
offset_left = 762.0
offset_top = 489.0
offset_right = 880.0
offset_bottom = 512.0
text = "Action Rating: 0"

View file

@ -24,6 +24,7 @@ config/features=PackedStringArray("4.6")
window/size/viewport_width=1280 window/size/viewport_width=1280
window/size/viewport_height=720 window/size/viewport_height=720
window/stretch/mode="viewport"
[dotnet] [dotnet]

View file

@ -0,0 +1,6 @@
{
"cyberware": [
"Piercings",
"Datajack"
]
}

View file

@ -0,0 +1,16 @@
{
"image": "res://sprites/cock.jpg",
"feat": "Aim Piss",
"base": [
"Au Natural",
"Les Americaines"
],
"style": [
"Bioware",
"Cyberware"
],
"cyberware": [
"Piercings",
"Datajack"
]
}

View file

@ -0,0 +1,12 @@
{
"image": "res://sprites/pussy.jpg",
"feat": "Boom of the Mother Goddness",
"base": [
"Au Natural",
"Les Americaines"
],
"style": [
"Bioware",
"Cyberware"
]
}