Changeset 64 for trunk/UEngine.pas
- Timestamp:
- Jan 7, 2023, 12:10:51 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r62 r64 4 4 5 5 uses 6 Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, 6 Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry, 7 7 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle, 8 8 Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, XMLConf, DOM, … … 143 143 destructor Destroy; override; 144 144 procedure Assign(Source: TPlayer); 145 procedure Load Config(Config: TXMLConfig; Path: string);146 procedure Save Config(Config: TXMLConfig; Path: string);145 procedure LoadFromRegistry(Context: TRegistryContext); 146 procedure SaveToRegistry(Context: TRegistryContext); 147 147 property Exploded: Boolean read FExploded write SetExploded; 148 148 end; … … 154 154 function AddNew: TPlayer; 155 155 procedure Assign(Players: TPlayers); 156 procedure Load Config(Config: TXMLConfig; Path: string);157 procedure Save Config(Config: TXMLConfig; Path: string);156 procedure LoadFromRegistry(Context: TRegistryContext); 157 procedure SaveToRegistry(Context: TRegistryContext); 158 158 function GetAliveCount: Integer; 159 159 function GetWinner: TPlayer; … … 210 210 procedure Redraw; 211 211 function IsInsideHouses(Pos: TPoint): Boolean; 212 procedure InitPlayerPool;213 212 procedure InitPlayers; 214 213 procedure CheckGameEnd; … … 243 242 procedure NewGame; 244 243 procedure NewRound; 245 procedure LoadConfig(Config: TXMLConfig; Path: string);246 procedure SaveConfig(Config: TXMLConfig; Path: string);247 244 procedure KeyUp(Key: Word); 248 245 procedure KeyDown(Key: Word); 246 procedure LoadFromRegistry(Context: TRegistryContext); 247 procedure SaveToRegistry(Context: TRegistryContext); 248 procedure InitPlayerPool; 249 249 property Bitmap: TBitmap read FBitmap write SetBitmap; 250 250 property Active: Boolean read FActive write SetActive; … … 317 317 end; 318 318 319 procedure TPlayers.SaveConfig(Config: TXMLConfig; Path: string); 320 var 321 I: Integer; 322 begin 323 Config.SetValue(DOMString(Path + '/Count'), Count); 324 for I := 0 to Count - 1 do 325 Items[I].SaveConfig(Config, Path + '/Player' + IntToStr(I)); 319 procedure TPlayers.LoadFromRegistry(Context: TRegistryContext); 320 var 321 Player: TPlayer; 322 begin 323 for Player in Self do begin 324 Player.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + IntToStr(Player.Id))); 325 end; 326 end; 327 328 procedure TPlayers.SaveToRegistry(Context: TRegistryContext); 329 var 330 Player: TPlayer; 331 begin 332 for Player in Self do begin 333 Player.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + IntToStr(Player.Id))); 334 end; 326 335 end; 327 336 … … 348 357 TopScore := Score; 349 358 Result := Items[I]; 350 end;351 end;352 353 procedure TPlayers.LoadConfig(Config: TXMLConfig; Path: string);354 var355 I: Integer;356 NewCount: Integer;357 begin358 NewCount := Config.GetValue(DOMString(Path + '/Count'), 0);359 while Count > NewCount do Delete(Count - 1);360 while Count < NewCount do Add(TPlayer.Create);361 for I := 0 to Count - 1 do begin362 Items[I].Engine := Engine;363 Items[I].Id := I;364 Items[I].LoadConfig(Config, Path + '/Player' + IntToStr(I));365 359 end; 366 360 end; … … 965 959 end; 966 960 967 procedure TPlayer.LoadConfig(Config: TXMLConfig; Path: string); 968 begin 969 with Config do begin 970 Self.Name := string(GetValue(DOMString(Path + '/Name'), UnicodeString(Name))); 971 Color1 := GetValue(DOMString(Path + '/Color1'), Color1); 972 Color2 := GetValue(DOMString(Path + '/Color2'), Color2); 973 Enabled := GetValue(DOMString(Path + '/Enabled'), Enabled); 974 Keys.Left := GetValue(DOMString(Path + '/Keys/Left'), Keys.Left); 975 Keys.Right := GetValue(DOMString(Path + '/Keys/Right'), Keys.Right); 976 Keys.Down := GetValue(DOMString(Path + '/Keys/Down'), Keys.Down); 977 Keys.Up := GetValue(DOMString(Path + '/Keys/Up'), Keys.Up); 978 Keys.Shoot := GetValue(DOMString(Path + '/Keys/Shoot'), Keys.Shoot); 979 end; 980 InitTanks; 981 end; 982 983 procedure TPlayer.SaveConfig(Config: TXMLConfig; Path: string); 984 begin 985 with Config do begin 986 SetValue(DOMString(Path + '/Name'), DOMString(Self.Name)); 987 SetValue(DOMString(Path + '/Color1'), Color1); 988 SetValue(DOMString(Path + '/Color2'), Color2); 989 SetValue(DOMString(Path + '/Enabled'), Enabled); 990 SetValue(DOMString(Path + '/Keys/Left'), Keys.Left); 991 SetValue(DOMString(Path + '/Keys/Right'), Keys.Right); 992 SetValue(DOMString(Path + '/Keys/Down'), Keys.Down); 993 SetValue(DOMString(Path + '/Keys/Up'), Keys.Up); 994 SetValue(DOMString(Path + '/Keys/Shoot'), Keys.Shoot); 961 procedure TPlayer.LoadFromRegistry(Context: TRegistryContext); 962 begin 963 with TRegistryEx.Create do 964 try 965 CurrentContext := Context; 966 Name := ReadStringWithDefault('Name', Name); 967 Color1 := ReadIntegerWithDefault('Color1', Color1); 968 Color2 := ReadIntegerWithDefault('Color2', Color2); 969 Enabled := ReadBoolWithDefault('Enabled', Enabled); 970 Keys.Left := ReadIntegerWithDefault('KeysLeft', Keys.Left); 971 Keys.Right := ReadIntegerWithDefault('KeyRight', Keys.Right); 972 Keys.Down := ReadIntegerWithDefault('KeyDown', Keys.Down); 973 Keys.Up := ReadIntegerWithDefault('KeyUp', Keys.Up); 974 Keys.Shoot := ReadIntegerWithDefault('KeyShoot', Keys.Shoot); 975 finally 976 Free; 977 end; 978 end; 979 980 procedure TPlayer.SaveToRegistry(Context: TRegistryContext); 981 begin 982 with TRegistryEx.Create do 983 try 984 CurrentContext := Context; 985 WriteString('Name', Name); 986 WriteInteger('Color1', Color1); 987 WriteInteger('Color2', Color2); 988 WriteBool('Enabled', Enabled); 989 WriteInteger('KeysLeft', Keys.Left); 990 WriteInteger('KeyRight', Keys.Right); 991 WriteInteger('KeyDown', Keys.Down); 992 WriteInteger('KeyUp', Keys.Up); 993 WriteInteger('KeyShoot', Keys.Shoot); 994 finally 995 Free; 995 996 end; 996 997 end; … … 1728 1729 end; 1729 1730 1730 procedure TEngine.LoadConfig(Config: TXMLConfig; Path: string); 1731 begin 1732 PlayerPool.LoadConfig(Config, Path + '/Players'); 1733 end; 1734 1735 procedure TEngine.SaveConfig(Config: TXMLConfig; Path: string); 1736 begin 1737 PlayerPool.SaveConfig(Config, Path + '/Players'); 1731 procedure TEngine.LoadFromRegistry(Context: TRegistryContext); 1732 begin 1733 with TRegistryEx.Create do 1734 try 1735 CurrentContext := Context; 1736 PlayerPool.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\Players')); 1737 finally 1738 Free; 1739 end; 1740 end; 1741 1742 procedure TEngine.SaveToRegistry(Context: TRegistryContext); 1743 begin 1744 with TRegistryEx.Create do 1745 try 1746 CurrentContext := Context; 1747 1748 PlayerPool.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\Players')); 1749 finally 1750 Free; 1751 end; 1738 1752 end; 1739 1753
Note:
See TracChangeset
for help on using the changeset viewer.