/// <summary> /// Загрузка из JSON по указанному пути /// </summary> public SpaceMap LoadFromJson(string name) { string path = Application.dataPath + "/" + name + ".json";//"maps/" + name; string filetext = string.Empty; string line; System.IO.StreamReader theReader = new System.IO.StreamReader(path, System.Text.Encoding.Default); using (theReader) { do { line = theReader.ReadLine(); if (line != null) { filetext += line; } }while (line != null); theReader.Close(); } SpaceMap loadedMap = JsonUtility.FromJson <SpaceMap>(filetext); return(loadedMap); }
public void Enter(IArea area) { CurrentArea = area; SpaceMap.Add(area.Locations); Trader.Enter(area); Worker.Enter(area); SpaceCamera.MoveTo(area); }
private void UnloadSpecialCargoTo(ILocation location) { var targetLocation = location == null?SpaceMap.GetAnyLocation() : SpaceMap.GetAnyLocationExcept(location); CurrentDelivery.Name = ""; CurrentDelivery.Source = null; CurrentDelivery.Destination = targetLocation; TargetMarker.GoTo(CurrentDelivery.Destination); }
private void LoadSpecialCargoFrom(ILocation location = null) { var targetLocation = location == null?SpaceMap.GetAnyLocation() : SpaceMap.GetAnyLocationExcept(location); CurrentDelivery.Name = SpecialDeliveries.OrderBy(Randomized).First().Name; CurrentDelivery.Source = location; CurrentDelivery.Destination = targetLocation; TargetMarker.GoTo(CurrentDelivery.Destination); }
public SpaceMap SaveToMap(Vector3Int sizes) { SpaceMap spaceMap = new SpaceMap(sizes, shiprait); for (int h = -sizes.y / 2 + 1; h < sizes.y / 2; h++) { for (int w = -sizes.x / 2 + 1; w < sizes.x / 2; w++) { spaceMap.planetList.Add(GetPlanet(new Vector3Int(w, h, 0))); } } return(spaceMap); }
public SpaceMap CreateSmallTestMap() { SpaceMap spaceMap = new SpaceMap(5, 5); for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { //TODO: fix my SmallTestMap //bool isEdge = x == 0 || y == 0 || x == 4 || y == 4; var s = new Space() { //Terrain = isEdge ? ttWall : ttFloor }; spaceMap.Add(s, (x, y)); } } //var sp = spaceMap.GetItem((3, 4)); //sp.Terrain = ttDoorClosed; return(spaceMap); }
public void ChangeLocation() { if (Key == null) { return; } Log.InfoFormat("[Pilot '{3}'] Publish system with key {0} from {1} to {2} ", Name, LocationPreviousSystemName, LocationCurrentSystemName, Name); SpaceMap.Publish(Name, LocationPreviousSystemName, LocationCurrentSystemName); if (OnChangeSolarSystem == null) { return; } Log.InfoFormat("[Pilot '{3}'] Call OnChangeSolarSystem with key after publish {0} from {1} to {2} ", Name, LocationPreviousSystemName, LocationCurrentSystemName, Name); try { SpaceMap.SelectedSolarSystemName = LocationCurrentSystemName; if (OnChangeSolarSystem != null) { OnChangeSolarSystem(this, LocationPreviousSystemName, LocationCurrentSystemName); } if (OnEnterToSolarSystem != null) { OnEnterToSolarSystem(Name, LocationPreviousSystemName, LocationCurrentSystemName); } } catch (Exception exception) { Log.ErrorFormat("[PilotEntity.ChangeLocation] Critical error = {0}", exception); } }
public void ApplyToMap(SpaceMap map, EntityWorld world) { }
/// <summary> /// Process results from "Edit statement on space map" feature. /// </summary> /// <param name="curStatement">Statement being edited</param> /// <param name="result">Result from space map dialog</param> private void ParseSpaceMapStatementResults(MissionStatement curStatement, SpaceMap.Space result) { if (result == null) return; curStatement.FromXml(result.SelectionSpecial.ToXml(new XmlDocument())); curStatement.Update(); OutputMissionNodeContentsToStatementTree(); RegisterChange("Changes to statement via space map"); }
/// <summary> /// Insert "Create Nameless" statement to the node. Called from ParseSpaceMapCreateResults. /// </summary> private void ParseSpaceMapCreateResults_InsertNameless(ref int i, MissionNode curNode, int position, SpaceMap.Space result, XmlDocument xDoc, List<string> missingProperties) { i--; missingProperties.Clear(); curNode.Actions.Insert(position, MissionStatement.NewFromXML(result.NamelessObjects[i].ToXml(xDoc, missingProperties), curNode)); if (missingProperties.Count > 0 && Settings.Current.AddFailureComments) { curNode.Actions.Insert(position, MissionStatement.NewFromXML(xDoc.CreateComment("will fail because it lacks " + missingProperties.Aggregate((x, y) => x + ", " + y) + " "), curNode)); } }
/// <summary> /// Process results from "Add via space map" or "Edit on space map" features. /// Adds and removes nessecary actions to the current statement. /// </summary> /// <param name="toDelete">List of original statements that were submitted for editing.</param> /// <param name="topmost">Target position where new actions are placed</param> /// <param name="result">Result received from the space map form</param> private void ParseSpaceMapCreateResults(List<MissionStatement> toDelete, int topmost, SpaceMap.Space result) { if (result == null) return; int i; MissionNode curNode = (MissionNode)TreeViewNodes.SelectedNode.Tag; List<string> missingProperties = new List<string>(); XmlDocument xDoc = new XmlDocument(); //Target point for all objects that are not after an Imported object int target_point = topmost == -1 ? curNode.Actions.Count : topmost; // Import Named objects from Space map i = result.NamedObjects.Count; // Can't exactly remember what happens here. Original intention here seems to have been: // Go through list of originally imported statements and try to match them to the new statements // For each originally imported statement, put one new statement in its place // When out of statements, add all remaining statements to where it's set in the settings while (result.NamedIdList.Count > 0) { ParseSpaceMapCreateResults_InsertNamed(ref i, curNode, result.NamedIdList[result.NamedIdList.Count - 1], result, xDoc, missingProperties); if (result.NamedObjects[i].Imported) result.NamedIdList.RemoveAt(result.NamedIdList.Count - 1); } while (i > 0) { ParseSpaceMapCreateResults_InsertNamed(ref i, curNode, target_point, result, xDoc, missingProperties); } // Import nameless objects from Space map i = result.NamelessObjects.Count; while (result.NamelessIdList.Count > 0) { ParseSpaceMapCreateResults_InsertNameless(ref i, curNode, result.NamelessIdList[result.NamelessIdList.Count - 1], result, xDoc, missingProperties); if (result.NamelessObjects[i].Imported) result.NamelessIdList.RemoveAt(result.NamelessIdList.Count - 1); } while (i > 0) { ParseSpaceMapCreateResults_InsertNameless(ref i, curNode, target_point, result, xDoc, missingProperties); } //Final stuff foreach (MissionStatement statement in toDelete) curNode.Actions.Remove(statement); OutputMissionNodeContentsToStatementTree(); RegisterChange("Changes to create statements via space map"); }
public void ApplyToMap(SpaceMap map, EntityWorld world) { throw new NotImplementedException(); }