public override void Load(XElement element, bool usePrefabValues, IdRemap idRemap) { base.Load(element, usePrefabValues, idRemap); List <Connection> loadedConnections = new List <Connection>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "input": loadedConnections.Add(new Connection(subElement, this, idRemap)); break; case "output": loadedConnections.Add(new Connection(subElement, this, idRemap)); break; } } for (int i = 0; i < loadedConnections.Count && i < Connections.Count; i++) { if (loadedConnections[i].wireId.Length == Connections[i].wireId.Length) { loadedConnections[i].wireId.CopyTo(Connections[i].wireId, 0); } else { //backwards compatibility when maximum number of wires has changed foreach (ushort id in loadedConnections[i].wireId) { for (int j = 0; j < Connections[i].wireId.Length; j++) { if (Connections[i].wireId[j] == 0) { Connections[i].wireId[j] = id; break; } } } } } disconnectedWireIds = element.GetAttributeUshortArray("disconnectedwires", new ushort[0]).ToList(); for (int i = 0; i < disconnectedWireIds.Count; i++) { disconnectedWireIds[i] = idRemap.GetOffsetId(disconnectedWireIds[i]); } }
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap) { base.Load(componentElement, usePrefabValues, idRemap); string containedString = componentElement.GetAttributeString("contained", ""); string[] itemIdStrings = containedString.Split(','); itemIds = new ushort[itemIdStrings.Length]; for (int i = 0; i < itemIdStrings.Length; i++) { if (!int.TryParse(itemIdStrings[i], out int id)) { continue; } itemIds[i] = idRemap.GetOffsetId(id); } }
public Connection(XElement element, ConnectionPanel connectionPanel, IdRemap idRemap) { #if CLIENT if (connector == null) { connector = GUI.Style.GetComponentStyle("ConnectionPanelConnector").GetDefaultSprite(); wireVertical = GUI.Style.GetComponentStyle("ConnectionPanelWire").GetDefaultSprite(); connectionSprite = GUI.Style.GetComponentStyle("ConnectionPanelConnection").GetDefaultSprite(); connectionSpriteHighlight = GUI.Style.GetComponentStyle("ConnectionPanelConnection").GetSprite(GUIComponent.ComponentState.Hover); screwSprites = GUI.Style.GetComponentStyle("ConnectionPanelScrew").Sprites[GUIComponent.ComponentState.None].Select(s => s.Sprite).ToList(); } #endif ConnectionPanel = connectionPanel; item = connectionPanel.Item; wires = new Wire[MaxLinked]; IsOutput = element.Name.ToString() == "output"; Name = element.GetAttributeString("name", IsOutput ? "output" : "input"); string displayNameTag = "", fallbackTag = ""; //if displayname is not present, attempt to find it from the prefab if (element.Attribute("displayname") == null) { foreach (XElement subElement in item.Prefab.ConfigElement.Elements()) { if (!subElement.Name.ToString().Equals("connectionpanel", StringComparison.OrdinalIgnoreCase)) { continue; } foreach (XElement connectionElement in subElement.Elements()) { string prefabConnectionName = element.GetAttributeString("name", null); if (prefabConnectionName == Name) { displayNameTag = connectionElement.GetAttributeString("displayname", ""); fallbackTag = connectionElement.GetAttributeString("fallbackdisplayname", ""); } } } } else { displayNameTag = element.GetAttributeString("displayname", ""); fallbackTag = element.GetAttributeString("fallbackdisplayname", null); } if (!string.IsNullOrEmpty(displayNameTag)) { //extract the tag parts in case the tags contains variables string tagWithoutVariables = displayNameTag?.Split('~')?.FirstOrDefault(); string fallbackTagWithoutVariables = fallbackTag?.Split('~')?.FirstOrDefault(); //use displayNameTag if found, otherwise fallBack if (TextManager.ContainsTag(tagWithoutVariables)) { DisplayName = TextManager.GetServerMessage(displayNameTag); } else if (TextManager.ContainsTag(fallbackTagWithoutVariables)) { DisplayName = TextManager.GetServerMessage(fallbackTag); } } if (string.IsNullOrEmpty(DisplayName)) { #if DEBUG DebugConsole.ThrowError("Missing display name in connection " + item.Name + ": " + Name); #endif DisplayName = Name; } IsPower = Name == "power_in" || Name == "power" || Name == "power_out"; Effects = new List <StatusEffect>(); wireId = new ushort[MaxLinked]; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "link": int index = -1; for (int i = 0; i < MaxLinked; i++) { if (wireId[i] < 1) { index = i; } } if (index == -1) { break; } int id = subElement.GetAttributeInt("w", 0); if (id < 0) { id = 0; } wireId[index] = idRemap.GetOffsetId(id); break; case "statuseffect": Effects.Add(StatusEffect.Load(subElement, item.Name + ", connection " + Name)); break; } } }