Skip to content

Commit

Permalink
Version 1.29
Browse files Browse the repository at this point in the history
-Overhaul External mod support
-No changes visible in AGX itself
  • Loading branch information
SirDiazo committed Jan 4, 2015
1 parent 8c70809 commit 47bb438
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 27 deletions.
111 changes: 111 additions & 0 deletions AGExt/CommonMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void ActivateActionGroup(int group, bool force, bool forceDir) //main act
//print("AGX action deactivate FIRE! " + agAct.ba.guiName);
ErrLine = "8";
agAct.ba.Invoke(actParam);
agAct.activated = false;
ErrLine = "9";
if (group <= 10)
{
Expand All @@ -193,6 +194,7 @@ public void ActivateActionGroup(int group, bool force, bool forceDir) //main act
//print("AGX action activate FIRE!" + agAct.ba.guiName);
ErrLine = "13";
agAct.ba.Invoke(actParam);
agAct.activated = true;
ErrLine = "14";
if (group <= 10)
{
Expand All @@ -201,6 +203,12 @@ public void ActivateActionGroup(int group, bool force, bool forceDir) //main act
}
ErrLine = "16";
}

foreach(AGXAction agActCheck in actionsList.Where(ag => ag.ba == agAct.ba))
{
agActCheck.activated = agAct.activated;
}

if (agAct.ba.listParent.module.moduleName == "ModuleEngines" && agAct.ba.name == "ActivateAction" || agAct.ba.listParent.module.moduleName == "ModuleEngines" && agAct.ba.name == "OnAction")
{
ErrLine = "17";
Expand All @@ -222,6 +230,7 @@ public void ActivateActionGroup(int group, bool force, bool forceDir) //main act
}
ErrLine = "22";
}
SaveThisVessel();
}
catch(Exception e)
{
Expand All @@ -230,6 +239,108 @@ public void ActivateActionGroup(int group, bool force, bool forceDir) //main act
}

}

public bool StateCheckGroup(int group)
{
if (vesselInstanceOK)
{
actionsList = AGXFlight.CheckActionsActiveActualCode(actionsList);
bool groupState = true;
if (actionsList.Where(ag => ag.group == group).Count() >= 1)
{
foreach (AGXAction agAct in actionsList.Where(ag => ag.group == group))
{
if (!agAct.activated)
{
groupState = false;
}
}
}
else
{
groupState = false;
}
return groupState;
}
else
{
Debug.Log("AGX Group State FALSE due to vessel not loaded.");
return false;
}
}

public void SaveThisVessel()
{
string errLine = "1";
try
{
ConfigNode thisVslNode = new ConfigNode(flightID.ToString());
errLine = "2";
if (AGXFlight.AGXFlightNode.HasNode(flightID.ToString()))
{
errLine = "3";
thisVslNode = AGXFlight.AGXFlightNode.GetNode(thisVsl.rootPart.flightID.ToString());
errLine = "4";
AGXFlight.AGXFlightNode.RemoveNode(thisVsl.rootPart.flightID.ToString());
}
errLine = "5";
thisVslNode.RemoveNodes("PART");
errLine = "6";
foreach (Part p in thisVsl.Parts)
{
errLine = "7";
List<AGXAction> thisPartsActions = new List<AGXAction>();
errLine = "8";
thisPartsActions.AddRange(actionsList.FindAll(p2 => p2.ba.listParent.part == p));
errLine = "18";
if (thisPartsActions.Count > 0)
{
//print("acts count " + thisPartsActions.Count);
ConfigNode partTemp = new ConfigNode("PART");
errLine = "19";
partTemp.AddValue("name", p.partInfo.name);
partTemp.AddValue("vesselName", p.vessel.vesselName);
//partTemp.AddValue("relLocX", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).x);
//partTemp.AddValue("relLocY", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).y);
//partTemp.AddValue("relLocZ", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).z);
partTemp.AddValue("flightID", p.flightID.ToString());
errLine = "20";
foreach (AGXAction agxAct in thisPartsActions)
{
//print("acts countb " + thisPartsActions.Count);
errLine = "21";
partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
}
errLine = "22";

thisVslNode.AddNode(partTemp);
errLine = "23";
}
errLine = "24";
}
errLine = "25";
if (AGXFlight.AGXFlightNode.HasNode(thisVsl.id.ToString()))
{
errLine = "26";
AGXFlight.AGXFlightNode.RemoveNode(thisVsl.id.ToString());
}
errLine = "27";
if (AGXFlight.AGXFlightNode.HasNode(thisVsl.rootPart.flightID.ToString()))
{
errLine = "28";
AGXFlight.AGXFlightNode.RemoveNode(thisVsl.rootPart.flightID.ToString());
}
errLine = "29";
//print("save node " + thisVsl);
AGXFlight.AGXFlightNode.AddNode(thisVslNode);
}
catch(Exception e)
{
Debug.Log("AGX OtherVslSaveNode Fail " + errLine + " " + e);
}

}

}


Expand Down
64 changes: 45 additions & 19 deletions AGExt/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public void Start()
}
GameEvents.onPartAttach.Add(PartAttaching);// this game event only fires for part removed, not child parts
GameEvents.onPartRemove.Add(PartRemove);
GameEvents.onEditorShipModified.Add(VesselChanged);
CurrentVesselActions.Clear();
EditorLoadFromFile();
EditorLoadFromNode();
Expand Down Expand Up @@ -694,6 +695,7 @@ public void PartAttaching(GameEvents.HostTargetAction<Part,Part> host_target)
AttachAGXPart(p);
}
DetachedPartReset.Start();
//RefreshDefaultActionsList();

}
catch(Exception e)
Expand Down Expand Up @@ -955,7 +957,13 @@ public static void ResetDetachedParts(object source, ElapsedEventArgs e)
}
DetachedPartActions.Clear();
EditorSaveToNode();

}

public void VesselChanged(ShipConstruct sc)
{
print("vessel change fire");
RefreshDefaultActionsList();
}

public static void AttachAGXPart(Part p)
Expand Down Expand Up @@ -1043,6 +1051,7 @@ public void OnDisable()
//EditorSaveToFile(); //some of my data has already been deleted by this point
GameEvents.onPartAttach.Remove(PartAttaching);
GameEvents.onPartRemove.Remove(PartRemove);
GameEvents.onEditorShipModified.Remove(VesselChanged);
//GameEvents.onGameSceneLoadRequested.Remove(LeavingEditor);


Expand Down Expand Up @@ -2221,7 +2230,7 @@ public void SelParts(int WindowID)
if (ba.name == baname)
{
ba.actionGroup = ba.actionGroup | defaultGroupToShow;
//Debug.Log("adding act");
Debug.Log("adding act");

}
}
Expand Down Expand Up @@ -2504,6 +2513,21 @@ public void SelParts(int WindowID)
// }
//}

public void RefreshDefaultActionsList()
{
defaultActionsListAll.Clear();

foreach (Part p in EditorLogic.SortedShipList)
{
defaultActionsListAll.AddRange(p.Actions);
foreach (PartModule pm in p.Modules)
{
defaultActionsListAll.AddRange(pm.Actions);
}
}

}

public void RefreshDefaultActionsListType()
{
defaultActionsListThisType.Clear();
Expand Down Expand Up @@ -2576,25 +2600,27 @@ public void GroupsWindow(int WindowID)
if (defaultShowingNonNumeric)
{
ErrLine = "4c";
defaultActionsListAll.Clear();
ErrLine = "4d";
{
ErrLine = "4e";
foreach (Part p in EditorLogic.SortedShipList)
{
ErrLine = "4f";
defaultActionsListAll.AddRange(p.Actions);
ErrLine = "4g";
foreach (PartModule pm in p.Modules)
{
ErrLine = "4h";
defaultActionsListAll.AddRange(pm.Actions);
//defaultActionsListAll.Clear();
//ErrLine = "4d";
//{
// ErrLine = "4e";
// foreach (Part p in EditorLogic.SortedShipList)
// {
// ErrLine = "4f";
// defaultActionsListAll.AddRange(p.Actions);
// ErrLine = "4g";
// foreach (PartModule pm in p.Modules)
// {
// ErrLine = "4h";
// defaultActionsListAll.AddRange(pm.Actions);

}
ErrLine = "4i";
}
ErrLine = "4j";
}
// }
// ErrLine = "4i";
// }
// ErrLine = "4j";
//}

RefreshDefaultActionsList();
ErrLine = "4k";
RefreshDefaultActionsListType();
ErrLine = "4l";
Expand Down
6 changes: 3 additions & 3 deletions AGExt/External.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public static bool AGX2VslGroupState(uint FlightID, int group) //8 on test, owrk
}
else
{
ScreenMessages.PostScreenMessage("AGX Action Fail, other vessels not implemented yet", 10F, ScreenMessageStyle.UPPER_CENTER);
return false;
AGXOtherVessel otherVsl = new AGXOtherVessel(FlightID);
return otherVsl.StateCheckGroup(group);
}
}
else
{
ScreenMessages.PostScreenMessage("AGX Action Not Activated, not in flight", 10F, ScreenMessageStyle.UPPER_CENTER);
ScreenMessages.PostScreenMessage("AGX Action not checked, not in flight", 10F, ScreenMessageStyle.UPPER_CENTER);
return false;
}
}
Expand Down
14 changes: 10 additions & 4 deletions AGExt/Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ public static void ActivateActionGroup(int group, bool force, bool forceDir)

foreach (AGXAction agAct in CurrentVesselActions.Where(agx => agx.group == group))
{
print("ActactA");
//print("ActactA");
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
Expand Down Expand Up @@ -5437,14 +5437,20 @@ public void AGXResetPartsList()
}
}

public void CheckActionsActive() //monitor actions state, have to add them manually
public static void CheckActionsActive()
{
CurrentVesselActions = CheckActionsActiveActualCode(CurrentVesselActions);
CalculateActionsState();
}

public static List<AGXAction> CheckActionsActiveActualCode(List<AGXAction> actsListToCheck) //monitor actions state, have to add them manually
{




//start toggle checking
foreach (AGXAction agAct in CurrentVesselActions)
foreach (AGXAction agAct in actsListToCheck)
{
if (agAct.ba.listParent.module.moduleName == "ModuleDeployableSolarPanel") //only one state on part
{
Expand Down Expand Up @@ -6388,8 +6394,8 @@ public void CheckActionsActive() //monitor actions state, have to add them manua
// agAct.activated = agAct.ba.listParent.module.isEnabled;
//}
}
return actsListToCheck;

CalculateActionsState();
}
}

Expand Down
2 changes: 1 addition & 1 deletion AGExt/Instantly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AGXMainMenu :PartModule
//abandoned module, no longer needed for key rebinding
public void Start()
{
print("AGExt Ver. 1.28b loaded");
print("AGExt Ver. 1.29 loaded");
}

}
Expand Down

0 comments on commit 47bb438

Please sign in to comment.