- Timestamp:
- Nov 5, 2014, 10:11:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r83 r84 200 200 end; 201 201 202 TPlayerCells = class; 203 TPlayerMap = class; 204 202 205 { TPlayerCell } 203 206 … … 206 209 InVisibleRange: Boolean; 207 210 MapCell: TCell; 211 List: TPlayerCells; 212 procedure LoadFromNode(Node: TDOMNode); 213 procedure SaveToNode(Node: TDOMNode); 208 214 end; 209 215 … … 211 217 212 218 TPlayerCells = class(TObjectList) 219 Map: TPlayerMap; 213 220 function SearchCell(Cell: TCell): TPlayerCell; 221 procedure LoadFromNode(Node: TDOMNode); 222 procedure SaveToNode(Node: TDOMNode); 214 223 end; 215 224 … … 219 228 Cells: TPlayerCells; 220 229 Player: TPlayer; 230 procedure LoadFromNode(Node: TDOMNode); 231 procedure SaveToNode(Node: TDOMNode); 221 232 procedure Update; 222 233 constructor Create; … … 480 491 end; 481 492 493 { TPlayerCell } 494 495 procedure TPlayerCell.LoadFromNode(Node: TDOMNode); 496 begin 497 Explored := ReadBoolean(Node, 'Explored', False); 498 MapCell := List.Map.Player.Game.Map.Cells.FindById(ReadInteger(Node, 'MapCell', 0)); 499 end; 500 501 procedure TPlayerCell.SaveToNode(Node: TDOMNode); 502 begin 503 WriteBoolean(Node, 'Explored', Explored); 504 WriteInteger(Node, 'MapCell', MapCell.Id); 505 end; 506 482 507 { TPlayerCells } 483 508 … … 492 517 end; 493 518 519 procedure TPlayerCells.LoadFromNode(Node: TDOMNode); 520 var 521 Node2: TDOMNode; 522 NewCell: TPlayerCell; 523 begin 524 Count := 0; 525 Node2 := Node.FirstChild; 526 while Assigned(Node2) and (Node2.NodeName = 'Cell') do begin 527 NewCell := TPlayerCell.Create; 528 NewCell.List := Self; 529 NewCell.LoadFromNode(Node2); 530 Add(NewCell); 531 Node2 := Node2.NextSibling; 532 end; 533 end; 534 535 procedure TPlayerCells.SaveToNode(Node: TDOMNode); 536 var 537 I: Integer; 538 NewNode: TDOMNode; 539 begin 540 for I := 0 to Count - 1 do begin; 541 NewNode := Node.OwnerDocument.CreateElement('Cell'); 542 Node.AppendChild(NewNode); 543 TPlayerCell(Items[I]).SaveToNode(NewNode); 544 end; 545 end; 546 494 547 { TPlayerMap } 548 549 procedure TPlayerMap.LoadFromNode(Node: TDOMNode); 550 var 551 NewNode: TDOMNode; 552 begin 553 with Node do begin 554 NewNode := FindNode('Cells'); 555 if Assigned(NewNode) then 556 Cells.LoadFromNode(NewNode); 557 end; 558 end; 559 560 procedure TPlayerMap.SaveToNode(Node: TDOMNode); 561 var 562 NewNode: TDOMNode; 563 begin 564 with Node do begin 565 NewNode := OwnerDocument.CreateElement('Cells'); 566 AppendChild(NewNode); 567 Cells.SaveToNode(NewNode); 568 end; 569 end; 495 570 496 571 procedure TPlayerMap.Update; … … 507 582 for I := 0 to Cells.Count - 1 do 508 583 with TPlayerCell(Cells[I]) do begin 584 List := Cells; 509 585 Explored := False; 510 586 InVisibleRange := False; … … 516 592 begin 517 593 Cells := TPlayerCells.Create; 594 Cells.Map := Self; 518 595 end; 519 596 … … 1569 1646 1570 1647 procedure TPlayer.LoadFromNode(Node: TDOMNode); 1648 var 1649 NewNode: TDOMNode; 1571 1650 begin 1572 1651 Id := ReadInteger(Node, 'Id', 0); … … 1576 1655 StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0)); 1577 1656 StartUnits := ReadInteger(Node, 'StartUnits', 0); 1657 1658 with Node do begin 1659 NewNode := FindNode('Map'); 1660 if Assigned(NewNode) then 1661 PlayerMap.LoadFromNode(NewNode); 1662 end; 1578 1663 end; 1579 1664 1580 1665 procedure TPlayer.SaveToNode(Node: TDOMNode); 1666 var 1667 NewNode: TDOMNode; 1581 1668 begin 1582 1669 WriteInteger(Node, 'Id', Id); … … 1586 1673 WriteInteger(Node, 'StartCell', StartCell.Id); 1587 1674 WriteInteger(Node, 'StartUnits', StartUnits); 1675 1676 with Node do begin 1677 NewNode := OwnerDocument.CreateElement('Map'); 1678 AppendChild(NewNode); 1679 PlayerMap.SaveToNode(NewNode); 1680 end; 1588 1681 end; 1589 1682
Note:
See TracChangeset
for help on using the changeset viewer.