void UpdatePower(MiniYamlNode power) { var range = 1; var rangeNode = power.LastChildMatching("Range"); if (rangeNode != null) { range = rangeNode.NodeValue <int>(); if (range > 3) { locations.Add("{0} ({1})".F(rangeNode.Key, rangeNode.Location.Filename)); } power.RemoveNode(rangeNode); } var size = 2 * range + 1; power.AddNode(new MiniYamlNode("Dimensions", size.ToString() + ", " + size.ToString())); var footprint = string.Empty; var emptycell = range; var affectedcell = 1; for (var i = 0; i < size; i++) { for (var e = 0; e < emptycell; e++) { footprint += '_'; } for (var a = 0; a < affectedcell; a++) { footprint += 'x'; } for (var e = 0; e < emptycell; e++) { footprint += '_'; } if (i < range) { emptycell--; affectedcell += 2; } else { emptycell++; affectedcell -= 2; } footprint += ' '; } power.AddNode(new MiniYamlNode("Footprint", footprint)); }
void ApplyChanges(MiniYamlNode actorNode, MiniYamlNode node) { // Type renamed to Types var type = node.LastChildMatching("Type"); if (type != null) type.RenameKey("Types"); // Allow(Allies|Neutral|Enemies) replaced with a ValidStances enum var stance = Stance.Neutral | Stance.Enemy; var allowAllies = node.LastChildMatching("AllowAllies"); if (allowAllies != null) { if (allowAllies.NodeValue<bool>()) stance |= Stance.Ally; else stance &= ~Stance.Ally; node.RemoveNode(allowAllies); } var allowNeutral = node.LastChildMatching("AllowNeutral"); if (allowNeutral != null) { if (allowNeutral.NodeValue<bool>()) stance |= Stance.Neutral; else stance &= ~Stance.Neutral; node.RemoveNode(allowNeutral); } var allowEnemies = node.LastChildMatching("AllowEnemies"); if (allowEnemies != null) { if (allowEnemies.NodeValue<bool>()) stance |= Stance.Enemy; else stance &= ~Stance.Enemy; node.RemoveNode(allowEnemies); } if (stance != (Stance.Neutral | Stance.Enemy)) node.AddNode("ValidStances", stance); }
public override IEnumerable <string> UpdateActorNode(ModData modData, MiniYamlNode actorNode) { var aircraft = actorNode.LastChildMatching("Aircraft"); var returnOnIdle = actorNode.LastChildMatching("ReturnOnIdle"); var flyAwayOnIdle = actorNode.LastChildMatching("FlyAwayOnIdle"); if (aircraft != null) { var landWhenIdle = false; var landWhenIdleNode = aircraft.LastChildMatching("LandWhenIdle"); if (landWhenIdleNode != null) { landWhenIdle = landWhenIdleNode.NodeValue <bool>(); aircraft.RemoveNode(landWhenIdleNode); } // FlyAwayOnIdle should have had higher priority than LandWhenIdle even if both were 'true'. // ReturnOnIdle has been broken for so long that it's safer to ignore it here and only inform // the modder of the places it's been removed from, so they can change the IdleBehavior manually if desired. if (flyAwayOnIdle != null && !flyAwayOnIdle.IsRemoval()) { aircraft.AddNode(new MiniYamlNode("IdleBehavior", "LeaveMap")); } else if (landWhenIdle) { aircraft.AddNode(new MiniYamlNode("IdleBehavior", "Land")); } } if (flyAwayOnIdle != null) { actorNode.RemoveNode(flyAwayOnIdle); } if (returnOnIdle != null) { returnOnIdles.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); actorNode.RemoveNode(returnOnIdle); } yield break; }
public override IEnumerable <string> UpdateActorNode(ModData modData, MiniYamlNode actorNode) { var rearmAnims = actorNode.ChildrenMatching("WithRearmAnimation"); var repairAnims = actorNode.ChildrenMatching("WithRepairAnimation"); var rearmAnimsTotal = rearmAnims.Count(); var repairAnimsTotal = repairAnims.Count(); if (rearmAnimsTotal == 0 && repairAnimsTotal == 0) { yield break; } else if (rearmAnimsTotal == 1 && repairAnimsTotal == 0) { foreach (var rearmAnim in rearmAnims) { rearmAnim.RenameKey("WithResupplyAnimation"); } } else if (rearmAnimsTotal == 0 && repairAnimsTotal == 1) { foreach (var repairAnim in repairAnims) { repairAnim.RenameKey("WithResupplyAnimation"); } } else if (rearmAnimsTotal == 1 && repairAnimsTotal == 1) { var rearmAnim = rearmAnims.First(); var repairAnim = repairAnims.First(); var rearmSequence = rearmAnim.LastChildMatching("Sequence"); var rearmBody = rearmAnim.LastChildMatching("Body"); var repairSequence = repairAnim.LastChildMatching("Sequence"); var repairBody = repairAnim.LastChildMatching("Body"); var matchingSequences = (rearmSequence == null && repairSequence == null) || (rearmSequence != null && repairSequence != null && rearmSequence.Value.Value == repairSequence.Value.Value); var matchingBodies = (rearmBody == null && repairBody == null) || (rearmBody != null && repairBody != null && rearmBody.Value.Value == repairBody.Value.Value); // If neither animation strays from the default values, we can safely merge them if (matchingSequences && matchingBodies) { rearmAnim.RenameKey("WithResupplyAnimation"); actorNode.RemoveNode(repairAnim); } else { rearmAnim.RenameKey("WithResupplyAnimation@Rearm", false, true); repairAnim.RenameKey("WithResupplyAnimation@Repair", false, true); } } else { // If we got here, we have more than one of at least one of the two animation traits. var rearmAnimCount = 0; foreach (var rearmAnim in rearmAnims) { ++rearmAnimCount; rearmAnim.RenameKey("WithResupplyAnimation@Rearm" + rearmAnimCount.ToString(), false, true); var playOnRearmNode = new MiniYamlNode("PlayAnimationOn", "Rearm"); rearmAnim.AddNode(playOnRearmNode); } var repairAnimCount = 0; foreach (var repairAnim in repairAnims) { ++repairAnimCount; repairAnim.RenameKey("WithResupplyAnimation@Repair" + repairAnimCount.ToString(), false, true); var playOnRepairNode = new MiniYamlNode("PlayAnimationOn", "Repair"); repairAnim.AddNode(playOnRepairNode); } } yield break; }
bool ExtractPanelDefinition(MiniYamlNode chromeProviderNode, MiniYamlNode regionsNode) { var cNode = regionsNode.LastChildMatching("background"); var hasCenter = cNode != null; var hasEdges = edgeKeys.Any(k => regionsNode.LastChildMatching(k) != null); // Not a panel if (!hasCenter && !hasEdges) { return(true); } // Panels may define just the background if (hasCenter && !hasEdges) { var bgRect = cNode.NodeValue <Rectangle>(); chromeProviderNode.AddNode("PanelRegion", new[] { bgRect.X, bgRect.Y, 0, 0, bgRect.Width, bgRect.Height, 0, 0 }); chromeProviderNode.AddNode("PanelSides", PanelSides.Center); regionsNode.RemoveNode(cNode); return(true); } // Panels may define just the edges, or edges plus background var tlNode = regionsNode.LastChildMatching("corner-tl"); if (tlNode == null) { return(false); } var tlRect = tlNode.NodeValue <Rectangle>(); var tNode = regionsNode.LastChildMatching("border-t"); if (tNode == null) { return(false); } var tRect = tNode.NodeValue <Rectangle>(); if (tRect.Left != tlRect.Right || tRect.Top != tlRect.Top || tRect.Bottom != tlRect.Bottom) { return(false); } var trNode = regionsNode.LastChildMatching("corner-tr"); if (trNode == null) { return(false); } var trRect = trNode.NodeValue <Rectangle>(); if (trRect.Left != tRect.Right || trRect.Top != tRect.Top || trRect.Bottom != tRect.Bottom) { return(false); } var lNode = regionsNode.LastChildMatching("border-l"); if (lNode == null) { return(false); } var lRect = lNode.NodeValue <Rectangle>(); if (lRect.Left != tlRect.Left || lRect.Top != tlRect.Bottom || lRect.Right != tlRect.Right) { return(false); } var rNode = regionsNode.LastChildMatching("border-r"); if (rNode == null) { return(false); } var rRect = rNode.NodeValue <Rectangle>(); if (rRect.Left != trRect.Left || rRect.Top != trRect.Bottom || rRect.Bottom != lRect.Bottom || rRect.Right != trRect.Right) { return(false); } var blNode = regionsNode.LastChildMatching("corner-bl"); if (blNode == null) { return(false); } var blRect = blNode.NodeValue <Rectangle>(); if (blRect.Left != lRect.Left || blRect.Top != lRect.Bottom || blRect.Right != lRect.Right) { return(false); } var bNode = regionsNode.LastChildMatching("border-b"); if (bNode == null) { return(false); } var bRect = bNode.NodeValue <Rectangle>(); if (bRect.Left != blRect.Right || bRect.Top != blRect.Top || bRect.Bottom != blRect.Bottom || bRect.Right != tRect.Right) { return(false); } var brNode = regionsNode.LastChildMatching("corner-br"); if (brNode == null) { return(false); } var brRect = brNode.NodeValue <Rectangle>(); if (brRect.Left != bRect.Right || brRect.Top != bRect.Top || brRect.Bottom != bRect.Bottom || brRect.Right != rRect.Right) { return(false); } // Background definition may be omitted if (hasCenter) { var bgRect = cNode.NodeValue <Rectangle>(); if (bgRect.Left != lRect.Right || bgRect.Top != lRect.Top || bgRect.Bottom != lRect.Bottom || bgRect.Right != tRect.Right) { return(false); } } // Define the short-form panel region chromeProviderNode.AddNode("PanelRegion", new[] { tlRect.X, tlRect.Y, tlRect.Width, tlRect.Height, trRect.Left - tlRect.Right, blRect.Top - tlRect.Bottom, brRect.Width, brRect.Height }); if (!hasCenter) { chromeProviderNode.AddNode("PanelSides", PanelSides.Edges); } // Remove the now redundant regions regionsNode.RemoveNode(tlNode); regionsNode.RemoveNode(tNode); regionsNode.RemoveNode(trNode); regionsNode.RemoveNode(lNode); regionsNode.RemoveNode(rNode); regionsNode.RemoveNode(blNode); regionsNode.RemoveNode(bNode); regionsNode.RemoveNode(brNode); if (cNode != null) { regionsNode.RemoveNode(cNode); } return(true); }