public void StoreData(String file, Godot.Collections.Dictionary save) { Godot.File databaseFile = new Godot.File(); databaseFile.Open("res://databases/" + file + ".json", Godot.File.ModeFlags.Write); databaseFile.StoreString(JSON.Print(save)); databaseFile.Close(); }
public void HandleRequest(Request request, Response response) { // check if file exist at folder (need to assume a base local root) var fullPath = "res://public" + Uri.UnescapeDataString(request.uri.LocalPath); // get file extension to add to header var fileExt = System.IO.Path.GetExtension(fullPath); //Debug.Log($"fullPath:{fullPath} fileExt:{fileExt}"); var f = new Godot.File(); // not found if (!f.FileExists(fullPath)) { response.statusCode = 404; response.message = "Not Found"; return; } // serve the file response.statusCode = 200; response.message = "OK"; response.headers.Add("Content-Type", MimeTypeMap.GetMimeType(fileExt)); var ret = f.Open(fullPath, Godot.File.ModeFlags.Read); // read file and set bytes if (ret == Error.Ok) { var length = (int)f.GetLen(); // add content length response.headers.Add("Content-Length", length.ToString()); response.SetBytes(f.GetBuffer(length)); } f.Close(); }
private bool _getResFolder(Godot.File file, string path, List <string> paths) { if (file.FileExists(path)) { file.Open(path, File.ModeFlags.Read); var ss = file.GetAsText(); if (string.IsNullOrEmpty(ss)) { return(false); } var cfg = Hocon.HoconParser.Parse(ss); var res = cfg.GetString("res"); if (res.valid() && !paths.Contains(res)) { if (paths.Count == 0) { paths.Add(res); } else { paths[0] = res; } } foreach (var val in cfg.AsEnumerable()) { if (val.Key != "res" && !paths.Contains(val.Key)) { paths.Add(val.Value.GetString()); } } file.Close(); return(true); } return(false); }
/// <summary> /// Create a new instance of the <see cref="GodotFileStream"/> class. /// </summary> /// <param name="path">The path to the file to open. This accepts Godot-style <code>user://</code> and <code>res://</code> paths.</param> /// <param name="flags">File flags.</param> /// <param name="compressionMode">If not null, this will enable compression/decompression.</param> public GodotFileStream(string path, File.ModeFlags flags, File.CompressionMode?compressionMode = null) { if (path == null) { throw new ArgumentNullException("path"); } _file = new File(); _flags = flags; Error result; if (compressionMode.HasValue) { result = _file.OpenCompressed(path, flags, compressionMode.Value); } else { result = _file.Open(path, flags); } if (result != Error.Ok) { throw new IOException($"Unable to open \"{path}\": {result}"); } }
public override void _Ready() { label = GetNode <RichTextLabel>("RichTextLabel"); Godot.File file = new Godot.File(); file.Open("res://Testing/Testing.cs", File.ModeFlags.Read); content = file.GetAsText(); file.Close(); label.Text = "Line1"; label.GetVScroll().Connect("value_changed", this, "ScrollLineLock"); //this.Connect(nameof(MySignal), this, "ScrollLineLock"); Font font = (Font)label.GetFont("normal_font", nameof(RichTextLabel)); int line_separation = (int)label.GetConstant("line_separation"); label.RectSize = new Vector2(label.RectSize.x, (font.GetHeight() + line_separation) * 8); GD.Print("ready is called"); GD.Print((int)1.9); GD.Print((int)1.3); double char_increase_rate = 6; int threshold = 5; int char_count = (int)(char_increase_rate - (((int)char_increase_rate / 5) * (5 - 1))); GD.Print("ans: " + char_count); }
private void RefreshDisplay() { Godot.File file = new Godot.File(); file.Open(this.SaveLocation, File.ModeFlags.Read); if (file.IsOpen()) { this.HasSaveData = true; } else { this.HasSaveData = false; } file.Close(); if (this.HasSaveData) { this._loadButton.Text = String.Format("Save Slot {0} - (data)", this.SlotNumber); var modified = file.GetModifiedTime(this.SaveLocation); var modifiedDate = DateTimeOffset.FromUnixTimeSeconds((long)modified).ToLocalTime().ToString("yyyy-MM-dd"); this._lastPlayedLabel.Text = String.Format("Last Played: {0}", modifiedDate); this._clearButton.Disabled = false; } else { this._loadButton.Text = String.Format("Save Slot {0} - (empty)", this.SlotNumber); this._lastPlayedLabel.Text = "Last Played: never"; this._clearButton.Disabled = true; } }
// Called when the node enters the scene tree for the first time. public override void _Ready() { buf = (AudioStreamGeneratorPlayback)GetStreamPlayback(); //FIXME: IMPLEMENT DRUMS channels[9].Mute = true; //Setup the patch bank. const string BANKPATH = "res://demo/bank0/"; const string EXT = ".gfmp"; for (int i = 0; i < patchBank.Length; i++) { patchBank[i] = new Patch(MixRate); var inst = (GeneralMidiInstrument)i; var path = BANKPATH + inst.ToString() + EXT; var dir = new Godot.Directory(); //Search for a bank to overload the initial one!! if (Godot.ResourceLoader.Exists(path) || dir.FileExists(path)) { var f = new Godot.File(); f.Open(path, File.ModeFlags.Read); patchBank[i].FromString(f.GetAsText()); f.Close(); GD.Print("Program ", i, " (", inst, ") loaded."); } else { //Init patch. patchBank[i].FromString(glue.INIT_PATCH, true); } } }
public static byte[] LoadData(string path) { var f = new Godot.File(); f.Open($"res://public/{path}", Godot.File.ModeFlags.Read); var buffer = f.GetBuffer((int)f.GetLen()); f.Close(); return(buffer); }
public Godot.Collections.Dictionary ReadData(String file) { Godot.File databaseFile = new Godot.File(); databaseFile.Open("res://databases/" + file + ".json", Godot.File.ModeFlags.Read); string jsonAsText = databaseFile.GetAsText(); databaseFile.Close(); JSONParseResult jsonParsed = JSON.Parse(jsonAsText); return(jsonParsed.Result as Godot.Collections.Dictionary); }
private static string ReadJSONFile(string path) { using var file = new File(); file.Open(path, File.ModeFlags.Read); var result = file.GetAsText(); // This might be completely unnecessary file.Close(); return(result); }
private void Save(Node2D node) { Godot.File savefile = new Godot.File(); if (savefile.FileExists(_fileLocation)) { throw new NotImplementedException(); } savefile.Open(_fileLocation, Godot.File.ModeFlags.Write); savefile.StoreVar(node, true); savefile.Close(); }
public static string ReadFile(string filepath) { File file = new File(); if (!file.FileExists(_prefix + _root + filepath)) { throw new FileNotFoundException(_prefix + _root + filepath); } file.Open(_prefix + _root + filepath, File.ModeFlags.Read); return(file.GetAsText()); }
public void _on_Save_pressed() { var playerName = GetNode <TextEdit>("TextEdit").Text; var saveGame = new Godot.File(); if (saveGame.FileExists(SCORE_FILE_PATH)) { saveGame.Open("user://score.save", Godot.File.ModeFlags.ReadWrite); string[] content = saveGame.GetAsText().Split("\n"); //sprawdza czy gracz już istnieje na liście //jeśli znajdzie gracza i nowy wynik jest lepszy to go nadpisuje for (int i = 0; i < content.Length; i++) { string[] separated = content[i].Split(':'); if (separated[0] == playerName) { found = true; if (uint.Parse(separated[1]) < uint.Parse(score)) { content[i] = $"{playerName}:{score}"; saveGame.StoreString($"{string.Join("\n", content)}"); break; } } } if (!found) { saveGame.StoreString($"{string.Join("\n", content)}\n{playerName}:{(score != "" ? score : "0")}"); } } else { saveGame.Open("user://score.save", Godot.File.ModeFlags.Write); saveGame.StoreString($"{playerName}:{(score != "" ? score : "0")}"); } saveGame.Close(); GetTree().ChangeScene("res://scene/TitleScreen.tscn"); }
public void save_settings() { var file = new Godot.File(); file.Open(_save_path, File.ModeFlags.Write); var data = new Dictionary(); data["render_distance"] = render_distance; data["fog_enabled"] = fog_enabled; String text = JSON.Print(data); file.StoreString(text); file.Close(); }
public void LoadCards(string mapName) { var cardDataFile = new Godot.File(); cardDataFile.Open("res://Data/Cards/" + _root.Map.MapDataFileName, File.ModeFlags.Read); var content = Godot.JSON.Parse(cardDataFile.GetAsText()); var contentResult = (Godot.Collections.Dictionary)content.Result; _cards = (Godot.Collections.Array)contentResult["cards"]; _graveyard = new Godot.Collections.Array(); cardDataFile.Close(); }
/// <summary> /// Display the Credits /// </summary> private void DisplayCredits() { Godot.File file = new Godot.File(); file.Open("res://Credits/credits.txt", Godot.File.ModeFlags.Read); string content = file.GetAsText(); file.Close(); Label name = new Label(); name.AddFontOverride("font", dFont); name.Text = content; name.AddColorOverride("font_color", new Color(0, 0, 0)); gridContainer.AddChild(name); }
private Node2D Load() { Godot.File savefile = new Godot.File(); if (!savefile.FileExists(_fileLocation)) { throw new NotImplementedException(); } savefile.Open(_fileLocation, Godot.File.ModeFlags.Read); var scene = savefile.GetVar(true); savefile.Close(); return(scene as Node2D); }
private void LoadMapData() { var mapDataFile = new Godot.File(); mapDataFile.Open("res://Data/Maps/" + mapData, File.ModeFlags.Read); var content = Godot.JSON.Parse(mapDataFile.GetAsText()); var contentResult = (Godot.Collections.Dictionary)content.Result; _collisionMaps = (Godot.Collections.Dictionary)contentResult["collisionMaps"]; _windows = (Godot.Collections.Dictionary)contentResult["windows"]; _searchables = (Godot.Collections.Dictionary)contentResult["searchables"]; mapDataFile.Close(); }
private void LoadJson() { var file = new File(); if (file.Open(_formationDataPath, (int)File.ModeFlags.Read) != Error.Ok) { file.Close(); throw new FileLoadException($"There was a problem loading: {_formationDataPath}"); } var data = file.GetAsText(); file.Close(); _formationList = JsonConvert.DeserializeObject <List <List <List <int> > > >(data); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { var singleton = GetNode <Singleton>("/root/Singleton"); singleton.SpeedrunActive = false; var file = new Godot.File(); file.Open("res://global/data.json", Godot.File.ModeFlags.Read); _data = JSON.Parse(file.GetAsText()).Result as Godot.Collections.Dictionary; _ending = _data["ending"] as Godot.Collections.Dictionary; _credits = _data["credits"] as Godot.Collections.Dictionary; file.Close(); printEndingAndCredits(); }
public void GetFromJSON(string filename) { var file = new File(); file.Open(filename, 1); var text = file.GetAsText(); List <Story> data = JsonConvert.DeserializeObject <List <Story> >( text); // replace line below with Godot's own method for getting the JSON text from file // System.IO.File.ReadAllText(@"C:\Users\Nathan - User\OneDrive\Godot\Loopy Lips - C#\loopy_lips.json") Random rnd = new Random(); var i = rnd.Next(0, data.Count); _story = data[i].story; Prompts = data[i].inputs; file.Close(); }
protected void loadDefaultBones() { if (!String.IsNullOrEmpty(_defaultPose)) { var file = new Godot.File(); file.Open(_defaultPose, Godot.File.ModeFlags.Read); var content = file.GetAsText(); file.Close(); bones = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GodotBindPose> >(content); if (bones.Count <= 0) { GD.PrintErr("No bones found in default pose"); } } }
protected UMAReciepe loadEditorReciepeByPath(string filePath) { if (String.IsNullOrEmpty(filePath)) { return(null); } var file = new Godot.File(); if (file.FileExists(filePath)) { file.Open(filePath, Godot.File.ModeFlags.Read); var converted = JsonConvert.DeserializeObject <UMAReciepe>(file.GetAsText()); file.Close(); return(converted); } return(null); }
public void loadEntities() { Godot.File entityFile = new Godot.File(); entityFile.Open("res://data/directive/gameworldentities.json", 1); string entityText = entityFile.GetAsText(); entityFile.Close(); Godot.JSONParseResult entityData = JSON.Parse(entityText); GContainers.Dictionary entityDataDict = (GContainers.Dictionary)entityData.Result; GContainers.Array gEntities = (GContainers.Array)entityDataDict["entities"]; GContainers.Array gArgs = (GContainers.Array)entityDataDict["args"]; var entityList = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "Zona.ECSEntity").ToList(); List <Type> loadedClasses = new List <Type>(); foreach (object entity in gEntities) { string e = Convert.ToString(entity); foreach (Type classType in entityList) { if (classType.Name == e) { loadedClasses.Add(classType); break; } } } for (int i = 0; i < gArgs.Count; i++) { GContainers.Array gargs = (GContainers.Array)gArgs[i]; var c = gargs.Count; object[] args = new object[c]; for (int j = 0; j < c; j++) { args[j] = (object)gargs[j]; } var entityInstance = (Entity)Activator.CreateInstance(loadedClasses[i], args); this.entities.Add(entityInstance); this.AddChild(entityInstance); } }
public void loadMailParams() { //Read file with mail info Godot.File file = new Godot.File(); //file.OpenEncryptedWithPass("user://mailFile.dat",Godot.File.ModeFlags.Read,OS.GetUniqueId()); file.Open("user://mailFile.txt", Godot.File.ModeFlags.Read); string serviceUrl, port, email, password; serviceUrl = file.GetLine(); port = file.GetLine(); email = file.GetLine(); password = file.GetLine(); file.Close(); //Create mail object mail = new Mail(); mail.sendTestMail(); }
private static void loadRegistry() { File registryFile = new File(); registryFile.Open("user://mcdata/reports/blocks.json", File.ModeFlags.Read); string content = registryFile.GetAsText(); JObject o = JObject.Parse(content); foreach (var entry in o) { string name = entry.Key.Split(':')[1]; JArray states = (entry.Value["states"]) as JArray; foreach (var state in states) { uint id = state["id"].Value <uint>(); add(new BlockState(name, id)); } } GD.Print($"Loaded {idToState.Count} states"); }
private void OnPressed_about() { var popup = GetNode <PopupPanel>("about_popup"); popup.PopupExclusive = true; popup.PopupCenteredRatio(0.85f); ThemeDefaultHolder(popup.GetNode <VBoxContainer>("about_holder")); popup.GetNode <VBoxContainer>("about_holder").GetNode <Label>("title").AddFontOverride("font", new DynamicFont() { FontData = GD.Load <DynamicFontData>("res://assets/default/Tuffy_Bold.ttf"), Size = 40 }); var logo = popup.GetNode <VBoxContainer>("about_holder").GetNode <TextureRect>("logo"); logo.Expand = true; logo.RectMinSize = logo.Texture.GetSize() * 0.7f; ThemeButtons(popup.GetNode <VBoxContainer>("about_holder")); var c_label = popup.GetNode <VBoxContainer>("about_holder").GetNode <RichTextLabel>("c_label"); c_label.BbcodeEnabled = true; c_label.RectMinSize = new Vector2(c_label.RectMinSize.x, 150); c_label.BbcodeText = "[center]Copyright (c) 2017 Leacme\n([color=#996600][url=http://leac.me]http://leac.me[/url][/color])\n\n[/center]"; c_label.BbcodeText += "[center][u]USAGE\n[/u][/center]"; using (var instrFil = new Godot.File()) { instrFil.Open("res://README.md", File.ModeFlags.Read); c_label.BbcodeText += "This application features the ability to " + instrFil.GetAsText().Split(new string[] { "This application features the ability to" }, StringSplitOptions.None)[1].Split("![][image_screenshot]")[0].Trim() + "\n\n"; c_label.BbcodeText += instrFil.GetAsText().Split(new string[] { "## Application Usage" }, StringSplitOptions.None)[1].Split("## Copyright")[0].Trim() + "\n\n"; instrFil.Close(); } c_label.BbcodeText += "[center][u]LICENSES\n[/u][/center]"; c_label.BbcodeText += ProjectSettings.GetSetting("application/config/name").ToString() + ":\n"; using (var leacLic = new Godot.File()) { leacLic.Open("res://LICENSE.md", File.ModeFlags.Read); c_label.BbcodeText += leacLic.GetAsText(); leacLic.Close(); } }
private static void WriteDataToSaveFile(string target, string justInfo, string serialized, string tempScreenshot) { using (var file = new File()) { file.Open(target, File.ModeFlags.Write); using (Stream gzoStream = new GZipOutputStream(new GodotFileStream(file))) { using (var tar = new TarOutputStream(gzoStream)) { OutputEntry(tar, SAVE_INFO_JSON, Encoding.UTF8.GetBytes(justInfo)); if (tempScreenshot != null) { byte[] data = null; using (var reader = new File()) { reader.Open(tempScreenshot, File.ModeFlags.Read); if (!reader.IsOpen()) { GD.PrintErr("Failed to open temp screenshot for writing to save"); } else { data = reader.GetBuffer((int)reader.GetLen()); } } if (data != null && data.Length > 0) { OutputEntry(tar, SAVE_SCREENSHOT, data); } } OutputEntry(tar, SAVE_SAVE_JSON, Encoding.UTF8.GetBytes(serialized)); } } } }
private void loadProcessors() { Godot.File file = new Godot.File(); file.Open("res://data/directive/gameworldprocessors.json", 1); string text = file.GetAsText(); file.Close(); var data = JSON.Parse(text); GContainers.Dictionary dataDict = data.Result as GContainers.Dictionary; GContainers.Array processors = (GContainers.Array)dataDict["processors"]; GContainers.Array priorities = (GContainers.Array)dataDict["priorities"]; var processorList = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "Zona.ECSProcessor").ToList(); List <string> processorClassList = new List <string>(); foreach (Type type in processorList) { if (type.Namespace == "Zona.ECSProcessor") { processorClassList.Add(type.Name); } } for (int i = 0; i < processors.Count; i++) { string pname = (string)processors[i]; if (processorClassList.Contains(pname)) { string className = "Zona.ECSProcessor." + pname; var proccessInstance = Activator.CreateInstance(Assembly.GetExecutingAssembly().GetName().Name, className); dynamic process = proccessInstance.Unwrap(); this.AddChild(process); dynamic priority = priorities[i]; this.addProcessor(priority, process); } } }
private void OnLoadButtonPressed() { if (this.HasSaveData == false) { // Initialize new EncounterState, EncounterScene var scene = _encounterPrefab.Instance() as EncounterScene; var newState = EncounterState.Create(this.SaveLocation); newState.SetStateForNewGame(); scene.SetEncounterState(newState); // Save to slot newState.WriteToFile(); var sceneManager = (SceneManager)GetNode("/root/SceneManager"); sceneManager.ShowEncounterScene(scene); } else { var scene = _encounterPrefab.Instance() as EncounterScene; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Godot.File file = new Godot.File(); file.Open(this.SaveLocation, File.ModeFlags.Read); var saveData = file.GetAsText(); saveData = StringCompression.DecompressString(saveData); file.Close(); var oldState = EncounterState.FromSaveData(saveData); stopwatch.Stop(); GD.Print("SaveSlotScene load completed, elapsed ms: ", stopwatch.ElapsedMilliseconds); scene.SetEncounterState(oldState); var sceneManager = (SceneManager)GetNode("/root/SceneManager"); sceneManager.ShowEncounterScene(scene); } }