- Timestamp:
- Oct 26, 2022, 5:25:25 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r121 r122 119 119 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 120 120 begin 121 //Engine.SaveToFile('Game.bmg'); 121 122 Core.PersistentForm1.Save(Self); 122 123 end; -
trunk/Languages/BigMetro.cs.po
r118 r122 251 251 msgstr "týden" 252 252 253 #: uengine.swrongfileformat 254 msgid "Wrong file format" 255 msgstr "Špatný formát souboru" 256 253 257 #: uformmain.sfridayshort 254 258 msgid "FRI" -
trunk/Languages/BigMetro.de.po
r118 r122 253 253 msgstr "" 254 254 255 #: uengine.swrongfileformat 256 msgid "Wrong file format" 257 msgstr "" 258 255 259 #: uformmain.sfridayshort 256 260 msgid "FRI" -
trunk/Languages/BigMetro.fr.po
r118 r122 253 253 msgstr "" 254 254 255 #: uengine.swrongfileformat 256 msgid "Wrong file format" 257 msgstr "" 258 255 259 #: uformmain.sfridayshort 256 260 msgid "FRI" -
trunk/Languages/BigMetro.pot
r118 r122 241 241 msgstr "" 242 242 243 #: uengine.swrongfileformat 244 msgid "Wrong file format" 245 msgstr "" 246 243 247 #: uformmain.sfridayshort 244 248 msgid "FRI" -
trunk/UEngine.pas
r121 r122 10 10 URegistry, UMetaCanvas, Generics.Collections, Generics.Defaults, UMenu, 11 11 UControls, UMetroPassenger, UColors, UView, URiver, UTrack, UCity, UGeometric, 12 U PersistentForm, UTranslator;12 UTranslator, DOM, XMLRead, XMLWrite, UXMLUtils; 13 13 14 14 type … … 37 37 function GetMaxPassengers: Integer; 38 38 function IsBestStationForShape(Shape: TStationShape; Check, Current: TLineStation): Boolean; 39 procedure LoadFromXmlNode(Node: TDOMNode); 40 procedure SaveToXmlNode(Node: TDOMNode); 39 41 constructor Create; 40 42 destructor Destroy; override; … … 47 49 function GetRect: TRect; 48 50 function AddNew: TMapStation; 51 procedure LoadFromXmlNode(Node: TDOMNode); 52 procedure SaveToXmlNode(Node: TDOMNode); 49 53 end; 50 54 … … 71 75 procedure UpdateEndingLines; 72 76 public 77 Id: Integer; 73 78 Index: Integer; 74 79 Engine: TEngine; … … 82 87 destructor Destroy; override; 83 88 function IsCircular: Boolean; 89 procedure LoadFromXmlNode(Node: TDOMNode); 90 procedure SaveToXmlNode(Node: TDOMNode); 84 91 end; 85 92 … … 89 96 Engine: TEngine; 90 97 function AddNew(Color: TColor): TMetroLine; 98 function FindById(Id: Integer): TMetroLine; 91 99 function SearchByColor(Color: TColor): TMetroLine; 100 procedure LoadFromXmlNode(Node: TDOMNode); 101 procedure SaveToXmlNode(Node: TDOMNode); 92 102 end; 93 103 … … 121 131 procedure SetLine(AValue: TMetroLine); 122 132 public 133 Engine: TEngine; 123 134 Passengers: TMetroPassengers; 124 135 TrackPosition: TTrackPosition; … … 127 138 TargetStation: TLineStation; 128 139 Carriages: TMetroCarriages; 140 procedure LoadFromXmlNode(Node: TDOMNode); 141 procedure SaveToXmlNode(Node: TDOMNode); 129 142 procedure FindTargetStation; 130 143 function GetTargetStationDistance: Integer; … … 140 153 function GetUnusedCount: Integer; 141 154 function AddNew: TMetroTrain; 155 procedure LoadFromXmlNode(Node: TDOMNode); 156 procedure SaveToXmlNode(Node: TDOMNode); 142 157 end; 143 158 … … 309 324 procedure LoadFromRegistry; 310 325 procedure SaveToRegistry; 326 procedure LoadFromFile(FileName: string); 327 procedure SaveToFile(FileName: string); 311 328 constructor Create(AOwner: TComponent); override; 312 329 destructor Destroy; override; … … 397 414 SSuccessReason = 'Your metro transported enough passengers and you have reached your goal for this city.'; 398 415 SUnlockedCity = 'City %s is now unlocked.'; 416 SWrongFileFormat = 'Wrong file format'; 399 417 400 418 // Cities … … 513 531 Result := TMetroTrain.Create; 514 532 Add(Result); 533 end; 534 535 procedure TMetroTrains.LoadFromXmlNode(Node: TDOMNode); 536 var 537 Node2: TDOMNode; 538 NewItem: TMetroTrain; 539 begin 540 Node2 := Node.FirstChild; 541 while Assigned(Node2) and (Node2.NodeName = 'Train') do begin 542 NewItem := TMetroTrain.Create; 543 NewItem.LoadFromXmlNode(Node2); 544 Add(NewItem); 545 Node2 := Node2.NextSibling; 546 end; 547 end; 548 549 procedure TMetroTrains.SaveToXmlNode(Node: TDOMNode); 550 var 551 I: Integer; 552 NewNode: TDOMNode; 553 begin 554 for I := 0 to Count - 1 do begin; 555 NewNode := Node.OwnerDocument.CreateElement('Train'); 556 Node.AppendChild(NewNode); 557 Items[I].SaveToXmlNode(NewNode); 558 end; 515 559 end; 516 560 … … 568 612 end; 569 613 614 procedure TMapStations.LoadFromXmlNode(Node: TDOMNode); 615 var 616 Node2: TDOMNode; 617 NewItem: TMapStation; 618 begin 619 Node2 := Node.FirstChild; 620 while Assigned(Node2) and (Node2.NodeName = 'Line') do begin 621 NewItem := TMapStation.Create; 622 NewItem.LoadFromXmlNode(Node2); 623 Add(NewItem); 624 Node2 := Node2.NextSibling; 625 end; 626 end; 627 628 procedure TMapStations.SaveToXmlNode(Node: TDOMNode); 629 var 630 I: Integer; 631 NewNode: TDOMNode; 632 begin 633 for I := 0 to Count - 1 do begin; 634 NewNode := Node.OwnerDocument.CreateElement('Station'); 635 Node.AppendChild(NewNode); 636 Items[I].SaveToXmlNode(NewNode); 637 end; 638 end; 639 570 640 { TMetroLines } 571 641 … … 579 649 end; 580 650 651 function TMetroLines.FindById(Id: Integer): TMetroLine; 652 var 653 I: Integer; 654 begin 655 I := 0; 656 while (I < Count) and (Items[I].Id <> Id) do Inc(I); 657 if I < Count then Result := Items[I] 658 else Result := nil; 659 end; 660 581 661 function TMetroLines.SearchByColor(Color: TColor): TMetroLine; 582 662 var … … 587 667 if I < Count then Result := Items[I] 588 668 else Result := nil; 669 end; 670 671 procedure TMetroLines.LoadFromXmlNode(Node: TDOMNode); 672 var 673 Node2: TDOMNode; 674 NewItem: TMetroLine; 675 begin 676 Node2 := Node.FirstChild; 677 while Assigned(Node2) and (Node2.NodeName = 'Line') do begin 678 NewItem := TMetroLine.Create; 679 NewItem.LoadFromXmlNode(Node2); 680 Add(NewItem); 681 Node2 := Node2.NextSibling; 682 end; 683 end; 684 685 procedure TMetroLines.SaveToXmlNode(Node: TDOMNode); 686 var 687 I: Integer; 688 NewNode: TDOMNode; 689 begin 690 for I := 0 to Count - 1 do begin; 691 NewNode := Node.OwnerDocument.CreateElement('Line'); 692 Node.AppendChild(NewNode); 693 Items[I].SaveToXmlNode(NewNode); 694 end; 589 695 end; 590 696 … … 786 892 end; 787 893 894 procedure TMetroLine.LoadFromXmlNode(Node: TDOMNode); 895 var 896 Node2: TDOMNode; 897 begin 898 Id := ReadInteger(Node, 'Id', Id); 899 Color := TColor(ReadInteger(Node, 'Color', Color)); 900 901 Node2 := Node.FindNode('Track'); 902 if Assigned(Node2) then 903 Track.LoadFromXmlNode(Node2); 904 end; 905 906 procedure TMetroLine.SaveToXmlNode(Node: TDOMNode); 907 var 908 Node2: TDOMNode; 909 begin 910 WriteInteger(Node, 'Id', Id); 911 WriteInteger(Node, 'Color', Color); 912 913 Node2 := Node.OwnerDocument.CreateElement('Track'); 914 Node.AppendChild(Node2); 915 Track.SaveToXmlNode(Node2); 916 end; 917 788 918 { TMetroTrain } 789 919 … … 797 927 TargetStation := nil; 798 928 end; 929 end; 930 931 procedure TMetroTrain.LoadFromXmlNode(Node: TDOMNode); 932 begin 933 Line := Engine.Lines.FindById(ReadInteger(Node, 'Line', 0)); 934 end; 935 936 procedure TMetroTrain.SaveToXmlNode(Node: TDOMNode); 937 begin 938 if Assigned(Line) then WriteInteger(Node, 'Line', Line.Id) 939 else WriteInteger(Node, 'Line', 0); 799 940 end; 800 941 … … 1031 1172 Result := (Check.MapStation.ShapeDistance[Shape] <> -1) and 1032 1173 (Check.MapStation.ShapeDistance[Shape] <= Distance); 1174 end; 1175 1176 procedure TMapStation.LoadFromXmlNode(Node: TDOMNode); 1177 begin 1178 Position.X := ReadInteger(Node, 'PositionX', Position.X); 1179 Position.Y := ReadInteger(Node, 'PositionY', Position.Y); 1180 Shape := TStationShape(ReadInteger(Node, 'Shape', Integer(Shape))); 1181 IsTerminal := ReadBoolean(Node, 'IsTerminal', IsTerminal); 1182 end; 1183 1184 procedure TMapStation.SaveToXmlNode(Node: TDOMNode); 1185 begin 1186 WriteInteger(Node, 'PositionX', Position.X); 1187 WriteInteger(Node, 'PositionY', Position.Y); 1188 WriteInteger(Node, 'Shape', Integer(Shape)); 1189 WriteBoolean(Node, 'IsTerminal', IsTerminal); 1033 1190 end; 1034 1191 … … 3369 3526 finally 3370 3527 Free; 3528 end; 3529 end; 3530 3531 procedure TEngine.LoadFromFile(FileName: string); 3532 var 3533 NewNode: TDOMNode; 3534 Doc: TXMLDocument; 3535 RootNode: TDOMNode; 3536 begin 3537 ReadXMLFile(Doc, FileName); 3538 Clear; 3539 with Doc do try 3540 if Doc.DocumentElement.NodeName <> 'BigMetroGame' then 3541 raise Exception.Create(SWrongFileFormat); 3542 RootNode := Doc.DocumentElement; 3543 with RootNode do begin 3544 ServedPassengerCount := ReadInteger(RootNode, 'ServedPassengerCount', ServedPassengerCount); 3545 3546 NewNode := FindNode('Stations'); 3547 Stations.LoadFromXmlNode(NewNode); 3548 3549 NewNode := FindNode('Lines'); 3550 Lines.LoadFromXmlNode(NewNode); 3551 3552 NewNode := FindNode('Trains'); 3553 Trains.LoadFromXmlNode(NewNode); 3554 end; 3555 finally 3556 FreeAndNil(Doc); 3557 end; 3558 end; 3559 3560 procedure TEngine.SaveToFile(FileName: string); 3561 var 3562 NewNode: TDOMNode; 3563 Doc: TXMLDocument; 3564 RootNode: TDOMNode; 3565 I: Integer; 3566 begin 3567 Doc := TXMLDocument.Create; 3568 with Doc do try 3569 RootNode := CreateElement('BigMetroGame'); 3570 AppendChild(RootNode); 3571 with RootNode do begin 3572 WriteInteger(RootNode, 'ServedPassengerCount', ServedPassengerCount); 3573 3574 for I := 0 to Lines.Count - 1 do 3575 Lines[I].Id := I + 1; 3576 3577 NewNode := OwnerDocument.CreateElement('Stations'); 3578 AppendChild(NewNode); 3579 Stations.SaveToXmlNode(NewNode); 3580 3581 NewNode := OwnerDocument.CreateElement('Lines'); 3582 AppendChild(NewNode); 3583 Lines.SaveToXmlNode(NewNode); 3584 3585 NewNode := OwnerDocument.CreateElement('Trains'); 3586 AppendChild(NewNode); 3587 Trains.SaveToXmlNode(NewNode); 3588 end; 3589 if ExtractFileDir(FileName) <> '' then 3590 ForceDirectories(ExtractFileDir(FileName)); 3591 WriteXMLFile(Doc, FileName); 3592 finally 3593 FreeAndNil(Doc); 3371 3594 end; 3372 3595 end; -
trunk/UTrack.pas
r107 r122 4 4 5 5 uses 6 Classes, SysUtils, Math, Generics.Collections, UGeometric; 6 Classes, SysUtils, Math, Generics.Collections, UGeometric, DOM, XMLRead, 7 XMLWrite, UXMLUtils; 7 8 8 9 type … … 48 49 // Move to TTrackLink later 49 50 function GetDistance: Integer; 51 52 procedure LoadFromXmlNode(Node: TDOMNode); 53 procedure SaveToXmlNode(Node: TDOMNode); 50 54 constructor Create; 51 55 destructor Destroy; override; … … 57 61 Track: TTrack; 58 62 function AddNew: TTrackPoint; 63 procedure LoadFromXmlNode(Node: TDOMNode); 64 procedure SaveToXmlNode(Node: TDOMNode); 59 65 end; 60 66 … … 64 70 Points: TTrackPoints; 65 71 Shift: TPoint; 72 procedure LoadFromXmlNode(Node: TDOMNode); 73 procedure SaveToXmlNode(Node: TDOMNode); 66 74 constructor Create; 67 75 destructor Destroy; override; … … 73 81 function SearchPoints(Point1, Point2: TTrackPoint): TTrackLink; 74 82 function AddNew: TTrackLink; 83 procedure LoadFromXmlNode(Node: TDOMNode); 84 procedure SaveToXmlNode(Node: TDOMNode); 75 85 end; 76 86 … … 86 96 constructor Create; 87 97 destructor Destroy; override; 98 procedure LoadFromXmlNode(Node: TDOMNode); 99 procedure SaveToXmlNode(Node: TDOMNode); 88 100 end; 89 101 … … 200 212 end; 201 213 214 procedure TTrackLinks.LoadFromXmlNode(Node: TDOMNode); 215 var 216 Node2: TDOMNode; 217 NewItem: TTrackLink; 218 begin 219 Node2 := Node.FirstChild; 220 while Assigned(Node2) and (Node2.NodeName = 'Link') do begin 221 NewItem := TTrackLink.Create; 222 NewItem.LoadFromXmlNode(Node2); 223 Add(NewItem); 224 Node2 := Node2.NextSibling; 225 end; 226 end; 227 228 procedure TTrackLinks.SaveToXmlNode(Node: TDOMNode); 229 var 230 I: Integer; 231 Node2: TDOMNode; 232 begin 233 for I := 0 to Count - 1 do begin; 234 Node2 := Node.OwnerDocument.CreateElement('Link'); 235 Node.AppendChild(Node2); 236 Items[I].SaveToXmlNode(Node2); 237 end; 238 end; 239 202 240 { TTrackPoints } 203 241 … … 206 244 Result := TTrackPoint.Create; 207 245 Result.Track := Track; 246 end; 247 248 procedure TTrackPoints.LoadFromXmlNode(Node: TDOMNode); 249 var 250 Node2: TDOMNode; 251 NewItem: TTrackPoint; 252 begin 253 Node2 := Node.FirstChild; 254 while Assigned(Node2) and (Node2.NodeName = 'Point') do begin 255 NewItem := TTrackPoint.Create; 256 NewItem.LoadFromXmlNode(Node2); 257 Add(NewItem); 258 Node2 := Node2.NextSibling; 259 end; 260 end; 261 262 procedure TTrackPoints.SaveToXmlNode(Node: TDOMNode); 263 var 264 I: Integer; 265 Node2: TDOMNode; 266 begin 267 for I := 0 to Count - 1 do begin; 268 Node2 := Node.OwnerDocument.CreateElement('Point'); 269 Node.AppendChild(Node2); 270 Items[I].SaveToXmlNode(Node2); 271 end; 208 272 end; 209 273 … … 222 286 FreeAndNil(Links); 223 287 inherited; 288 end; 289 290 procedure TTrack.LoadFromXmlNode(Node: TDOMNode); 291 begin 292 Points.LoadFromXmlNode(Node); 293 Links.LoadFromXmlNode(Node); 294 end; 295 296 procedure TTrack.SaveToXmlNode(Node: TDOMNode); 297 begin 298 Points.SaveToXmlNode(Node); 299 Links.SaveToXmlNode(Node); 224 300 end; 225 301 … … 281 357 { TTrackLink } 282 358 359 procedure TTrackLink.LoadFromXmlNode(Node: TDOMNode); 360 begin 361 362 end; 363 364 procedure TTrackLink.SaveToXmlNode(Node: TDOMNode); 365 begin 366 367 end; 368 283 369 constructor TTrackLink.Create; 284 370 begin … … 444 530 end; 445 531 532 procedure TTrackPoint.LoadFromXmlNode(Node: TDOMNode); 533 begin 534 Position.X := ReadInteger(Node, 'PositionX', Position.X); 535 Position.Y := ReadInteger(Node, 'PositionY', Position.Y); 536 end; 537 538 procedure TTrackPoint.SaveToXmlNode(Node: TDOMNode); 539 begin 540 WriteInteger(Node, 'PositionX', Position.X); 541 WriteInteger(Node, 'PositionY', Position.Y); 542 end; 543 446 544 constructor TTrackPoint.Create; 447 545 begin
Note:
See TracChangeset
for help on using the changeset viewer.