Skip to content

Commit

Permalink
Version 1.24
Browse files Browse the repository at this point in the history
-Fix double keypress issues
-Move state checking timer to fixedupdate
  • Loading branch information
SirDiazo committed Nov 29, 2014
1 parent aaa3738 commit 73865c8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
13 changes: 13 additions & 0 deletions AGExt/External.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ public static bool AGXGroupState(int i) //is a group activated?
public BaseAction ba;
public KSPActionGroup agrp;
}
public class AGXCooldown : MonoBehaviour
{
public uint vslFlightID;
public int actGroup;
public int delayLeft;

public AGXCooldown(uint ID, int grp, int delay)
{
vslFlightID = ID;
actGroup = grp;
delayLeft = delay;
}
}



Expand Down
68 changes: 54 additions & 14 deletions AGExt/Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace ActionGroupsExtended
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class AGXFlight : PartModule
{
private static int activationCoolDown = 5;
private static List<AGXCooldown> groupCooldowns;
private List<Part> oldShipParts;
//Selected Parts Window Variables
private bool AGXLockSet = false; //is inputlock set?
Expand Down Expand Up @@ -267,6 +269,16 @@ public void Start()
//print("Catch");
}

groupCooldowns = new List<AGXCooldown>(); //setup values for group cooldowns logic
try
{
activationCoolDown = Convert.ToInt32(AGExtNode.GetValue("ActivationCooldown"));
}
catch
{
print("AGX Default cooldown not found, using 5 Update frames");
}

if (ToolbarManager.ToolbarAvailable) //check if toolbar available, load if it is
{

Expand Down Expand Up @@ -1212,9 +1224,11 @@ public void AGXOnDraw()

public static void ActivateActionGroupCheckModKeys(int group) //backwards compatibility, toggle group
{

print("AGX Key check for some reason " + group);
if (AGXguiMod1Groups[group] == Input.GetKey(AGXguiMod1Key) && AGXguiMod2Groups[group] == Input.GetKey(AGXguiMod2Key))
{
//print("Key act for some reason " + group);
print("AGX Key activate for some reason " + group);
ActivateActionGroup(group, false, false);
}
}
Expand All @@ -1241,7 +1255,13 @@ public static void ActivateActionGroup(int group, bool force, bool forceDir)

foreach (AGXAction agAct in CurrentVesselActions.Where(agx => agx.group == group))
{

if(groupCooldowns.Any(cd => cd.actGroup == agAct.group && cd.vslFlightID == agAct.ba.listParent.part.vessel.rootPart.flightID)) //rather then fight with double negative bools, do noting if both match, run if no match
{
//if this triggers, that action/group combo is in cooldown
print("AGX Action not activated, that group still in cooldown");
}
else //action not in cooldown
{
if (force) //are we forcing a direction or toggling?
{
if (forceDir) //we are forcing a direction so set the agAct.activated to trigger the direction below correctly
Expand All @@ -1253,7 +1273,7 @@ public static void ActivateActionGroup(int group, bool force, bool forceDir)
if (agAct.activated)
{
KSPActionParam actParam = new KSPActionParam(KSPActionGroup.None, KSPActionType.Deactivate);

print("AGX action deactivate FIRE! " + agAct.ba.guiName);
agAct.ba.Invoke(actParam);
foreach (AGXAction agxAct in CurrentVesselActions)
{
Expand All @@ -1272,6 +1292,7 @@ public static void ActivateActionGroup(int group, bool force, bool forceDir)
{
KSPActionParam actParam = new KSPActionParam(KSPActionGroup.None, KSPActionType.Activate);
//agAct.activated = true;
print("AGX action activate FIRE!" + agAct.ba.guiName);
agAct.ba.Invoke(actParam);
foreach (AGXAction agxAct in CurrentVesselActions)
{
Expand All @@ -1285,13 +1306,16 @@ public static void ActivateActionGroup(int group, bool force, bool forceDir)
FlightGlobals.ActiveVessel.ActionGroups[CustomActions[group]] = true;
}


}

}
//ModuleAGExtData pmAgx = agAct.ba.listParent.part.Modules.OfType<ModuleAGExtData>().First<ModuleAGExtData>();
//pmAgx.partAGActions.Clear();
//pmAgx.partAGActions.AddRange(CurrentVesselActions.Where(agp => agp.prt == agAct.ba.listParent.part));
//pmAgx.AGXData = pmAgx.SaveActionGroups();

}
groupCooldowns.Add(new AGXCooldown(FlightGlobals.ActiveVessel.rootPart.flightID, group, 0));
CalculateActionsState();
}

Expand Down Expand Up @@ -3700,6 +3724,7 @@ public void DockingEvent()

public void Update()
{
//print("alpha 1 " + Input.GetKeyDown(KeyCode.Alpha1));
//print("AGXLock state " + AGXLockSet);
string errLine = "1";
try
Expand Down Expand Up @@ -4217,16 +4242,17 @@ public void Update()
// }
// }
//}
if (actionsCheckFrameCount >= 20)
if (actionsCheckFrameCount >= 15) //this increments in the FixedUpdate frame now
{
CheckActionsActive();
//PartVesselChangeCheck();
actionsCheckFrameCount = 0;
}
else
{
actionsCheckFrameCount = actionsCheckFrameCount + 1;
}
//else
//{
// actionsCheckFrameCount = actionsCheckFrameCount + (int)(Time.deltaTime * 1000f);
//}
//print("delta time " + actionsCheckFrameCount);
errLine = "37";
//print("vessel " + FlightGlobals.ActiveVessel.id.ToString());
//print("uid " + FlightGlobals.ActiveVssel.rootPart.uid.ToString());
Expand All @@ -4250,6 +4276,14 @@ public void Update()

//}
//PrintPartPos();

//count down action cool downs
groupCooldowns.RemoveAll(cd => cd.delayLeft > activationCoolDown); //remove actions from list that are finished cooldown, cooldown is in Update frame passes, pulled from .cfg
foreach(AGXCooldown agCD in groupCooldowns)
{
agCD.delayLeft = agCD.delayLeft + 1;

}
//PrintPartActs();

}
Expand All @@ -4258,18 +4292,19 @@ public void Update()
print("AGX Update error: " + errLine + " " + e);
}
}
public void FixedUpdate()
{
actionsCheckFrameCount = actionsCheckFrameCount + 1; //this affects actions on vessel, limit how often we check toggle states
}

public void PrintPartActs()
{
try
{
//print("crew " + FlightGlobals.ActiveVessel.GetVesselCrew().Count);
foreach (Part p in FlightGlobals.ActiveVessel.parts)
foreach (AGXCooldown agCD in groupCooldowns)
{
foreach (ModuleEngines eng in p.Modules.OfType<ModuleEngines>())
{
print("state " + eng.isOperational + eng.getIgnitionState);
}
print("action " + agCD.vslFlightID + " " + agCD.actGroup + " " + agCD.delayLeft);
}


Expand Down Expand Up @@ -5138,6 +5173,11 @@ public void AGXResetPartsList()

public void CheckActionsActive() //monitor actions state, have to add them manually
{




//start toggle checking
foreach (AGXAction agAct in CurrentVesselActions)
{
if (agAct.ba.listParent.module.moduleName == "ModuleDeployableSolarPanel") //only one state on part
Expand Down
2 changes: 1 addition & 1 deletion AGExt/Instantly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AGXMainMenu :PartModule

public void Start()
{
print("AGExt Ver. 1.23a loaded");
print("AGExt Ver. 1.24 loaded");
//below no longer needed with InputLockManager
//AGXguiKeys = new Dictionary<int, KeyCode>();
//AGExtNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.cfg");
Expand Down

0 comments on commit 73865c8

Please sign in to comment.