Files
2024-07-10 16:16:34 +01:00

57 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Godot;
using VirtualChemistry.Demo.Scenes;
using VirtualChemistry.Chemistry.Bonds.Implements;
namespace VirtualChemistry.Demo.Concepts;
public abstract partial class Bond2D : Line2D
{
public BaseBond BondFrom { get; set; }
public BaseBond BondTo { get; set; }
public Atom AtomFrom { get; set; }
public Atom AtomTo { get; set; }
protected Label BondTypeA { get; set; }
protected Label BondTypeB { get; set; }
/*public string TypeA { get; set; }
public string TypeB { get; set; }*/
public int Index { get; set; } = 999;
public int Multi { get; set; } = -1;
public override void _Ready()
{
BondTypeA = GetNode<Label>("BondTypeA");
BondTypeB = GetNode<Label>("BondTypeB");
}
public void Reindex()
{
HashSet<Bond2D> bonds = new();
foreach (Bond2D bond in GlobalScene.CompoundConstructor.BondMap[AtomFrom])
{
if (
(bond.AtomTo == AtomTo && bond.AtomFrom == AtomFrom) ||
(bond.AtomFrom == AtomTo && bond.AtomTo == AtomFrom)
)
bonds.Add(bond);
}
int idx = 1;
foreach (Bond2D bond in bonds.OrderBy(x => x.Index))
{
if (bond.Index != idx)
bond.Index = idx;
idx++;
bond.Multi = bonds.Count;
}
}
public abstract void BondUpdate();
public static Bond2D Resolve(BaseBond b1, BaseBond b2)
{
if (b1.Atom == b2.Atom)
return ResourceLoader.Load<PackedScene>("res://Scenes/SelfBond.tscn").Instantiate<SelfBond>();
return ResourceLoader.Load<PackedScene>("res://Scenes/SingleBond.tscn").Instantiate<SingleBond>();
}
}