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)); }
private KnyttWorldManager <Texture> .WorldEntry generateBinWorld(string world_dir) { Texture icon; string txt; KnyttBinWorldLoader binloader; lock (file_lock) { binloader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world_dir)); } lock (file_lock) { icon = GDKnyttAssetManager.loadTexture(binloader.GetFile("Icon.png")); } lock (file_lock) { txt = GDKnyttAssetManager.loadTextFile(binloader.GetFile("World.ini")); } GDKnyttWorldImpl world = new GDKnyttWorldImpl(); world.setDirectory(world_dir, binloader.RootDirectory); world.loadWorldConfig(txt); world.setBinMode(null); return(new KnyttWorldManager <Texture> .WorldEntry(world, icon)); }
private WorldEntry generateRemoteWorld(Dictionary json_item) { WorldEntry world_info = new WorldEntry(); world_info.HasServerInfo = true; world_info.Name = HTTPUtil.jsonValue <string>(json_item, "name"); world_info.Author = HTTPUtil.jsonValue <string>(json_item, "author"); world_info.Description = HTTPUtil.jsonValue <string>(json_item, "description"); var base64_icon = HTTPUtil.jsonValue <string>(json_item, "icon"); world_info.Icon = base64_icon != null && base64_icon.Length > 0 ? GDKnyttAssetManager.loadTexture(decompress(Convert.FromBase64String(base64_icon))) : null; world_info.Link = HTTPUtil.jsonValue <string>(json_item, "link"); world_info.FileSize = HTTPUtil.jsonInt(json_item, "file_size"); world_info.Upvotes = HTTPUtil.jsonInt(json_item, "upvotes"); world_info.Downvotes = HTTPUtil.jsonInt(json_item, "downvotes"); world_info.Downloads = HTTPUtil.jsonInt(json_item, "downloads"); world_info.Complains = HTTPUtil.jsonInt(json_item, "complains"); world_info.Verified = HTTPUtil.jsonBool(json_item, "verified"); world_info.Approved = HTTPUtil.jsonBool(json_item, "approved"); return(world_info); }
protected override object bytesToTexture(byte[] data) { return(GDKnyttAssetManager.loadTexture(data)); }