mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Added generic DefModExtension for Distance and Ticks
This commit is contained in:
		
							parent
							
								
									d21a665a3c
								
							
						
					
					
						commit
						ef1e3cdd0f
					
				
					 3 changed files with 86 additions and 0 deletions
				
			
		
							
								
								
									
										20
									
								
								Source/Common/Defs/DistanceExtension.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Source/Common/Defs/DistanceExtension.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,20 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using Verse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace RJW_Genes
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Small Extension that covers distances for Genes.
 | 
				
			||||||
 | 
					    /// This allows to set distance in the XMLs. 
 | 
				
			||||||
 | 
					    /// The distance is measured in tiles, so a distance of ~25 means 25 tiles away from the pawn in any direction. 
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    public class DistanceExtension : DefModExtension
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public int Distance;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								Source/Common/Defs/ModExtensionHelper.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								Source/Common/Defs/ModExtensionHelper.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,48 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using Verse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace RJW_Genes
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    internal class ModExtensionHelper
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static int GetDistanceFromModExtension(GeneDef defOf, int fallback)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            DistanceExtension distanceExt = defOf.GetModExtension<DistanceExtension>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            int potentialDistance = distanceExt?.Distance ?? fallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (potentialDistance > 0)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return potentialDistance;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                ModLog.Warning($"Retrieved a bad distance ({potentialDistance}) reading the RJW_Genes.DistanceExtension for {defOf.defName}");    
 | 
				
			||||||
 | 
					                return 1; 
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static int GetTickIntervalFromModExtension(GeneDef defOf, int fallback)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            TickIntervalExtension tickExt = defOf.GetModExtension<TickIntervalExtension>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            int potentialTickInterval = tickExt?.tickInterval ?? fallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (potentialTickInterval > 0)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return potentialTickInterval;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ModLog.Warning($"Retrieved a bad distance ({potentialTickInterval}) reading the RJW_Genes.DistanceExtension for {defOf.defName}");
 | 
				
			||||||
 | 
					                return 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								Source/Common/Defs/TickIntervalExtension.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Source/Common/Defs/TickIntervalExtension.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using Verse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace RJW_Genes
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// General DefModExtension to cover various genes that need to tick regularly.
 | 
				
			||||||
 | 
					    /// Defining it like this allows to adjust things in XML. 
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    public class TickIntervalExtension : DefModExtension
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public int tickInterval;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue