本文整理汇总了C#中Map.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Map.Save方法的具体用法?C# Map.Save怎么用?C# Map.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.Save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(ModData modData, string[] args)
{
Game.ModData = modData;
map = new Map(modData, modData.ModFiles.OpenPackage(args[1]));
Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height);
map.Resize(width, height);
var forRemoval = new List<MiniYamlNode>();
foreach (var kv in map.ActorDefinitions)
{
var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var location = actor.InitDict.Get<LocationInit>().Value(null);
if (!map.Contains(location))
{
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location));
forRemoval.Add(kv);
}
}
foreach (var kv in forRemoval)
map.ActorDefinitions.Remove(kv);
map.Save((IReadWritePackage)map.Package);
}
示例2: Start
void Start()
{
var map = new Map();
map.Load("1", Difficulty.Easy);
Debug.Log(map.MapFilePath);
map.Save(null, null, null, "2", Difficulty.Hard);
Debug.Log(map.MapFilePath);
}
示例3: UpgradeMaps
static void UpgradeMaps(string mod)
{
var MapFolderPath = new string[] { Environment.CurrentDirectory, "mods", mod, "maps" }
.Aggregate(Path.Combine);
foreach (var path in ModData.FindMapsIn(MapFolderPath))
{
var map = new Map(path);
map.Save(path+".oramap");
}
}
示例4: Run
public void Run(ModData modData, string[] args)
{
// HACK: The engine code assumes that Game.modData is set.
Game.modData = modData;
var map = new Map(args[1]);
var engineDate = Exts.ParseIntegerInvariant(args[2]);
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
map.Save(args[1]);
}
示例5: UpgradeMap
public static void UpgradeMap(ModData modData, IReadWritePackage package, int engineDate)
{
UpgradeRules.UpgradeMapFormat(modData, package);
if (engineDate < UpgradeRules.MinimumSupportedVersion)
{
Console.WriteLine("Unsupported engine version. Use the release-{0} utility to update to that version, and then try again",
UpgradeRules.MinimumSupportedVersion);
return;
}
var map = new Map(modData, package);
ProcessYaml(map, map.WeaponDefinitions, engineDate, UpgradeRules.UpgradeWeaponRules);
ProcessYaml(map, map.RuleDefinitions, engineDate, UpgradeRules.UpgradeActorRules);
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
map.Save(package);
}
示例6: UpgradeMap
public static void UpgradeMap(string[] args)
{
var map = new Map(args[1]);
var engineDate = Exts.ParseIntegerInvariant(args[2]);
Game.modData = new ModData(map.RequiresMod);
UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
map.Save(args[1]);
}
示例7: SaveMapLogic
public SaveMapLogic(Widget widget, ModData modData, Action<string> onSave, Action onExit,
Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions)
{
var title = widget.Get<TextFieldWidget>("TITLE");
title.Text = map.Title;
var author = widget.Get<TextFieldWidget>("AUTHOR");
author.Text = map.Author;
var visibilityPanel = Ui.LoadWidget("MAP_SAVE_VISIBILITY_PANEL", null, new WidgetArgs());
var visOptionTemplate = visibilityPanel.Get<CheckboxWidget>("VISIBILITY_TEMPLATE");
visibilityPanel.RemoveChildren();
foreach (MapVisibility visibilityOption in Enum.GetValues(typeof(MapVisibility)))
{
// To prevent users from breaking the game only show the 'Shellmap' option when it is already set.
if (visibilityOption == MapVisibility.Shellmap && !map.Visibility.HasFlag(visibilityOption))
continue;
var checkbox = (CheckboxWidget)visOptionTemplate.Clone();
checkbox.GetText = () => visibilityOption.ToString();
checkbox.IsChecked = () => map.Visibility.HasFlag(visibilityOption);
checkbox.OnClick = () => map.Visibility ^= visibilityOption;
visibilityPanel.AddChild(checkbox);
}
var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
visibilityDropdown.OnMouseDown = _ =>
{
visibilityDropdown.RemovePanel();
visibilityDropdown.AttachPanel(visibilityPanel);
};
var writableDirectories = new List<SaveDirectory>();
SaveDirectory selectedDirectory = null;
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
{
Func<SaveDirectory, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => selectedDirectory == option,
() => selectedDirectory = option);
item.Get<LabelWidget>("LABEL").GetText = () => option.DisplayName;
return item;
};
foreach (var kv in modData.MapCache.MapLocations)
{
var folder = kv.Key as Folder;
if (folder == null)
continue;
try
{
using (var fs = File.Create(Path.Combine(folder.Name, ".testwritable"), 1, FileOptions.DeleteOnClose))
{
// Do nothing: we just want to test whether we can create the file
}
writableDirectories.Add(new SaveDirectory(folder, kv.Value));
}
catch
{
// Directory is not writable
}
}
if (map.Package != null)
selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name));
// Prioritize MapClassification.User directories over system directories
if (selectedDirectory == null)
selectedDirectory = writableDirectories.OrderByDescending(kv => kv.Classification).First();
directoryDropdown.GetText = () => selectedDirectory == null ? "" : selectedDirectory.DisplayName;
directoryDropdown.OnClick = () =>
directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, setupItem);
}
var mapIsUnpacked = map.Package != null && (map.Package is Folder || map.Package is ZipFolder);
var filename = widget.Get<TextFieldWidget>("FILENAME");
filename.Text = map.Package == null ? "" : mapIsUnpacked ? Path.GetFileName(map.Package.Name) : Path.GetFileNameWithoutExtension(map.Package.Name);
var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
{
{ MapFileType.OraMap, new MapFileTypeInfo { Extension = ".oramap", UiLabel = ".oramap" } },
{ MapFileType.Unpacked, new MapFileTypeInfo { Extension = "", UiLabel = "(unpacked)" } }
};
var typeDropdown = widget.Get<DropDownButtonWidget>("TYPE_DROPDOWN");
{
Func<KeyValuePair<MapFileType, MapFileTypeInfo>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => fileType == option.Key,
() => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; });
item.Get<LabelWidget>("LABEL").GetText = () => option.Value.UiLabel;
//.........这里部分代码省略.........
示例8: SaveMapLogic
public SaveMapLogic(Widget widget, Action<string> onSave, Action onExit, Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions)
{
var title = widget.Get<TextFieldWidget>("TITLE");
title.Text = map.Title;
var author = widget.Get<TextFieldWidget>("AUTHOR");
author.Text = map.Author;
// TODO: This should use a multi-line textfield once they exist
var description = widget.Get<TextFieldWidget>("DESCRIPTION");
description.Text = map.Description;
// TODO: This should use a multi-selection dropdown once they exist
var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
{
var mapVisibility = new List<string>(Enum.GetNames(typeof(MapVisibility)));
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => visibilityDropdown.Text == option,
() => { visibilityDropdown.Text = option; });
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
};
visibilityDropdown.Text = Enum.GetName(typeof(MapVisibility), map.Visibility);
visibilityDropdown.OnClick = () =>
visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem);
}
Func<string, string> makeMapDirectory = dir =>
{
var f = Platform.UnresolvePath(dir);
if (f.StartsWith("~"))
f = f.Substring(1);
return f;
};
var mapDirectories = Game.ModData.Manifest.MapFolders
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => directoryDropdown.Text == option,
() => directoryDropdown.Text = option);
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
};
var mapDirectory = map.Path != null ? Platform.UnresolvePath(Path.GetDirectoryName(map.Path)) : null;
var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory);
if (initialDirectory == null)
initialDirectory = mapDirectories.Keys.First();
directoryDropdown.Text = initialDirectory;
directoryDropdown.OnClick = () =>
directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapDirectories.Keys, setupItem);
}
var filename = widget.Get<TextFieldWidget>("FILENAME");
filename.Text = Path.GetFileNameWithoutExtension(map.Path);
var fileTypes = new Dictionary<string, string>()
{
{ ".oramap", ".oramap" },
{ "(unpacked)", "" }
};
var typeDropdown = widget.Get<DropDownButtonWidget>("TYPE_DROPDOWN");
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => typeDropdown.Text == option,
() => typeDropdown.Text = option);
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
};
typeDropdown.Text = map.Path != null ? Path.GetExtension(map.Path) : ".oramap";
if (string.IsNullOrEmpty(typeDropdown.Text))
typeDropdown.Text = fileTypes.First(t => t.Value == "").Key;
typeDropdown.OnClick = () =>
typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes.Keys, setupItem);
}
var close = widget.Get<ButtonWidget>("BACK_BUTTON");
close.OnClick = () => { Ui.CloseWindow(); onExit(); };
var save = widget.Get<ButtonWidget>("SAVE_BUTTON");
save.OnClick = () =>
{
if (string.IsNullOrEmpty(filename.Text))
return;
//.........这里部分代码省略.........
示例9: btn_DumpMinimaps_Click
void btn_DumpMinimaps_Click(object sender, EventArgs e)
{
const string exportPath = "C:\\Export";
const string minimapPath = exportPath + "\\Minimaps";
const string heightmapPath = exportPath + "\\Heightmaps";
const string metalmapPath = exportPath + "\\Metalmaps";
const string mapInfoPath = exportPath + "\\MapInfo";
Directory.CreateDirectory(exportPath);
Directory.CreateDirectory(minimapPath);
Directory.CreateDirectory(heightmapPath);
Directory.CreateDirectory(metalmapPath);
Directory.CreateDirectory(mapInfoPath);
using (var us = new UnitSync(Program.SpringPath)) {
int i = 0;
var count = GalaxyMap.Instance.Galaxy.MapNames.Count;
foreach (var mapName in GalaxyMap.Instance.Galaxy.MapNames) {
try {
var map = new Map(mapName, us.GetMapInfo(mapName), us.GetMapChecksum(mapName));
map.FixAspectRatio(us.GetMinimap(mapName, 0)).Save(minimapPath.Combine(mapName + ".png"), ImageFormat.Png);
us.GetHeightMap(mapName).Save(heightmapPath.Combine(mapName + ".png"), ImageFormat.Png);
us.GetMetalMap(mapName).Save(metalmapPath.Combine(mapName + ".png"), ImageFormat.Png);
map.Save(mapInfoPath.Combine(mapName + ".dat"));
} catch (Exception ex) {
Debug.WriteLine(string.Format("{0} is corrupted: coult not export data. ({1}/{2}", mapName, i++, count));
}
Debug.WriteLine(
"Extracted data from {0} ({1}/{2})".FormatWith(mapName, ++i, count));
}
}
}
示例10: SaveToDb
public void SaveToDb(string name)
{
Console.WriteLine ("Saving to db");
Map map = new Map () {
Height = this.h,
Width = this.w
};
GameState game = new GameState () {
Name = name,
Map = map,
};
string[] deleteTables = new string[] {
"gamestate",
"map",
"hex",
"hexresource",
"map_cities",
"map_rivers",
"map_hexes",
"hex_edges",
"hex_effects",
"kingdom"
};
foreach (string deleteTable in deleteTables)
MySqlProvider.Provider.ExecuteNonQuery ("truncate " + deleteTable + ";");
map.Game = game;
map.Save ();
game.Save ();
RecordList<Hex> hexes = new RecordList<Hex> ();
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
Hex hex = new Hex ();
hex.EnsureId ();
hex.X = x;
hex.Y = y;
Color c = b.GetPixel (x, y);
if (c == blue)
hex.Terrain = TerrainType.Sea;
else if (c == white)
hex.Terrain = TerrainType.Mountains;
else if (c == darkGreen)
hex.Terrain = TerrainType.Forest;
else if (c == town)
{
hex.Terrain = TerrainType.Plains;
}
else
hex.Terrain = TerrainType.Plains;
hexes.Add (hex);
hexMap[x,y] = hex;
}
}
//cities have to be done in a separate pass to account for growth.
map.Hexes = hexes;
map.EnsureMapIsBuilt (true);
//check coastals
foreach (Hex h in hexes)
if (h.Terrain == TerrainType.Sea)
CheckCoastal (h);
hexes.Save ();
foreach (var kvp in riverPaths)
{
River r = new River();
int z = 0;
foreach(Point p in kvp.Value)
{
r.Path.Add (new Triple<int> () {
X = p.X,
Y = p.Y,
Z = z++
});
}
r.Save ();
r.Path.Save ();
r.SaveRelations("Path");
map.Rivers.Add (r);
}
map.SaveRelations ("Rivers");
map.SaveRelations ("Hexes");
}
示例11: IniFile
void IUtilityCommand.Run(Utility utility, string[] args)
{
// HACK: The engine code assumes that Game.modData is set.
Game.ModData = utility.ModData;
var filename = args[1];
var file = new IniFile(File.Open(args[1], FileMode.Open));
var basic = file.GetSection("Basic");
var mapSection = file.GetSection("Map");
var tileset = mapSection.GetValue("Theater", "");
var iniSize = mapSection.GetValue("Size", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray();
var iniBounds = mapSection.GetValue("LocalSize", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray();
var size = new Size(iniSize[2], 2 * iniSize[3]);
var map = new Map(Game.ModData, utility.ModData.DefaultTileSets[tileset], size.Width, size.Height)
{
Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)),
Author = "Westwood Studios",
Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]),
RequiresMod = utility.ModData.Manifest.Id
};
var fullSize = new int2(iniSize[2], iniSize[3]);
ReadTiles(map, file, fullSize);
ReadActors(map, file, "Structures", fullSize);
ReadActors(map, file, "Units", fullSize);
ReadActors(map, file, "Infantry", fullSize);
ReadTerrainActors(map, file, fullSize);
ReadWaypoints(map, file, fullSize);
ReadOverlay(map, file, fullSize);
ReadLighting(map, file);
var spawnCount = map.ActorDefinitions.Count(n => n.Value.Value == "mpspawn");
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
map.Save(ZipFile.Create(dest, new Folder(".")));
Console.WriteLine(dest + " saved.");
}
示例12: Save
public static void Save(string Path, Map CurrentMap)
{
MapPath = Path;
CurrentMap.Save(Path+"\\Map.ege");
}
示例13: Run
protected void Run(Utility utility, string[] args)
{
// HACK: The engine code assumes that Game.modData is set.
Game.ModData = ModData = utility.ModData;
var filename = args[1];
using (var stream = File.OpenRead(filename))
{
var file = new IniFile(stream);
var basic = file.GetSection("Basic");
var player = basic.GetValue("Player", string.Empty);
if (!string.IsNullOrEmpty(player))
singlePlayer = !player.StartsWith("Multi");
var mapSection = file.GetSection("Map");
var format = GetMapFormatVersion(basic);
ValidateMapFormat(format);
// The original game isn't case sensitive, but we are.
var tileset = GetTileset(mapSection).ToUpperInvariant();
if (!ModData.DefaultTileSets.ContainsKey(tileset))
throw new InvalidDataException("Unknown tileset {0}".F(tileset));
Map = new Map(ModData, ModData.DefaultTileSets[tileset], MapSize, MapSize)
{
Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)),
Author = "Westwood Studios",
};
Map.RequiresMod = ModData.Manifest.Id;
SetBounds(Map, mapSection);
ReadPacks(file, filename);
ReadTrees(file);
LoadVideos(file, "BASIC");
LoadBriefing(file);
ReadActors(file);
LoadSmudges(file, "SMUDGE");
var waypoints = file.GetSection("Waypoints");
LoadWaypoints(waypoints);
// Create default player definitions only if there are no players to import
MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0);
foreach (var p in Players)
LoadPlayer(file, p);
Map.PlayerDefinitions = MapPlayers.ToMiniYaml();
}
Map.FixOpenAreas();
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
Map.Save(ZipFile.Create(dest, new Folder(".")));
Console.WriteLine(dest + " saved.");
}
示例14: CreateNewMap
private void CreateNewMap()
{
Texture2D CurrentTileFile = CurrentMap.TileSet;
NewMap dlg = new NewMap();
dlg.StartPosition = FormStartPosition.CenterParent;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
using (XNAUtils utils = new XNAUtils())
{
if (File.Exists(Project.Dir + "\\" + dlg.GetName() + ".plm"))
{
ShowPopup("Création d'une carte", "Une carte portant le même nom existe déjà. Vous devez choisir une carte avec un nom différent de " + dlg.Name, PopupReason.Error);
return;
}
// Pour éviter le bug des de la map out of bounds du Panel lors des scrolls à l'extrême bas-droit
PN_Map.Focus();
MapSize = new SizeI(dlg.GetSize());
CurrentMap = new Map(MapSize, Prefs.Map.TileSize.Width);
CurrentMap.Name = dlg.GetName();
CurrentMap.WasInit = true;
CurrentMap.TileSet = utils.ConvertToTexture(dlg.GetImage());
CurrentMap.FilePath = Project.Dir + "\\" + dlg.GetName() + ".plm";
CurrentMap.Save();
tabControlPanel1.AddTab(CurrentMap);
PN_Map.Dock = DockStyle.None;
PN_Map.Location = new System.Drawing.Point(0, 0);
PN_Map.Size = new System.Drawing.Size(CurrentMap.MapSize.Width * Prefs.Map.TileSize.Width + 1, CurrentMap.MapSize.Height * Prefs.Map.TileSize.Width + 1);
PN_Map.BackgroundImage = null;
PN_Map.Refresh();
PN_Tileset.Size = new System.Drawing.Size(CurrentMap.TileSet.Width, CurrentMap.TileSet.Height);
LastOpenedMapFile = CurrentMap.FilePath;
Text = "Pixel Lion - " + CurrentMap.Name;
EnableMapEditing();
// Enable History
History.Clear();
History.PushHistory(new MapState(CurrentMap.CloneTiles()));
// Reload Quick Maps
RefreshDevice();
DrawMap();
}
}