/// <inheritdoc /> public IMapGrid?LoadBlueprint(MapId mapId, string path) { TextReader reader; var resPath = new ResourcePath(path).ToRootedPath(); // try user if (!_resMan.UserData.Exists(resPath)) { Logger.InfoS("map", $"No user blueprint path: {resPath}"); // fallback to content if (_resMan.TryContentFileRead(resPath, out var contentReader)) { reader = new StreamReader(contentReader); } else { Logger.ErrorS("map", $"No blueprint found: {resPath}"); return(null); } } else { var file = _resMan.UserData.Open(resPath, FileMode.Open); reader = new StreamReader(file); } IMapGrid grid; using (reader) { Logger.InfoS("map", $"Loading Grid: {resPath}"); var data = new MapData(reader); LoadedMapData?.Invoke(data.Stream, resPath.ToString()); if (data.GridCount != 1) { throw new InvalidDataException("Cannot instance map with multiple grids as blueprint."); } var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _componentManager, _prototypeManager, (YamlMappingNode)data.RootNode, mapId); context.Deserialize(); grid = context.Grids[0]; if (!context.MapIsPostInit && _pauseManager.IsMapInitialized(mapId)) { foreach (var entity in context.Entities) { entity.RunMapInit(); } } } return(grid); }
private void WriteMetaSection() { var meta = new YamlMappingNode(); RootNode.Add("meta", meta); meta.Add("format", MapFormatVersion.ToString(CultureInfo.InvariantCulture)); // TODO: Make these values configurable. meta.Add("name", "DemoStation"); meta.Add("author", "Space-Wizards"); var isPostInit = false; foreach (var grid in Grids) { if (_pauseManager.IsMapInitialized(grid.ParentMap)) { isPostInit = true; break; } } meta.Add("postmapinit", isPostInit ? "true" : "false"); }