Example #1
0
        private void loadRooms(string basePath)
        {
            if (!Directory.Exists(basePath))
            {
                return;
            }

            var          roomFolders  = Directory.GetDirectories(basePath);
            const string roomFilename = RoomModel.Filename;

            foreach (var roomFolder in roomFolders)
            {
                var roomJsonPath = Path.Combine(roomFolder, roomFilename);
                if (!File.Exists(roomJsonPath))
                {
                    Debug.WriteLine($"Missing room json at {roomFolder}");
                    continue;
                }
                var room = RoomModel.Load(roomJsonPath);
                Rooms.Add(room);
                var roomFiles = Directory.GetFiles(roomFolder);
                foreach (var roomFile in roomFiles)
                {
                    if (roomFile == roomJsonPath)
                    {
                        continue;
                    }

                    var entity = EntityModel.Load(roomFile);
                    Entities.Add(entity.ID, entity);
                    if (entity.ID != room.BackgroundEntity)
                    {
                        room.Entities.Add(entity.ID);
                    }
                }
            }
        }
Example #2
0
        private void addNewEntities(List <object> entities, MethodModel methodModel)
        {
            bool isParent = _potentialParent != null && _targetRadioGroup?.SelectedButton == _parentButton;
            bool isUi     = _targetRadioGroup?.SelectedButton == _guiButton || (isParent && _editor.Game.State.UI.Contains(_potentialParent));
            bool isFirst  = true;

            foreach (var entityObj in entities)
            {
                IEntity     entity      = (IEntity)entityObj;
                MethodModel initializer = null;
                if (isFirst)
                {
                    isFirst     = false;
                    initializer = methodModel;
                }
                if (isParent)
                {
                    if (entity is IObject obj)
                    {
                        _potentialParent.TreeNode.AddChild(obj);
                    }
                    else
                    {
                        throw new Exception($"Unkown entity created: {entity?.GetType().Name ?? "null"}");
                    }
                }
                addToModel(entity, initializer);
                if (isUi)
                {
                    if (entity is IObject obj)
                    {
                        _editor.Game.State.UI.Add(obj);
                        _editor.Project.Model.Guis.Add(entity.ID);
                    }
                    else
                    {
                        throw new Exception($"Unkown entity created: {entity?.GetType().Name ?? "null"}");
                    }
                }
                else
                {
                    var roomModel = _editor.Project.Model.Rooms.FirstOrDefault(r => r.ID == _editor.Game.State.Room.ID);
                    if (roomModel == null)
                    {
                        Debug.WriteLine($"Room {_editor.Game.State.Room.ID} encountered for the first time!");
                        roomModel = new RoomModel {
                            ID = _editor.Game.State.Room.ID, Entities = new HashSet <string>()
                        };
                        _editor.Project.Model.Rooms.Add(roomModel);
                    }
                    roomModel.Entities.Add(entity.ID);
                    if (entity is IObject obj)
                    {
                        _editor.Game.State.Room.Objects.Add(obj);
                    }
                    else if (entity is IArea area)
                    {
                        _editor.Game.State.Room.Areas.Add(area);
                    }
                    else
                    {
                        throw new Exception($"Unkown entity created: {entity?.GetType().Name ?? "null"}");
                    }
                }
            }
        }