CnC_Remastered_Collection

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

Terrain.cs (2530B)


      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.ComponentModel;
     18 using System.Drawing;
     19 using System.Runtime.CompilerServices;
     20 using MobiusEditor.Interface;
     21 
     22 namespace MobiusEditor.Model
     23 {
     24     public class Terrain : ICellOverlapper, ICellOccupier, INotifyPropertyChanged, ICloneable
     25     {
     26         public event PropertyChangedEventHandler PropertyChanged;
     27 
     28         private TerrainType type;
     29         public TerrainType Type { get => type; set => SetField(ref type, value); }
     30 
     31         private int icon;
     32         public int Icon { get => icon; set => SetField(ref icon, value); }
     33 
     34         public Rectangle OverlapBounds => Type.OverlapBounds;
     35 
     36         public bool[,] OccupyMask => Type.OccupyMask;
     37 
     38         private string trigger = Model.Trigger.None;
     39         public string Trigger { get => trigger; set => SetField(ref trigger, value); }
     40 
     41         public Color Tint { get; set; } = Color.White;
     42 
     43         public Terrain Clone()
     44         {
     45             return new Terrain()
     46             {
     47                 Type = Type,
     48                 Icon = Icon,
     49                 Trigger = Trigger
     50             };
     51         }
     52 
     53         protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
     54         {
     55             if (EqualityComparer<T>.Default.Equals(field, value))
     56             {
     57                 return false;
     58             }
     59             field = value;
     60             OnPropertyChanged(propertyName);
     61             return true;
     62         }
     63 
     64         protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     65 
     66         object ICloneable.Clone()
     67         {
     68             return Clone();
     69         }
     70     }
     71 }