/// <summary> /// Initializes a new instance of the <see cref="GameSettingsData" /> class. /// </summary> public GameSettings(IContentStorage storage, ILog log, string filename = DefaultSettingsFilename) { if (!storage.IsFileExist(filename)) { // TODO: Write error. Settings file does not exist return; } var rootElement = storage.LoadXml(filename); this.DefaultLocale = rootElement.GetChildElementText(LocaleElementName); this.HeartBeat = rootElement.GetChildElementValue <int>(HeartBeatElementName, 500); this.LineSpace = Math.Max(1, rootElement.GetChildElementValue <int>(LineSpaceElementName, 1)); this.LoginWorldName = rootElement.GetChildElementText(LoginWorldElementName); this.StartWorldName = rootElement.GetChildElementText(StartWorldElementName); this.PlayerProfileFolder = DefaultPlayerProfileFolder; this.PlayerDataFolder = DefaultPlayerDataFolder; this.MapDataFolder = DefaultMapDataFolder; this.MapDesignFolder = DefaultMapDesignFolder; this.WorldDataFolder = DefaultWorldDataFolder; this.SetFolders(rootElement.SelectSingleNode(FolderRootElementName) as XmlElement, log); this.LoadWorldConfigurations(rootElement.SelectSingleNode(WorldRootElementName) as XmlElement, log); }
public static XmlElement LoadXml(this IContentStorage storage, string folder, string file) { var path = string.IsNullOrEmpty(folder) ? file : storage.CombinePath(folder, file); return(storage.LoadXml(path)); }
private void LoadRoomsFromMapFile( IContentStorage storage, string path, object syncObject, IGameContext context, bool inDesign, IList <RoomData> dataToProcess) { XmlElement rootElement = storage.LoadXml(path); string areaName = rootElement.GetAttribute(AreaNameAttributeName); if (string.IsNullOrWhiteSpace(areaName)) { // TODO: write log. area name is required return; } Area area; lock (syncObject) { if (!this.areas.TryGetValue(areaName, out area)) { area = new Area(areaName); this.areas.Add(areaName, area); } } foreach (XmlElement roomElement in rootElement.SelectNodes(RoomElementName)) { string roomName = roomElement.GetAttribute(RoomNameAttributeName); if (string.IsNullOrWhiteSpace(roomName)) { // TODO: write error. room name is required continue; } roomName = roomName.Trim(); IRoom room = null; var typeElement = roomElement.SelectSingleNode(TypeElementName) as XmlElement; if (typeElement != null) { room = RuntimeUtility.CreateInstance <IRoom>(typeElement, context.TypeManager, context.Log); } if (room == null) { room = new Room(); } var fullName = GetRoomFullName(areaName, roomName); var roomData = new RoomData { Name = roomName, Area = area, InDesign = inDesign, Data = roomElement }; lock (syncObject) { if (area.Rooms.ContainsKey(roomName)) { // TODO: write error } else { area.Rooms.Add(roomName, room); rooms.Add(fullName, room); dataToProcess.Add(roomData); } } } }
/// <summary> /// Initializes a new instance of the <see cref="TypeManager" /> class. /// </summary> /// <param name="storage">content storage</param> /// <param name="typeFilename">type XML file path</param> public TypeManager(IContentStorage storage, string typeFilename = DefaultTypeFilename) : this(storage.LoadXml(typeFilename)) { }