First off, sorry if this has been asked already, but I've been googling around and haven't found any solutions. I'm thinking maybe I just don't know how to word the question correctly.
public class WeatherEngine : ParticleEngine
{
public enum WeatherType
{
None,
Rain,
Snow
}
public WeatherEngine(List<Texture2D> weatherTextures, WeatherType weatherType) : base(weatherTextures, null)
{}
I'm currently attempting to derive my weather class from my particle engine, but I'm having difficulty figuring out whether there's a way to modify some of the data before passing it into the base class constructor.
Ideally, I'd like to be able to pass a full list of possible weather textures for each weather type, and then separate that list into another list List<Texture2D> currentWeatherTextures
to pass into the base constructor.
AFAIK, my only other option is to separate the list before calling the constructor of WeatherEngine, but in the spirit of keeping my main class mostly clear of logic and instead just using it to initialize everything, I was hoping that there's an alternative solution.
Or should I just not derive WeatherEngine from ParticleEngine at all, and keep the two separate?
You can just make a private static method in the derived class that modifies the data and returns the value to pass to the base class' constructor:
using System;
namespace ConsoleApp2
{
public class Base
{
public Base(string param)
{
Console.WriteLine("Param: " + param);
}
}
public class Derived : Base
{
public Derived(string param) : base(Modify(param))
{
}
static string Modify(string s)
{
return "Modified: " + s;
}
}
class Program
{
static void Main()
{
Derived d = new Derived("Test");
}
}
}