forked from openairlinetycoon/OpenATDeluxe
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Game File Loading/Saving System - Refractor of the GFXLibrary and File
WARNING WIP - THERE WILL BE BUGS MAJOR UPDATE TODO: Try to reduce the file size - more the 7 times the game size is a bit much.... Added a saving and loading system for the ATD images. Now loads all files from the game and saves it to our project when used in the editor. It will save all ATD files to a .pck when it's a standalone build. That .pck will be loaded into the game for later use. Added a loading scene, for picking the path to your ATD install. Changed the main scene, from the base scene to the loading scene. Added textures for testing purposes to the base scene. Changed the system behind getting the textures from the GFXLibrary - now you have to use GFXFile.GetTexture() to retrieve a chacheble texture Updated the README Updated the background color to black, the window size to Full HD and the resizing method to stretch.
- Loading branch information
1 parent
4b1c04a
commit 5018c10
Showing
12 changed files
with
427 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,5 +269,7 @@ ATD/ | |
SDL*/ | ||
source_code_win/ | ||
BASE/ | ||
BUILDS/ | ||
.import/ | ||
.mono/ | ||
Images/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[preset.0] | ||
|
||
name="Windows Desktop" | ||
platform="Windows Desktop" | ||
runnable=true | ||
custom_features="" | ||
export_filter="scenes" | ||
export_files=PoolStringArray( "res://Properties/AssemblyInfo.cs", "res://default_env.tres", "res://icon.png", "res://scenes/base.tscn", "res://scenes/load.tscn", "res://src/GFXLibrary.cs", "res://src/MouseCursor.cs", "res://src/RoomManager.cs" ) | ||
include_filter="" | ||
exclude_filter="" | ||
export_path="P:/Projekte/Major Games/OpenATD/BUILDS/oATD.exe" | ||
patch_list=PoolStringArray( ) | ||
script_export_mode=1 | ||
script_encryption_key="" | ||
|
||
[preset.0.options] | ||
|
||
texture_format/bptc=false | ||
texture_format/s3tc=true | ||
texture_format/etc=false | ||
texture_format/etc2=false | ||
texture_format/no_bptc_fallbacks=true | ||
binary_format/64_bits=true | ||
custom_template/release="" | ||
custom_template/debug="" | ||
application/icon="" | ||
application/file_version="" | ||
application/product_version="" | ||
application/company_name="" | ||
application/product_name="" | ||
application/file_description="" | ||
application/copyright="" | ||
application/trademarks="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
[gd_scene load_steps=2 format=2] | ||
[gd_scene load_steps=5 format=2] | ||
|
||
[ext_resource path="res://src/MouseCursor.cs" type="Script" id=1] | ||
[ext_resource path="res://Images/gli/buero_a/BUERO.tres" type="Texture" id=2] | ||
[ext_resource path="res://Images/gli/buero_a/LETTERS.tres" type="Texture" id=3] | ||
[ext_resource path="res://Images/gli/buero_a/NOSABO.tres" type="Texture" id=4] | ||
|
||
[node name="BaseGameController" type="Node2D"] | ||
[node name="Game" type="Node2D"] | ||
|
||
[node name="MOUSE" type="Sprite" parent="."] | ||
position = Vector2( 494.348, 30.5995 ) | ||
|
||
[node name="Mouse" type="Sprite" parent="."] | ||
position = Vector2( 366.758, 207.202 ) | ||
z_index = 999 | ||
centered = false | ||
script = ExtResource( 1 ) | ||
pathToAirlineTycoonD = "..\\BASE\\ATD" | ||
|
||
[node name="buero" type="Sprite" parent="."] | ||
position = Vector2( 965.744, 539.596 ) | ||
scale = Vector2( 2.44196, 2.44196 ) | ||
texture = ExtResource( 2 ) | ||
|
||
[node name="letters" type="Sprite" parent="buero"] | ||
position = Vector2( 69.4884, 176.542 ) | ||
texture = ExtResource( 3 ) | ||
|
||
[node name="nosabo" type="Sprite" parent="buero"] | ||
position = Vector2( 107.3, 110.007 ) | ||
texture = ExtResource( 4 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://src/ATDGameLoader.cs" type="Script" id=1] | ||
|
||
[node name="Node2D" type="Node2D"] | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Title" type="Sprite" parent="."] | ||
position = Vector2( 937.422, 541.914 ) | ||
scale = Vector2( 2.24936, 2.24936 ) | ||
|
||
[node name="FileDialog" type="FileDialog" parent="."] | ||
margin_left = 685.0 | ||
margin_top = 388.863 | ||
margin_right = 1239.0 | ||
margin_bottom = 710.863 | ||
window_title = "Verzeichnis wählen" | ||
dialog_text = "Select Path" | ||
mode = 2 | ||
access = 2 | ||
current_dir = "P:/Projekte/Major Games/OpenATD" | ||
current_path = "P:/Projekte/Major Games/OpenATD/" | ||
|
||
[node name="DirectoryInvalid" type="AcceptDialog" parent="."] | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
margin_left = 731.76 | ||
margin_top = 511.715 | ||
margin_right = 1178.76 | ||
margin_bottom = 569.715 | ||
resizable = true | ||
dialog_text = "\"INVALID PATH CHOSEN, CAN'T FIND glbasis.gli IN SUBFOLDER gli!\"" | ||
|
||
[node name="LoadInfo" type="Label" parent="."] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = 261.299 | ||
margin_top = 1036.08 | ||
margin_right = 318.299 | ||
margin_bottom = 1050.08 | ||
rect_scale = Vector2( 2, 2 ) | ||
custom_colors/font_color = Color( 0.290196, 0.92549, 0, 1 ) | ||
custom_colors/font_color_shadow = Color( 0.0313726, 0.137255, 0.027451, 1 ) | ||
text = "Loading.." | ||
align = 3 | ||
valign = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
using Godot; | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using Directory = System.IO.Directory; | ||
using Thread = System.Threading.Thread; | ||
|
||
public class ATDGameLoader : Node { | ||
public Label loadInfo; | ||
public FileDialog selectATDPath; | ||
public AcceptDialog directoryInvalidDialog; | ||
|
||
static Dictionary<string, List<GFXLibrary>> libraryFolders; | ||
|
||
[Export] | ||
bool forceRebuild = false; | ||
bool isInEditor; | ||
|
||
static volatile string currentFolder; | ||
static volatile string currentLibrary; | ||
static volatile string currentFile; | ||
|
||
// Called when the node enters the scene tree for the first time. | ||
public override void _Ready() { | ||
loadInfo = GetNode<Label>("LoadInfo"); | ||
|
||
isInEditor = Engine.EditorHint; | ||
|
||
if (forceRebuild || (!System.IO.File.Exists("ATDFiles.pck")) || !Directory.Exists(ProjectSettings.GlobalizePath("res://Images"))) { | ||
selectATDPath = GetNode<FileDialog>("FileDialog"); //Get the path to the ATD install | ||
selectATDPath.Connect("dir_selected", this, nameof(ChoseFile)); | ||
selectATDPath.PopupCentered(new Vector2(500, 500)); | ||
|
||
directoryInvalidDialog = GetNode<AcceptDialog>("DirectoryInvalid"); | ||
directoryInvalidDialog.Connect("confirmed", this, nameof(AcceptDialog)); | ||
} else { //If there is no need for a rebuild, just skip asking | ||
if (!isInEditor) { | ||
ProjectSettings.LoadResourcePack("ATDFiles.pck"); //If we are not in the editor: we need to add the ATDFiles | ||
} | ||
GetTree().ChangeScene("res://scenes/base.tscn"); | ||
} | ||
} | ||
|
||
public void ChoseFile(string dir) { | ||
if (!System.IO.File.Exists(dir + "/gli/glbasis.gli")) { //Basic check to see if we are inside the ATD folder | ||
GD.PrintErr("INVALID PATH CHOSEN, CAN'T FIND glbasis.gli IN SUBFOLDER gli!"); | ||
directoryInvalidDialog.PopupCentered(); | ||
return; | ||
} | ||
|
||
GFXLibrary.pathToAirlineTycoonD = dir; | ||
|
||
Thread t = new Thread(LoadData); | ||
t.Name = "DataLoader"; | ||
|
||
t.Start(); | ||
} | ||
|
||
public void AcceptDialog() { | ||
selectATDPath.PopupCentered(new Vector2(500, 500)); //try try and try again | ||
} | ||
|
||
public override void _Process(float delta) { | ||
loadInfo.SetText("Loading: " + currentFolder + "/" + currentLibrary + "/" + currentFile); | ||
} | ||
|
||
private void LoadData() { | ||
libraryFolders = new Dictionary<string, List<GFXLibrary>>(); //A list of graphic folders of the game | ||
libraryFolders.Add("room", new List<GFXLibrary>()); | ||
libraryFolders.Add("gli", new List<GFXLibrary>()); | ||
|
||
foreach (var folderKVP in libraryFolders) { | ||
string folderName = folderKVP.Key; | ||
List<GFXLibrary> folderGFXList = folderKVP.Value; | ||
|
||
currentFolder = folderName; | ||
|
||
//Load up all GFX files in the directory | ||
string[] files = System.IO.Directory.GetFiles(GFXLibrary.pathToAirlineTycoonD + "/" + folderName); | ||
foreach (string f in files) { | ||
if (f.EndsWith(".gli")) { | ||
var lib = new GFXLibrary(GFXLibrary.pathToAirlineTycoonD + "/" + folderName + "/" + System.IO.Path.GetFileName(f)); | ||
lib.GetFilesInLibrary(); | ||
|
||
folderGFXList.Add(lib); | ||
} | ||
} | ||
} | ||
|
||
|
||
GetNode<Sprite>("Title").SetTexture( | ||
libraryFolders["room"] | ||
.Find((lib) => lib.name == "titel2").files | ||
.Find((f) => f.name.Trim('\0') == "TITEL").GetTexture()); | ||
|
||
|
||
//Write them to disk | ||
ExportImages(!System.IO.File.Exists("ATDFiles.pck") && !isInEditor); | ||
|
||
//Should only be needed when we are not in the editor, but adding it doesnt hurt us, even if the file isn't present | ||
bool s = ProjectSettings.LoadResourcePack("ATDFiles.pck"); | ||
GetTree().ChangeScene("res://scenes/base.tscn"); | ||
} | ||
|
||
private void ExportImages(bool packFiles) { | ||
PCKPacker p = new PCKPacker(); | ||
|
||
|
||
if (packFiles) //Should we pack them up? Only needed when we are not inside the editor | ||
p.PckStart("ATDFiles.pck", 4); | ||
|
||
|
||
string basePath = ProjectSettings.GlobalizePath("res://Images"); //Get an absolute Path to our project/executable folder | ||
string baseGodotPath = "res://Images"; | ||
|
||
if (!Directory.Exists(basePath)) | ||
Directory.CreateDirectory(basePath); | ||
|
||
|
||
foreach (var folderKVP in libraryFolders) { | ||
List<GFXLibrary> librarys = folderKVP.Value; | ||
string libraryName = folderKVP.Key; | ||
|
||
SaveLibrarysInList(packFiles, p, basePath + "/" + libraryName, baseGodotPath + "/" + libraryName, librarys); | ||
} | ||
if (packFiles) | ||
p.Flush(true); | ||
} | ||
|
||
private static void SaveLibrarysInList(bool packFiles, PCKPacker p, string basePath, string baseGodotPath, List<GFXLibrary> librarys) { | ||
foreach (var lib in librarys) { | ||
string libPath = basePath + "/" + lib.name; | ||
string libGodotPath = baseGodotPath + "/" + lib.name; | ||
|
||
currentLibrary = lib.name; | ||
|
||
if (!Directory.Exists(libPath)) | ||
Directory.CreateDirectory(libPath); | ||
|
||
SaveFiles(packFiles, p, lib, libPath, libGodotPath); | ||
} | ||
} | ||
|
||
private static void SaveFiles(bool packFiles, PCKPacker p, GFXLibrary lib, string libPath, string libGodotPath) { | ||
foreach (GFXLibrary.GFXFile file in lib.files) { | ||
string fileName = file.name.Trim('\0') + ".tres"; | ||
string filePath = libPath + "/" + fileName; | ||
string fileGodotPath = libGodotPath + "/" + fileName; | ||
|
||
currentFile = fileName; | ||
|
||
GD.Print(filePath); | ||
GD.Print(fileGodotPath); | ||
|
||
ResourceSaver.Save(filePath, file.GetTexture(), (int)ResourceSaver.SaverFlags.Compress); | ||
|
||
if (packFiles) | ||
p.AddFile(fileGodotPath, filePath); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.