public void ProfileChanged(string sThisProfile)
{
//fresh profile?
if (Profiles.Count == 0)
{
//Lets create a new profile
Profiles.Add(new TrackedProfile(sThisProfile));
//Reference it to the Collection
currentprofile = Profiles[Profiles.Count - 1];
}
//Did we really change profiles?
if (Profiles.Count > 0 && currentprofile.ProfileName != sThisProfile)
{
//Refresh Profile Target Blacklist
FunkyGame.Profile.UpdateProfileBlacklist();
//Set the "end" date for current profile
currentprofile.UpdateRangeVariables();
bool foundPreviousEntry = false;
foreach (TrackedProfile item in Profiles)
{
//Found the profile so lets use that instead!
if (item.ProfileName == sThisProfile)
{
foundPreviousEntry = true;
item.RestartRangeVariables();//reset Starting variables
//Reference it to the Collection
currentprofile = item;
break;
}
}
//Profile was not found.. so lets add it and set it as current.
if (!foundPreviousEntry)
{
//Lets create a new profile
Profiles.Add(new TrackedProfile(sThisProfile));
//Reference it to the Collection
currentprofile = Profiles[Profiles.Count - 1];
}
else
{//Reorder the profiles!
int previousProfileIndex = Profiles.IndexOf(currentprofile);
//Copy profiles
TrackedProfile[] clone_profiles = new TrackedProfile[Profiles.Count];
Profiles.CopyTo(clone_profiles, 0);
//Reorder..
for (int i = previousProfileIndex; i < Profiles.Count - 1; i++)
{
Profiles[i] = clone_profiles[i + 1];
}
//Finally Set the last profile to current!
Profiles[Profiles.Count - 1] = currentprofile;
}
WriteProfileTrackerOutput(ref FunkyGame.CurrentStats);
}
}