/// <summary> /// Reads a single file /// </summary> /// <param name="comp">The component to be read</param> /// <param name="eventName">The event to be read</param> public static string ReadSingle(IDEComponent comp, string eventName) { if (comp.Type != IDEComponent.ComponentType.None && comp.Type != IDEComponent.ComponentType.Sprite && comp.Type != IDEComponent.ComponentType.Sound) { string targetPath = GameConfig.path; switch (comp.Type) { case IDEComponent.ComponentType.Object: targetPath += @"\Codes\Objects\obj" + ((Object)comp).id + @"\" + eventName + ".js"; break; case IDEComponent.ComponentType.Room: targetPath += @"\Codes\Rooms\room" + ((Room)comp).id + @"\" + eventName + ".js"; break; case IDEComponent.ComponentType.Script: targetPath += @"\Codes\Scripts\script" + ((Script)comp).id + ".js"; break; } if (File.Exists(targetPath)) { return(File.ReadAllText(targetPath)); } } return(null); }
/// <summary> /// Updates a single file /// </summary> /// <param name="comp">The component to be updated</param> /// <param name="data">The new data</param> /// <param name="eventName">The event to be updated</param> public static void UpdateSingle(IDEComponent comp, string data, string eventName) { if (comp.Type != IDEComponent.ComponentType.None && comp.Type != IDEComponent.ComponentType.Sprite && comp.Type != IDEComponent.ComponentType.Sound) { string targetPath = GameConfig.path; switch (comp.Type) { case IDEComponent.ComponentType.Object: targetPath += @"\Codes\Objects\obj" + ((Object)comp).id + @"\" + eventName + ".js"; break; case IDEComponent.ComponentType.Room: targetPath += @"\Codes\Rooms\room" + ((Room)comp).id + @"\" + eventName + ".js"; break; case IDEComponent.ComponentType.Script: targetPath += @"\Codes\Scripts\script" + ((Script)comp).id + ".js"; break; } Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); using (StreamWriter w = new StreamWriter(targetPath)) { w.Write(data); } } }