Skip to content

Commit

Permalink
Patch to fix delay
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesenibbles123 committed Mar 31, 2021
1 parent fefd367 commit 428a58c
Showing 1 changed file with 83 additions and 37 deletions.
120 changes: 83 additions & 37 deletions FlagReplacement/Mainmod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class Mainmod : MonoBehaviour

static Dictionary<string, Texture2D> flags = new Dictionary<string, Texture2D>();

static Dictionary<int, bool> ships = new Dictionary<int, bool>();

static bool hasNotSetNavy = true;
static bool hasNotSetPirate = true;
static Texture navyFlag;
static Texture pirateFlag;

public static Mainmod Instance;

void Awake()
Expand Down Expand Up @@ -50,6 +57,11 @@ void initFiles()
streamWriter.Close();
}

if (!File.Exists(Application.dataPath + texturesFilePath))
{
Directory.CreateDirectory(Application.dataPath + texturesFilePath);
}

initFlags();
}

Expand Down Expand Up @@ -108,62 +120,96 @@ static void Postfix(ShipConstruction __instance, string shipType, int team, ïç
}
}

private IEnumerator doStuff(int team)
static void resetFlag(Renderer renderer, bool isNavy)
{
Transform shipTransform = GameMode.Instance.teamParents[team];
Renderer[] renderers = shipTransform.GetComponentsInChildren<Renderer>(true);

Thread childThread = new Thread(() => threadedFlags(renderers, team));
childThread.Start();
yield return null;
if (isNavy)
{
renderer.material.mainTexture = navyFlag;
}
else
{
renderer.material.mainTexture = pirateFlag;
}
}

static void threadedFlags(Renderer[] renderers, int teamNum)
static void loopOver(Renderer[] renderers, Texture flag, int team)
{
try
foreach (Renderer renderer in renderers)
{
float startTime = Time.time;
while (1 != 2)
try
{
if (startTime <= Time.time - 2)
if (renderer.name == "teamflag")
{
if (GameMode.Instance.teamCaptains[teamNum].steamID != 0)
debugLog($"Faction flag: -{renderer.material.mainTexture.name}-");

if (ships.TryGetValue(team, out bool isNavy))
{
if (flag != null && flag.name != "NOFLAG")
{
renderer.material.mainTexture = flag;
}
else
{
resetFlag(renderer, isNavy);
}
}
else
{
string steamID = GameMode.Instance.teamCaptains[teamNum].steamID.ToString();
if (flags.TryGetValue(steamID, out Texture2D flag))
if (renderer.material.mainTexture.name == "flag_navy")
{
foreach (Renderer renderer in renderers)
ships.Add(team, true);
if (hasNotSetNavy)
{
try
{
if (renderer.name == "teamflag")
{
debugLog($"Faction flag: -{renderer.material.mainTexture.name}-");
if (flag.name != "NOFLAG")
{
renderer.material.mainTexture = flag;
}
}
}
catch (Exception e)
{
// Just ignore
}
navyFlag = renderer.material.mainTexture;
hasNotSetNavy = false;
}
break;
}
else
{
break;
ships.Add(team, false);
if (hasNotSetPirate)
{
pirateFlag = renderer.material.mainTexture;
hasNotSetPirate = false;
}
}

if (flag != null && flag.name != "NOFLAG")
{
renderer.material.mainTexture = flag;
}
else
{
resetFlag(renderer, isNavy);
}
}

}
}
}catch (Exception e)
catch (Exception e)
{
// Just ignore
}
}
}

private IEnumerator doStuff(int team)
{
yield return new WaitForSeconds(4f);

if (GameMode.Instance.teamCaptains[team].steamID != 0)
{
debugLog("ERROR");
debugLog(e.Message);
debugLog("ERROR");
Transform shipTransform = GameMode.Instance.teamParents[team];
Renderer[] renderers = shipTransform.GetComponentsInChildren<Renderer>(true);
string steamID = GameMode.Instance.teamCaptains[team].steamID.ToString();
if (flags.TryGetValue(steamID, out Texture2D flag))
{
loopOver(renderers, flag, team);
}
else
{
loopOver(renderers, null, team);
}
}
}
}
Expand Down

0 comments on commit 428a58c

Please sign in to comment.