public CapacitorUI(Item[] slot, CapacitorEntity capacitorEntity) { chargingSlot = new ChargingSlot[4]; for (int i = 0; i < chargingSlot.Length; i++) { chargingSlot[i] = new ChargingSlot(new Ref <Item>(slot, i), TUA.instance.GetTexture("API/TerraEnergy/Texture/ChargingSlotUI"), capacitorEntity, capacitorEntity.maxTransferRate); } this.capacitorEntity = capacitorEntity; }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; Item currentSelectedItem = player.inventory[player.selectedItem]; Tile tile = Main.tile[i, j]; int left = i - (tile.frameX / 18); int top = j - (tile.frameY / 18); Main.NewText("X " + i + " Y " + j); int index = mod.GetTileEntity <CapacitorEntity>().Find(left, top); if (index == -1) { Main.NewText("false"); return; } if (currentSelectedItem.type == mod.ItemType("TerraMeter")) { StorageEntity se = (StorageEntity)TileEntity.ByID[index]; Main.NewText(se.getEnergy().getCurrentEnergyLevel() + " / " + se.getEnergy().getMaxEnergyLevel() + " TE in this Capacitor"); } if (currentSelectedItem.type == mod.ItemType("RodOfLinking")) { RodOfLinking it = currentSelectedItem.modItem as RodOfLinking; StorageEntity se = it.getEntity(); if (se == null) { Main.NewText("The rod of linking is vound to nothing"); return; } CapacitorEntity ce = (CapacitorEntity)TileEntity.ByID[index]; if (se.type == mod.TileEntityType("EnergyCollectorEntity")) { EnergyCollectorEntity ece = se as EnergyCollectorEntity; ece.linkToCapacitor(ce); } else if (se.type == mod.TileEntityType("TerraFurnaceEntity")) { TerraFurnaceEntity tfe = se as TerraFurnaceEntity; tfe.linkToCapacitor(ce); } Main.NewText("Succesfully linked to a capacitor, now transferring energy to it", Color.ForestGreen); } }
public override void NewRightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; Item currentSelectedItem = player.inventory[player.selectedItem]; Tile tile = Main.tile[i, j]; int left = i - (tile.frameX / 18); int top = j - (tile.frameY / 18); Main.NewText("X " + i + " Y " + j); int index = ModContent.GetInstance <BasicTECapacitorEntity>().Find(left, top); if (index == -1) { Main.NewText("false"); return; } if (currentSelectedItem.type == ModContent.ItemType <TerraMeter>()) { StorageEntity se = (StorageEntity)TileEntity.ByID[index]; Main.NewText(se.GetEnergy().getCurrentEnergyLevel() + " / " + se.GetEnergy().getMaxEnergyLevel() + " TE in this Capacitor"); return; } if (currentSelectedItem.type == ModContent.ItemType <RodOfLinking>()) { RodOfLinking it = currentSelectedItem.modItem as RodOfLinking; int tileEntityID = it.GetEntity(); if (tileEntityID == -1) { Main.NewText("The rod of linking is bound to nothing"); return; } CapacitorEntity ce = (CapacitorEntity)TileEntity.ByID[index]; if (ModTileEntity.GetTileEntity(it.GetStoredEntityType().type) is ITECapacitorLinkable terraEnergyCompatibleLinkable) { terraEnergyCompatibleLinkable.LinkToCapacitor(ce); Main.NewText("Succesfully linked to a capacitor, now transferring energy to it", Color.ForestGreen); } return; } BasicTECapacitorEntity capacitorEntity = (BasicTECapacitorEntity)TileEntity.ByID[index]; capacitorEntity.Activate(); }
// Called during instantiation public override void Awake() { if (CompareTag("ActiveItem")) { id = idCounter++; if (_capacitorEntity == null) { _capacitorEntity = new CapacitorEntity { Capacitance = DefaultCapacitance }; } SetAndInitializeConnectors(); GameObject componentIdManager = GameObject.Find("_ComponentIdManager"); GenerateId script = componentIdManager.GetComponent <GenerateId>(); script.generatedIds[3]++; _name += script.generatedIds[3].ToString(); } }
public void LinkToCapacitor(CapacitorEntity capacitor) => boundCapacitor = capacitor;
public void Load(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } LastFileName = fileName; ClearScene(); BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream fileStream = new FileStream(LastFileName, FileMode.Open, FileAccess.Read); object o = binaryFormatter.Deserialize(fileStream); SerializationPackage package = (SerializationPackage)o; foreach (SimulationElement simulationElement in package.SimulationElements) { Type entityType = simulationElement.GetType(); if (entityType == typeof(BatteryEntity)) { BatteryEntity concreteEntity = simulationElement as BatteryEntity; GameObject concreteGameObject = InstantiateGameObject(_batteryPrefab); concreteGameObject.GetComponent <GUIBattery>().Awake(); concreteGameObject.GetComponent <GUIBattery>().Entity = concreteEntity; } else if (entityType == typeof(ResistorEntity)) { ResistorEntity concreteEntity = simulationElement as ResistorEntity; GameObject concreteGameObject = InstantiateGameObject(_resistorPrefab); concreteGameObject.GetComponent <GUIResistor>().Awake(); concreteGameObject.GetComponent <GUIResistor>().Entity = concreteEntity; } else if (entityType == typeof(VoltmeterEntity)) { VoltmeterEntity concreteEntity = simulationElement as VoltmeterEntity; GameObject concreteGameObject = InstantiateGameObject(_voltmeterPrefab); concreteGameObject.GetComponent <GUIVoltmeter>().Awake(); concreteGameObject.GetComponent <GUIVoltmeter>().Entity = concreteEntity; } else if (entityType == typeof(AmpermeterEntity)) { AmpermeterEntity concreteEntity = simulationElement as AmpermeterEntity; GameObject concreteGameObject = InstantiateGameObject(_ampermeterPrefab); concreteGameObject.GetComponent <GUIAmpermeter>().Awake(); concreteGameObject.GetComponent <GUIAmpermeter>().Entity = concreteEntity; } else if (entityType == typeof(AnalogSwitchEntity)) { AnalogSwitchEntity concreteEntity = simulationElement as AnalogSwitchEntity; GameObject concreteGameObject = InstantiateGameObject(_analogSwitchPrefab); concreteGameObject.GetComponent <GUIAnalogSwitch>().Awake(); concreteGameObject.GetComponent <GUIAnalogSwitch>().Entity = concreteEntity; } else if (entityType == typeof(CapacitorEntity)) { CapacitorEntity concreteEntity = simulationElement as CapacitorEntity; GameObject concreteGameObject = InstantiateGameObject(_capacitorPrefab); concreteGameObject.GetComponent <GUICapacitor>().Awake(); concreteGameObject.GetComponent <GUICapacitor>().Entity = concreteEntity; } else if (entityType == typeof(InductorEntity)) { InductorEntity concreteEntity = simulationElement as InductorEntity; GameObject concreteGameObject = InstantiateGameObject(_inductorPrefab); concreteGameObject.GetComponent <GUIInductor>().Awake(); concreteGameObject.GetComponent <GUIInductor>().Entity = concreteEntity; } else if (entityType == typeof(LampEntity)) { LampEntity concreteEntity = simulationElement as LampEntity; GameObject concreteGameObject = InstantiateGameObject(_lampPrefab); concreteGameObject.GetComponent <GUILamp>().Awake(); concreteGameObject.GetComponent <GUILamp>().Entity = concreteEntity; } else if (entityType == typeof(NodeEntity)) { NodeEntity concreteEntity = simulationElement as NodeEntity; GameObject concreteGameObject = InstantiateGameObject(_nodePrefab); concreteGameObject.GetComponent <GUINode>().Awake(); concreteGameObject.GetComponent <GUINode>().Entity = concreteEntity; } else if (entityType == typeof(LedDiodeEntity)) { LedDiodeEntity concreteEntity = simulationElement as LedDiodeEntity; GameObject concreteGameObject = InstantiateGameObject(_ledDiodePrefab); concreteGameObject.GetComponent <GUILedDiode>().Awake(); concreteGameObject.GetComponent <GUILedDiode>().Entity = concreteEntity; } else if (entityType == typeof(TransistorNPNEntity)) { TransistorNPNEntity concreteEntity = simulationElement as TransistorNPNEntity; GameObject concreteGameObject = InstantiateGameObject(_transistorNPNPrefab); concreteGameObject.GetComponent <GUITransistorNPN>().Awake(); concreteGameObject.GetComponent <GUITransistorNPN>().Entity = concreteEntity; } else if (entityType == typeof(TransistorPNPEntity)) { TransistorPNPEntity concreteEntity = simulationElement as TransistorPNPEntity; GameObject concreteGameObject = InstantiateGameObject(_transistorPNPPrefab); concreteGameObject.GetComponent <GUITransistorPNP>().Awake(); concreteGameObject.GetComponent <GUITransistorPNP>().Entity = concreteEntity; } else if (entityType == typeof(ZenerDiodeEntity)) { ZenerDiodeEntity concreteEntity = simulationElement as ZenerDiodeEntity; GameObject concreteGameObject = InstantiateGameObject(_zenerDiodePrefab); concreteGameObject.GetComponent <GUIZenerDiode>().Awake(); concreteGameObject.GetComponent <GUIZenerDiode>().Entity = concreteEntity; } else if (entityType == typeof(PotentiometerEntity)) { PotentiometerEntity concreteEntity = simulationElement as PotentiometerEntity; GameObject concreteGameObject = InstantiateGameObject(_potentiometerPrefab); concreteGameObject.GetComponent <GUIPotentiometer>().Awake(); concreteGameObject.GetComponent <GUIPotentiometer>().Entity = concreteEntity; } } List <Connector> connectors = FindObjectsOfType <Connector>().ToList(); connectors = connectors.Where( x => x.transform.parent != null && (x.transform.parent.CompareTag("ActiveItem") || x.transform.parent.CompareTag("ActiveNode"))).ToList(); foreach (LineEntity packageLineEntity in package.LineEntities) { Connector start = connectors.Find(x => x.TemporaryId == packageLineEntity.StartConnectorId); Connector end = connectors.Find(x => x.TemporaryId == packageLineEntity.EndConnectorId); GameObject linePrefab = Instantiate(_linePrefab); Line line = linePrefab.AddComponent <Line>(); line.Begin = start.gameObject; line.End = end.gameObject; line.TypeOfLine = packageLineEntity.LineType; line.EndPos = end.transform.position; line.StartPos = start.transform.position; linePrefab.tag = "ActiveLine"; linePrefab.transform.position = new Vector2((line.Begin.transform.position.x + line.EndPos.x) / 2, (line.Begin.transform.position.y + line.EndPos.y) / 2); end.GetComponent <Connectable>().AddConnected(start.gameObject); start.GetComponent <Connectable>().AddConnected(end.gameObject); start.ConnectedConnectors.Add(end); end.ConnectedConnectors.Add(start); } fileStream.Close(); }
public void linkToCapacitor(CapacitorEntity capacitor) { boundCapacitor = capacitor; }