Changeset 106 for trunk/UGame.pas


Ignore:
Timestamp:
Jan 17, 2015, 8:22:44 PM (10 years ago)
Author:
chronos
Message:
  • Added: Check for some configuration values loaded as integers to enumeration type.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r105 r106  
    26372637
    26382638procedure TGame.LoadConfig(Config: TXmlConfig; Path: string);
     2639var
     2640  Value: Integer;
    26392641begin
    26402642  with Config do begin
     
    26472649    Map.Size := Point(GetValue(Path + '/MapSizeX', 10),
    26482650      GetValue(Path + '/MapSizeY', 10));
    2649     Map.Shape := TMapShape(GetValue(Path + '/MapShape', 0));
     2651    Value := GetValue(Path + '/MapShape', 0);
     2652    if (Value >= Integer(Low(TMapShape))) and (Value <= Integer(High(TMapShape))) then
     2653      Map.Shape := TMapShape(Value) else Map.Shape := Low(TMapShape);
    26502654    CityEnabled := GetValue(Path + '/CityEnabled', False);
    26512655    CityPercentage := GetValue(Path + '/CityPercentage', 10);
    26522656    BridgeEnabled := GetValue(Path + '/BridgeEnabled', True);
    2653     GrowAmount := TGrowAmount(GetValue(Path + '/GrowAmount', Integer(gaBySquareRoot)));
    2654     GrowCells := TGrowCells(GetValue(Path + '/GrowCells', Integer(gcPlayerAll)));
    2655     WinObjective := TWinObjective(GetValue(Path + '/WinObjective', Integer(woDefeatAllOponents)));
     2657    Value := GetValue(Path + '/GrowAmount', Integer(gaBySquareRoot));
     2658    if (Value >= Integer(Low(TGrowAmount))) and (Value <= Integer(High(TGrowAmount))) then
     2659      GrowAmount := TGrowAmount(Value) else GrowAmount := Low(TGrowAmount);
     2660    Value := GetValue(Path + '/GrowCells', Integer(gcPlayerAll));
     2661    if (Value >= Integer(Low(TGrowCells))) and (Value <= Integer(High(TGrowCells))) then
     2662      GrowCells := TGrowCells(Value) else GrowCells := Low(TGrowCells);
     2663    Value := GetValue(Path + '/WinObjective', Integer(woDefeatAllOponents));
     2664    if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then
     2665      WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective);
    26562666  end;
    26572667end;
Note: See TracChangeset for help on using the changeset viewer.