// Call this if you don't want a level placed in RAM public void unpackWorld() { string dir = $"user://Worlds/{BinLoader.RootDirectory}"; GDKnyttAssetManager.ensureDirExists(dir); string marker_name = $"{dir}/_do_not_load_"; File marker = new File(); marker.Open(marker_name, File.ModeFlags.Write); marker.Close(); foreach (string filename in BinLoader.GetFileNames()) { string fullname = $"{dir}/{filename}"; GDKnyttAssetManager.ensureDirExists(fullname.Substring(0, fullname.LastIndexOf('/'))); File f = new File(); f.Open(fullname, File.ModeFlags.Write); f.StoreBuffer(BinLoader.GetFile(filename)); f.Close(); } new Directory().Remove(marker_name); new Directory().Remove(WorldDirectory); removeDirectory("user://Cache/" + GDKnyttAssetManager.extractFilename(WorldDirectory)); purgeBinFile(); setDirectory(dir, WorldDirectoryName); BinMode = false; }
public void initialize(string path) { KWorld = new GDKnyttWorldImpl(); if (new Directory().DirExists(path)) { KWorld.setDirectory(path, GDKnyttAssetManager.extractFilename(path)); } else { var loader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(path)); KWorld.setBinMode(loader); KWorld.setDirectory(path, loader.RootDirectory); } string ini = GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("World.ini")); KWorld.loadWorldConfig(ini); Texture info = (KWorld.worldFileExists("Info+.png") ? KWorld.getWorldTexture("Info+.png") : KWorld.worldFileExists("Info.png") ? KWorld.getWorldTexture("Info.png") : null) as Texture; if (info != null) { info.Flags |= (uint)Texture.FlagsEnum.Filter; GetNode <TextureRect>("InfoRect").Texture = info; } GetNode <SlotButton>("InfoRect/Slot1Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName; GetNode <SlotButton>("InfoRect/Slot2Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName; GetNode <SlotButton>("InfoRect/Slot3Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName; GetNode <Button>("InfoRect/RatePanel/VBoxContainer/UninstallButton").Disabled = KWorld.WorldDirectory.StartsWith("res://"); }
private WorldEntry generateDirectoryWorld(string world_dir) { KnyttWorldInfo world_info; string cache_dir = "user://Cache/" + GDKnyttAssetManager.extractFilename(world_dir); string ini_cache_name = cache_dir + "/World.ini"; string played_flag_name = cache_dir + "/LastPlayed.flag"; if (new File().FileExists(ini_cache_name)) { world_info = getWorldInfo(GDKnyttAssetManager.loadFile(ini_cache_name)); } else { var ini_bin = GDKnyttAssetManager.loadFile(world_dir + "/world.ini"); var ini_data = new IniData(); world_info = getWorldInfo(ini_bin, merge_to: ini_data["World"]); GDKnyttAssetManager.ensureDirExists(cache_dir); var f = new File(); f.Open(ini_cache_name, File.ModeFlags.Write); f.StoreString(ini_data.ToString()); f.Close(); } Texture icon = GDKnyttAssetManager.loadExternalTexture(world_dir + "/icon.png"); var last_played = new File().FileExists(played_flag_name) ? new File().GetModifiedTime(played_flag_name) : 0; return(new WorldEntry(icon, world_info, world_dir, last_played)); }
public void uninstallWorld() { if (BinMode) { new Directory().Remove(WorldDirectory); removeDirectory("user://Cache/" + GDKnyttAssetManager.extractFilename(WorldDirectory)); } else { removeDirectory(WorldDirectory); } removeDirectory($"user://Cache/{WorldDirectoryName}"); // TODO: also remove .part files which might left after an unfinished download }
private WorldEntry generateBinWorld(string world_dir) { byte[] icon_bin; KnyttWorldInfo world_info; string cache_dir = "user://Cache/" + GDKnyttAssetManager.extractFilename(world_dir); string icon_cache_name = cache_dir + "/Icon.png"; string ini_cache_name = cache_dir + "/World.ini"; string played_flag_name = cache_dir + "/LastPlayed.flag"; if (new Directory().DirExists(cache_dir)) { icon_bin = GDKnyttAssetManager.loadFile(icon_cache_name); world_info = getWorldInfo(GDKnyttAssetManager.loadFile(ini_cache_name)); } else { KnyttBinWorldLoader binloader; byte[] ini_bin; try { binloader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world_dir)); } catch (InvalidOperationException) { return(null); } icon_bin = binloader.GetFile("Icon.png"); ini_bin = binloader.GetFile("World.ini"); GDKnyttAssetManager.ensureDirExists("user://Cache"); new Directory().MakeDir(cache_dir); var f = new File(); f.Open(icon_cache_name, File.ModeFlags.Write); f.StoreBuffer(icon_bin); f.Close(); var ini_data = new IniData(); world_info = getWorldInfo(ini_bin, merge_to: ini_data["World"]); f.Open(ini_cache_name, File.ModeFlags.Write); f.StoreString(ini_data.ToString()); f.Close(); } Texture icon = GDKnyttAssetManager.loadTexture(icon_bin); var last_played = new File().FileExists(played_flag_name) ? new File().GetModifiedTime(played_flag_name) : 0; return(new WorldEntry(icon, world_info, world_dir, last_played)); }
public void _on_SlotButton_StartGame(bool new_save, string filename, int slot) { GetNode <LevelSelection>("../LevelSelection").killConsumers(); string cache_dir = GDKnyttAssetManager.extractFilename(KWorld.WorldDirectory); GDKnyttAssetManager.ensureDirExists($"user://Cache/{cache_dir}"); var f = new File(); f.Open($"user://Cache/{cache_dir}/LastPlayed.flag", File.ModeFlags.Write); f.Close(); KnyttSave save = new KnyttSave(KWorld, new_save ? GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("DefaultSavegame.ini")) : GDKnyttAssetManager.loadTextFile(filename), slot); KWorld.CurrentSave = save; GDKnyttDataStore.KWorld = KWorld; GDKnyttDataStore.startGame(new_save); this.QueueFree(); }