public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap) { base.Load(componentElement, usePrefabValues, idRemap); string nodeString = componentElement.GetAttributeString("nodes", ""); if (nodeString == "") { return; } string[] nodeCoords = nodeString.Split(';'); for (int i = 0; i < nodeCoords.Length / 2; i++) { float.TryParse(nodeCoords[i * 2], NumberStyles.Float, CultureInfo.InvariantCulture, out float x); float.TryParse(nodeCoords[i * 2 + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out float y); nodes.Add(new Vector2(x, y)); } Drawable = nodes.Any(); }
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 List <ushort> [itemIdStrings.Length]; for (int i = 0; i < itemIdStrings.Length; i++) { itemIds[i] ??= new List <ushort>(); foreach (string idStr in itemIdStrings[i].Split(';')) { if (!int.TryParse(idStr, out int id)) { continue; } itemIds[i].Add(idRemap.GetOffsetId(id)); } } }
public virtual void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap) { if (componentElement != null) { foreach (XAttribute attribute in componentElement.Attributes()) { if (!SerializableProperties.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out SerializableProperty property)) { continue; } if (property.OverridePrefabValues || !usePrefabValues) { property.TrySetValue(this, attribute.Value); } } ParseMsg(); OverrideRequiredItems(componentElement); } if (item.Submarine != null) { SerializableProperty.UpgradeGameVersion(this, originalElement, item.Submarine.Info.GameVersion); } }
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; } } }
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap) { base.Load(componentElement, usePrefabValues, idRemap); loadedVariant = componentElement.GetAttributeInt("variant", -1); }
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap) { base.Load(componentElement, usePrefabValues, idRemap); loadedRotationLimits = componentElement.GetAttributeVector2("rotationlimits", RotationLimits); loadedBaseRotation = componentElement.GetAttributeFloat("baserotation", componentElement.Parent.GetAttributeFloat("rotation", BaseRotation)); }