Beispiel #1
0
        static void ImportGameObjects(ILogger logger, IGameData gameData)
        {
            var repo = new JsonBasedWorldObjectRepository();
            var objs = repo.AllObjects();

            if (objs.Count > 0)
            {
                logger.LogDebug("Removing existing objects..");
                var objects = gameData.GetAllGameObjects();
                foreach (GameObject obj in objects)
                {
                    var transform = gameData.GetTransform(obj.TransformId);
                    if (transform != null)
                    {
                        gameData.Remove(transform);
                    }

                    gameData.Remove(obj);
                }

                logger.LogDebug("Importing objects from json file..");
                foreach (var obj in objs)
                {
                    var transform = gameData.CreateTransform();
                    transform.SetPosition(obj.Position);
                    transform.SetRotation(obj.Rotation);

                    var newObj = gameData.CreateGameObject();
                    newObj.Id                  = obj.Id;
                    newObj.Type                = obj.Type;
                    newObj.InteractItemType    = obj.InteractItemType;
                    newObj.RespawnMilliseconds = obj.RespawnMilliseconds;
                    newObj.Static              = obj.Static;
                    newObj.Experience          = obj.Experience;
                    newObj.TransformId         = transform.Id;
                }
            }

            gameData.Flush();
        }