openairlinetycoon / OpenATDeluxe

The open source remake of Airline Tycoon Deluxe
GNU General Public License v3.0
104 stars 13 forks source link

Image Management System #4

Open Serphentas opened 5 years ago

Serphentas commented 5 years ago

Initially started by @WizzardMaker

We need a system to easily access all needed files and their textures. A central place where all GFXLibs are loaded and we have a template system with objects/scenes for all files, or maybe use an editor for a level with a saved level file for loading

Serphentas commented 5 years ago

I think we could make our job much easier by creating a toolkit which reads data from GLI containers and outputs standard JPG/PNG/whatever images, which can later be easily read without having to do fancy conversion all over the place.

Perhaps do this once on load and fill the game folder with these recovered files, or ship the game with them from the start ?

WizzardMaker commented 5 years ago

Yeah, I thought about it. Problem is, we aren't allowed to upload the game files. This project would be killed in seconds because of copyright issues.

I don't know how Godot handles images on build and whether we can exclude them in the build and load new ones during start up. But it's rather easy to extract all files. I already have them and it's an easy step to save as PNG in Godot.

Serphentas commented 5 years ago

Indeed for copyright issues we can't include them. I'll work on a patch that automatically creates local files on the first start.

WizzardMaker commented 5 years ago

It seems that it will be a bit more cumbersome to be able to use the atd files in godot I experimented a bit to find out whether there is a way to exclude textures from a build to prevent us from sharing the game files with a release build, but it seems godot doesn't like that. You can't exclude a texture, you can't use proxy textures, as they will just import the file from the external path

You can define the texture yourself though and maybe make a "build" tool to remove the texture content before a build and then let the game code reimport them later on. We would need to fill each and every texture in the game before we could access them though. Load the texture based on the file name from the godot intern texture from our *.png directory

Kinda how I do now for testing. Have a Sprite script attached to each ATD Sprite and when we are not in the editor, replace the texture data from the current texture with the texture data from the corresponding .png file

WizzardMaker commented 5 years ago

Okay, problem solved!

We now can Import all images from the game into godot and use them like normal sprites! I wrote a game loader which will create godot texture files. Those can be used inside godot. Before you can build the game for the public, you have to run a cleaner script, which will remove all the image data (temporarily), export the game and restore the data again. The exported game just needs the ATD files and will make a .pck file from those. This .pck will replace all the empty image files.

I have to clean a bit of the code before I commit it but it should be ready!

Serphentas commented 5 years ago

I was actually working on a loader/saver function as well, hope we're not in code conflict now. But yeah, generally speaking load when needed from disk so as to avoid builds with redundant data.

Serphentas commented 5 years ago

Would you like me to commit to a different branch maybe ?

WizzardMaker commented 5 years ago

Sure! There shouldn't be any major conflict though. All in one lonely file on my end. But yes please, show me your approach!

Serphentas commented 5 years ago

Just commited here https://github.com/WizzardMaker/OpenATDeluxe/tree/4-save-glibs

WizzardMaker commented 5 years ago

as to avoid builds with redundant data

Yeah I can see the reason behind that. A problem with your approach is that we don't really have that good of a use case for the godot editor anymore. There is overhead with my approach and there is room for improvement, but with it we have the ability to fully use the editor with all game sprites showing up.

We should check for a way to maybe combine our approaches.

It also seems like you are missing a loading method right now on your branch, its only saving the files as png and then never using it.

Serphentas commented 5 years ago

Yeah there's no loading in my code. Actually I didn't want to make a potential merge leading to much conflicts, but now there's your code I can do just that.

Serphentas commented 5 years ago

Upon loading with your code, I get:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at ATDGameLoader.LoadData () [0x0011c] in /home/xerxes/Documents/coding/OpenATDeluxe/src/ATDGameLoader.cs:91 
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
  at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 

I replaced all statics paths from your system with mine, if that helps.

WizzardMaker commented 5 years ago

Seems like it can't either apply the loading screen texture, maybe due to a missing node, or it can't find the appropriate texture file.

It's probably because you have a different game version, which doesn't have the "newer" loading screen (though I probably shouldn't have used the newer one...)

There are in theory 2 title "rooms", title and title2. try to change in line 100 of the ATDGameLoader.cs file the lib.name == "titel2" to lib.name == "titel" That should fix it

EDIT: Oh and there shouldn't™ be any static paths anymore. The Folder Dialog in the beginning should ask for the path to your ATD folder and load all necessary files from that.

Serphentas commented 5 years ago

It actually worked with "titel" up until I pulled your last commit, then

Assertion failed: Room not found! Room: RoomAirport
  at Godot.GodotTraceListener.Fail (System.String message, System.String detailMessage) [0x00032] in /tmp/build_GodotSharp/GodotSharp/Core/GodotTraceListener.cs:28 
  at System.Diagnostics.TraceListener.Fail (System.String message) [0x00000] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Diagnostics.TraceInternal.Fail (System.String message) [0x00000] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Diagnostics.TraceInternal.Assert (System.Boolean condition, System.String message) [0x00000] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Diagnostics.Debug.Assert (System.Boolean condition, System.String message) [0x00000] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at RoomManager.ChangeRoom (System.String newRoomName, System.Boolean isAirport) [0x0000d] in /home/xerxes/Documents/coding/OpenATDeluxe/src/RoomManager.cs:41 
  at RoomManager._Ready () [0x0006e] in /home/xerxes/Documents/coding/OpenATDeluxe/src/RoomManager.cs:31 

Unhandled Exception:
System.Collections.Generic.KeyNotFoundException: The given key 'RoomAirport' was not present in the dictionary.
  at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
  at RoomManager.ChangeRoom (System.String newRoomName, System.Boolean isAirport) [0x0007f] in /home/xerxes/Documents/coding/OpenATDeluxe/src/RoomManager.cs:51 
  at RoomManager._Ready () [0x0006e] in /home/xerxes/Documents/coding/OpenATDeluxe/src/RoomManager.cs:31 

Bare with me, the Godot learning curve isn't kind. :p

EDIT: Tried doing a forced reload of game files but still getting the same error at runtime.

Serphentas commented 5 years ago

I got it somewhat working again, although I don't see the mouse cursor anymore:

foreach (string file_path in System.IO.Directory.GetFiles ("./scenes/rooms/")) {
    string file_name = System.IO.Path.GetFileNameWithoutExtension (file_path);
    rooms.Add (file_name, ResourceLoader.Load<PackedScene> ("res://scenes/rooms/" + file_name + ".tscn"));
}

The problem was that your loop only found Images which is a directory and not a scene file, which is strange.

WizzardMaker commented 5 years ago

I think I know why this is happening

There could be a file name mismatch. I use Windows, which doesn't care about capitalization in file names, where as you use Linux as far as I can see it.

Can you tell me how your Images folder looks like, and whether you have the file Images/gli/glbasis/CURSOR.tres And check if you can open the base.tscn scene

WizzardMaker commented 5 years ago

And you have to watch out with the System.IO namespace. They can't read the files from the "res://" space when you export the game as they are no longer inside any readable folder and instead inside of a .pck file

Serphentas commented 5 years ago

I do have CURSOR.tres and the Images folder looks like this: img_structure.txt.

WizzardMaker commented 5 years ago

Cursor discussion moved to #9

WizzardMaker commented 5 years ago

Turns out, we can decrease the size of all images by around 1900% (~855MB to ~45MB)

There will be a rather big commit later which changes a bit on how images are handled.

For now, everything involving images should be paused until I commit everything.

Serphentas commented 5 years ago

Now that's quite a good improvement :))

I'm more focused on other stuff so feel free to commit

WizzardMaker commented 5 years ago

Commit f9c2b7d also changed the extensions of all images. Meaning you should delete the current Images folder, so that the scenes don't break

Serphentas commented 5 years ago

That did the trick. This new commit really brings the airport to life, nice !

EDIT: had to do a forced reload though