CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

HouseType.cs (2650B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // The Command & Conquer Map Editor and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // The Command & Conquer Map Editor and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 using System;
     16 using System.Collections.Generic;
     17 using System.Linq;
     18 using System.Text;
     19 using System.Threading.Tasks;
     20 
     21 namespace MobiusEditor.Model
     22 {
     23     public class HouseType
     24     {
     25         public sbyte ID { get; private set; }
     26 
     27         public string Name { get; private set; }
     28 
     29         public string UnitTeamColor { get; private set; }
     30 
     31         public string BuildingTeamColor { get; private set; }
     32 
     33         public IDictionary<string, string> OverrideTeamColors { get; private set; }
     34 
     35         public HouseType(sbyte id, string name, string unitTeamColor, string buildingTeamColor, params (string type, string teamColor)[] overrideTeamColors)
     36         {
     37             ID = id;
     38             Name = name;
     39             UnitTeamColor = unitTeamColor;
     40             BuildingTeamColor = buildingTeamColor;
     41             OverrideTeamColors = overrideTeamColors.ToDictionary(x => x.type, x => x.teamColor);
     42         }
     43 
     44         public HouseType(sbyte id, string name, string teamColor)
     45             : this(id, name, teamColor, teamColor)
     46         {
     47         }
     48 
     49         public HouseType(sbyte id, string name)
     50             : this(id, name, null)
     51         {
     52         }
     53 
     54         public override bool Equals(object obj)
     55         {
     56             if (obj is HouseType)
     57             {
     58                 return this == obj;
     59             }
     60             else if (obj is sbyte)
     61             {
     62                 return ID == (sbyte)obj;
     63             }
     64             else if (obj is string)
     65             {
     66                 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
     67             }
     68 
     69             return base.Equals(obj);
     70         }
     71 
     72         public override int GetHashCode()
     73         {
     74             return ID.GetHashCode();
     75         }
     76 
     77         public override string ToString()
     78         {
     79             return Name;
     80         }
     81     }
     82 }