Exemplo n.º 1
0
    public void SetAtomA(Atom atom)
    {
        if (atom != null && atomChoices.Count > atom.GetAtomicNumber())
        {
            ChoiceOption choiceOption = atomChoices[atom.GetAtomicNumber() - 1];
            choiceOption.SetButtonEvent(() => {
                RemoveAtomA();
                AudioManager.Instance.PlaySound(choiceClickSound);
            });
            choiceOption.SetColors(ChoiceOption.defaultPressedColor, ChoiceOption.defaultHoverColor, ChoiceOption.defaultNormalColor);
            choiceOption.SetFocus(false);
        }

        atomA = atom;
        //atomChoices[atomA.GetAtomicNumber() - 1].SetInteractable(false);

        AtomInfo info = Game.Instance.gameData.FindAtomInfo(atom.GetAtomicNumber());
        AtomData data = Game.Instance.gameData.FindAtomData(atom.GetAtomicNumber());

        atomAText.text    = info.GetAtom().GetName();
        atomAImage.sprite = info.GetImage();

        atomAAmo.maxValue = data.GetCurrAmo();
        SetAtomAAmoText();

        atomABtn.interactable = true;
    }
Exemplo n.º 2
0
    private void CalculateInfo()
    {
        var info = Game.Instance.playerData.EstimateCombine(atomA, atomB, (int)atomAAmo.value, (int)atomBAmo.value);

        if (info.targetAtom == null)
        {
            infoText.text = "That atom can not be created.";
            produceButton.interactable = false;
            atomResultText.text        = Game.Instance.gameData.GetUknown().GetName();
            return;
        }


        //AtomInfo atomInfo = Game.Instance.gameData.FindAtomInfo(info.targetAtom.GetAtomicNumber());
        AtomData atomData = Game.Instance.gameData.FindAtomData(info.targetAtom.GetAtomicNumber());

        if (!atomData.IsDiscovered())
        {
            atomResultText.text    = Game.Instance.gameData.GetUknown().GetName();
            atomResultImage.sprite = Game.Instance.gameData.GetUknownInfo().GetImage();
        }
        else
        {
            atomResultText.text    = info.targetAtom.GetName();
            atomResultImage.sprite = Game.Instance.gameData.FindAtomInfo(info.targetAtom.GetAtomicNumber())
                                     .GetImage();
        }

        atomProduced = info.targetAtom;

        infoText.text = "Max Production: " + info.amo + "\nSuccess: " + info.success * 100 + "% Stability: " + info.stability * 100 + "%"; // Max Production, Success, Stability

        produceButton.interactable = info.amo > 0;
    }
Exemplo n.º 3
0
        public static AtomData GetAtomByName(string Name)
        {
            string   sql  = "select * from AtomObjects where atom_name='" + Name + "'";
            AtomData atom = GetAtomBySql(sql);

            return(atom);
        }
Exemplo n.º 4
0
    public void SetDisplay()
    {
        //AtomInfo info = Game.Instance.gameData.FindAtomInfo(atom.GetAtomicNumber());
        AtomData data = Game.Instance.gameData.FindAtomData(atom.GetAtomicNumber());

        text.text = atom.GetName() + "\n<size=80%> Atomic Number: " + atom.GetAtomicNumber() + " Curr Amo: " + data.GetCurrAmo();
    }
Exemplo n.º 5
0
        public static void AddAtom(AtomData Atom)
        {
            try
            {
                string sql;
                using (NpgsqlConnection connection = new NpgsqlConnection(strPostGISConnection))
                {
                    connection.Open();

                    sql = "insert into AtomObjects (atom_guid,atom_name,CountryId,pointX,pointY)" +
                          "values ('" + Atom.UnitGuid + "','" +
                          Atom.UnitName + "'," +
                          0 + "," +
                          Atom.Location.x + "," +
                          Atom.Location.y +

                          " )  ";
                    using (NpgsqlCommand command = new NpgsqlCommand(sql, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 6
0
    private void CheckAtomMilestone(Atom a, float amo)
    {
        AtomData data    = Game.Instance.gameData.FindAtomData(a.GetAtomicNumber());
        int      currAmo = data.GetCurrAmo();
        int      prevAmo = currAmo - (int)amo;

        if (currAmo == int.MaxValue)
        {
            Game.Instance.logSystem.Log(a.GetName() + ": MAX");
            return;
        }

        bool hasSurpassed = false;

        for (int i = 1000000000; i > 1; i /= 10)
        {
            if (CheckAtomAmo(currAmo, prevAmo, i, ref hasSurpassed))
            {
                Game.Instance.logSystem.Log(a.GetName() + ": " + i);
                break;
            }
            if (hasSurpassed)
            {
                break;
            }
        }
    }
Exemplo n.º 7
0
 private void Fill(IDictionary dict)
 {
     dict[1]     = 1;
     dict["hey"] = "ho";
     dict[new AtomData("foo")] = new AtomData("bar");
     dict[4] = "Yoman";
 }
Exemplo n.º 8
0
        public void DbStoredProcedureHandler_Execute()
        {
            var commander = new EchoProcedureEmulator();

            var test = new DbStoredProcedureHandler();

            test.Database        = commander.Database;
            test.OperationName   = commander.OperationName;
            test.MetadataBuilder = commander.MetadataBuilder;

            var arg1 = new AtomData("String", "The quick brown fox etc. etc.");
            var arg2 = new AtomData("Integer", 123456);
            var arg3 = new AtomData("Decimal", 3.14159m);

            var arguments = new AtomCollectionData();

            arguments.AddAtom(arg1);
            arguments.AddAtom(arg2);
            arguments.AddAtom(arg3);

            var result = test.Execute(arguments);

            var rowsets = result.RowSets.ToArray();

            Assert.AreEqual(3, rowsets.Length);

            Assert.AreEqual(arg1.Name, rowsets[0].Rows.First().Atoms.First().Name);
            Assert.AreEqual(arg2.Name, rowsets[1].Rows.First().Atoms.First().Name);
            Assert.AreEqual(arg3.Name, rowsets[2].Rows.First().Atoms.First().Name);

            Assert.AreEqual(arg1.Value, rowsets[0].Rows.First().Atoms.First().Value);
            Assert.AreEqual(arg2.Value, rowsets[1].Rows.First().Atoms.First().Value);
            Assert.AreEqual(arg3.Value, rowsets[2].Rows.First().Atoms.First().Value);
        }
Exemplo n.º 9
0
        protected async override void OnDrop(System.Windows.DragEventArgs e)
        {
            double currMapX = 0;
            double currMapY = 0;

            System.Windows.DataObject d = (System.Windows.DataObject)e.Data;

            string[] dataFormats = d.GetFormats();
            string   dataText    = d.GetText();

            Point position = e.GetPosition(this);

            GMap.NET.PointLatLng curPosition = FromLocalToLatLng((int)position.X, (int)position.Y);
            currMapX = curPosition.Lng;
            currMapY = curPosition.Lat;

            for (int i = 0; i < dataFormats.Length; i++)
            {
                string dragFormat = dataFormats[i];

                if (dragFormat.Contains("FormationTree") && dataText == "Actor")
                {
                    object dragObject = d.GetData(dragFormat);

                    FormationTree formation = dragObject as FormationTree;
                    if (formation == null)
                    {
                        continue;
                    }

                    enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined;
                    SetHighwayFilter(highwayFilter);
                    shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY);

                    if (PointId != null)
                    {
                        shPoint           pnt             = PointId.point;
                        DeployedFormation deployFormation = new DeployedFormation();
                        deployFormation.x         = pnt.x;
                        deployFormation.y         = pnt.y;
                        deployFormation.formation = formation;

                        AtomData atom = await TDSClient.SAGInterface.SAGSignalR.DeployFormationFromTree(VMMainViewModel.Instance.SimulationHubProxy, deployFormation);

                        if (atom != null)
                        {
                            AtomDeployedEventArgs args = new AtomDeployedEventArgs();
                            args.atom = atom;
                            if (AtomDeployedEvent != null)
                            {
                                AtomDeployedEvent(this, args);
                            }
                        }
                    }

                    return;
                }
            }
        }
Exemplo n.º 10
0
    private void CalculateInfo()
    {
        if (atomA.GetAtomicNumber() == 1)  // Hydrogen can not be split
        {
            infoText.text         = "Hydrogen can not be split";
            splitBtn.interactable = false;
            return;
        }
        PlayerData.AtomCollision info;
        if (toHydrogenToggle.isOn)
        {
            info           = new PlayerData.AtomCollision();
            info.success   = 1;
            info.stability = 1;

            Atom atom = atomA;
            int  amo  = (int)atomAAmo.value;
            do
            {
                var infoTemp = Game.Instance.playerData.EstimateSplit(atom, amo);
                atom = infoTemp.targetAtom;
                amo  = infoTemp.amo;
                print("Currently at: " + atom.GetName() + " " + amo);

                info.targetAtom = atom;
                info.amo        = amo;
                info.success   *= infoTemp.success;
                info.stability *= infoTemp.stability;
            } while (atom.GetAtomicNumber() != 1);
        }
        else
        {
            int amo = atomAAmo.value < 0 ? int.MaxValue : (int)atomAAmo.value;
            info = Game.Instance.playerData.EstimateSplit(atomA, amo);
        }

        AtomData atomData = Game.Instance.gameData.FindAtomData(info.targetAtom.GetAtomicNumber());

        if (!atomData.IsDiscovered())
        {
            atomResultText.text    = Game.Instance.gameData.GetUknown().GetName();
            atomResultImage.sprite = Game.Instance.gameData.GetUknownInfo().GetImage();
        }
        else
        {
            atomResultText.text    = info.targetAtom.GetName();
            atomResultImage.sprite = Game.Instance.gameData.FindAtomInfo(info.targetAtom.GetAtomicNumber())
                                     .GetImage();
        }

        //atomResultText.text = info.targetAtom.GetName();
        infoText.text = "Max Production: " + info.amo + "\nSuccess: " + info.success * 100 + "% Stability: " + info.stability * 100 + "%"; // Max Production, Success, Stability

        splitBtn.interactable = info.amo > 0;
    }
Exemplo n.º 11
0
    public CraftResult Craft(Craftable c, int amount)
    {
        CraftResult result = new CraftResult();

        result.atomsUsed = new List <AtomAmo>();

        var atoms = c.GetAtomsForProduction();

        for (int i = 0; i < atoms.Length; i++)  // Find Minumum
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            if (data.GetCurrAmo() < needed)
            {
                amount = data.GetCurrAmo() / atomAmo.amo;
            }
        }

        for (int i = 0; i < atoms.Length; i++)
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            data.Lose(needed);

            AtomAmo atomUsed = new AtomAmo();
            atomUsed.atom = atomAmo.atom;
            atomUsed.amo  = needed;
            result.atomsUsed.Add(atomUsed);
        }
        result.amountCreated = amount;

        int amoOfCraftables;

        if (!craftables.TryGetValue(c, out amoOfCraftables))
        {
            craftables[c] = amount;
        }
        else
        {
            craftables[c] = amoOfCraftables + amount;
        }

        if (OnCraftableProduced != null)
        {
            OnCraftableProduced(c, amount);
        }

        return(result);
    }
Exemplo n.º 12
0
    public AtomCollisionResult ProduceCombine(Atom a, Atom b, int aAmo, int bAmo)
    {
        AtomCollision info = EstimateCombine(a, b, aAmo, bAmo);

        AtomCollisionResult result = new AtomCollisionResult();

        result.atomsProduced = new List <AtomAmo>();
        result.atomsUsed     = new List <AtomAmo>();

        AtomData aData   = Game.Instance.gameData.FindAtomData(a.GetAtomicNumber());
        AtomData bData   = Game.Instance.gameData.FindAtomData(b.GetAtomicNumber());
        int      usedAmo = Mathf.Min(Mathf.Min(aAmo, aData.GetCurrAmo()), Mathf.Min(bAmo, bData.GetCurrAmo()));

        Atom target = info.targetAtom;
        int  maxAmo = info.amo;

        float successChance   = info.success;
        float stabilityChance = 1.0f;

        stabilityChance = info.stability;

        int produced   = (int)(maxAmo * successChance);
        int stabilized = (int)(produced * stabilityChance);

        AtomAmo atomAmo = new AtomAmo();

        atomAmo.amo  = stabilized;
        atomAmo.atom = target;
        result.atomsProduced.Add(atomAmo);

        Game.Instance.Absorb(target, stabilized);

        AtomAmo atomAUsed = new AtomAmo();

        atomAUsed.atom = a;
        atomAUsed.amo  = usedAmo;
        result.atomsUsed.Add(atomAUsed);

        AtomAmo atomBUsed = new AtomAmo();

        atomBUsed.atom = b;
        atomBUsed.amo  = usedAmo;
        result.atomsUsed.Add(atomBUsed);

        Game.Instance.Use(a, usedAmo);
        Game.Instance.Use(b, usedAmo);

        if (OnAtomCombine != null)
        {
            OnAtomCombine(target, stabilized);
        }

        return(result);
    }
Exemplo n.º 13
0
 public void ByMonth()
 {
     AtomData.Clear();
     for (int i = 1; i <= 12; i++)
     {
         var data = Db.Table <DataModel>().Where(p => p.Time.Month == i);
         AtomData.Add(new GraphModel {
             Line = data.Max(p => p.Temp), Line2 = data.Average(p => p.Temp), Line3 = data.Min(p => p.Temp)
         });
     }
 }
Exemplo n.º 14
0
    public static void CreateAtomData(Atom a)
    {
        AtomData aD = AtomData.CreateNewAtomData(a);

        string atomDataPathName = AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/ScriptableObjects/AtomData/" + a.GetAtomicNumber() + a.GetName() + "Data.asset");

        AssetDatabase.CreateAsset(aD, atomDataPathName);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
    }
Exemplo n.º 15
0
        public bool Upgrade()
        {
            bool success = CanUpgrade();

            if (success)
            {
                for (int i = 0; i < data.cost.Count; i++)   // Use
                {
                    AtomAmo atomCost = data.cost[i];
                    if (atomCost.atom == null)
                    {
                        continue;
                    }

                    AtomData atomData = Game.Instance.gameData.FindAtomData(data.cost[i].atom.GetAtomicNumber());
                    atomData.Lose(data.cost[i].amo);
                }

                data.level++;
                data.value = valueProgression.Evaluate(data.level);

                data.cost.Clear();
                if (!IsMaxLevel())
                {
                    AtomAmo amo = new AtomAmo();
                    for (int i = 0; i < atomProgression.Count; i++)
                    {
                        amo.amo = (int)amoProgression[i].Evaluate(data.level);

                        int index = (int)atomProgression[i].Evaluate(data.level);
                        if (index == 0)
                        {
                            amo.atom = null;
                        }
                        else
                        {
                            amo.atom = Game.Instance.gameData.FindAtom(index);
                        }

                        data.cost.Add(amo);
                    }
                }
            }

            return(success);
        }
Exemplo n.º 16
0
        public void DrawMonth(int year)
        {
            AtomData.Clear();
            SoilData.Clear();
            SoilData.Add(new PieModel {
                title = "", value = 0
            });
            RainData.Clear();
            PmData.Clear();
            var data = Db.Table <DataModel>().ToList().Where(p => p.Time.Year == year);

            for (int i = 1; i <= 12; i++)
            {
                var temp = data.Where(p => p.Time.Month == i);
                if (temp.Count() > 0)
                {
                    AtomData.Add(new GraphModel {
                        Line = temp.Max(p => p.Temp), Line2 = temp.Average(p => p.Temp), Line3 = temp.Min(p => p.Temp)
                    });
                }
            }
            var count = data.Count();
            var soil  = (double)data.Count(p => p.Soil == 0) / count;
            var rain  = (double)data.Count(p => p.Rain == 0) / count;
            var pm    = (double)data.Count(p => p.Pm25 == 0) / count;

            SoilData.Add(new PieModel {
                title = "干燥", value = soil
            });
            SoilData.Add(new PieModel {
                title = "湿润", value = 1 - soil
            });
            RainData.Add(new PieModel {
                title = "有雨", value = 1 - rain
            });
            RainData.Add(new PieModel {
                title = "无雨", value = rain
            });
            PmData.Add(new PieModel {
                title = "超标", value = 1 - pm
            });
            PmData.Add(new PieModel {
                title = "良好", value = pm
            });
        }
Exemplo n.º 17
0
    public AtomCollisionResult ProduceSplit(Atom a, int aAmo)
    {
        AtomCollision info = EstimateSplit(a, aAmo);

        AtomData aData = Game.Instance.gameData.FindAtomData(a.GetAtomicNumber());

        aAmo = Mathf.Min(aAmo, aData.GetCurrAmo());

        AtomCollisionResult result = new AtomCollisionResult();

        result.atomsProduced = new List <AtomAmo>();
        result.atomsUsed     = new List <AtomAmo>();

        Atom target = info.targetAtom;

        // Split
        int produced = (int)(info.amo * info.success); // Random Loss

        // Stabilize
        int stabilized = (int)(produced * info.stability);

        // Result
        AtomAmo atomAmo = new AtomAmo();

        atomAmo.amo  = stabilized;
        atomAmo.atom = target;
        result.atomsProduced.Add(atomAmo);
        Game.Instance.Absorb(target, stabilized);

        // Used
        AtomAmo atomAUsed = new AtomAmo();

        atomAUsed.atom = a;
        atomAUsed.amo  = aAmo;
        result.atomsUsed.Add(atomAUsed);
        Game.Instance.Use(a, aAmo);


        if (OnAtomSplit != null)
        {
            OnAtomSplit(target, stabilized);
        }

        return(result);
    }
Exemplo n.º 18
0
        public void DrawHour(int year, int month, int day)
        {
            SoilData.Clear();
            RainData.Clear();
            PmData.Clear();
            AtomData.Clear();
            SoilData.Add(new PieModel {
                title = "", value = 0
            });
            var list = Db.Table <DataModel>().ToList();
            var data = list.Where(p => p.Time.Year == year && p.Time.Month == month && p.Time.Day == day);

            for (int i = 0; i < 24; i++)
            {
                var temp = data.First(p => p.Time.Hour == i);
                AtomData.Add(new GraphModel {
                    Line = temp.Temp
                });
            }
            var count = data.Count();
            var soil  = (double)data.Count(p => p.Soil == 0) / count;
            var rain  = (double)data.Count(p => p.Rain == 0) / count;
            var pm    = (double)data.Count(p => p.Pm25 == 0) / count;

            SoilData.Add(new PieModel {
                title = "干燥", value = soil
            });
            SoilData.Add(new PieModel {
                title = "湿润", value = 1 - soil
            });
            RainData.Add(new PieModel {
                title = "有雨", value = 1 - rain
            });
            RainData.Add(new PieModel {
                title = "无雨", value = rain
            });
            PmData.Add(new PieModel {
                title = "超标", value = 1 - pm
            });
            PmData.Add(new PieModel {
                title = "良好", value = pm
            });
        }
Exemplo n.º 19
0
    public static void CreateAtom(string name, string abbreviation, int atomicNumber)
    {
        Atom a = Atom.CreateNewAtom(name, abbreviation, atomicNumber);

        AtomInfo aI = AtomInfo.CreateNewAtomInfo(a);
        AtomData aD = AtomData.CreateNewAtomData(a);

        string atomPathName     = AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/ScriptableObjects/Atom/" + a.GetAtomicNumber() + a.GetName() + ".asset");
        string atomInfoPathName = AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/ScriptableObjects/AtomInfo/" + a.GetAtomicNumber() + a.GetName() + "Info.asset");
        string atomDataPathName = AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/ScriptableObjects/AtomData/" + a.GetAtomicNumber() + a.GetName() + "Data.asset");

        AssetDatabase.CreateAsset(a, atomPathName);
        AssetDatabase.CreateAsset(aI, atomInfoPathName);
        AssetDatabase.CreateAsset(aD, atomDataPathName);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
    }
Exemplo n.º 20
0
    public void Absorb(Atom atom, int amo)
    {
        if (amo == 0)
        {
            return;
        }

        AtomData data = FindAtomData(atom.GetAtomicNumber());

        if (data == null)
        {
            return;
        }

        if (!data.IsDiscovered())
        {
            data.SetIsDiscovered(true);
            if (OnAtomDiscover != null)
            {
                OnAtomDiscover(atom, amo);
            }

            if (maxAtom == null || atom.GetAtomicNumber() > maxAtom.GetAtomicNumber())
            {
                maxAtom = atom;
            }
        }
        if (amo + data.GetCurrAmo() < data.GetCurrAmo())
        {
            amo = int.MaxValue - data.GetCurrAmo();
            if (amo == 0)
            {
                return;
            }
        }

        data.Gain(amo);
        if (OnAtomAdd != null)
        {
            OnAtomAdd(atom, amo);
        }
    }
Exemplo n.º 21
0
    public void Use(Atom atom, int amo)
    {
        if (amo == 0)
        {
            return;
        }

        AtomData data = FindAtomData(atom.GetAtomicNumber());

        if (data == null)
        {
            return;
        }

        data.Lose(amo);
        if (OnAtomUse != null)
        {
            OnAtomUse(atom, amo);
        }
    }
Exemplo n.º 22
0
    public bool CanCraft(Craftable c)
    {
        int amount = 1;

        var atoms = c.GetAtomsForProduction();

        for (int i = 0; i < atoms.Length; i++)   // Find Minumum
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            if (data.GetCurrAmo() < needed)
            {
                amount = data.GetCurrAmo() / atomAmo.amo;
            }
        }

        return(amount != 0);
    }
Exemplo n.º 23
0
        private static AtomData GetAtomBySql(string sql)
        {
            try
            {
                AtomData atom = new AtomData();

                using (NpgsqlConnection connection = new NpgsqlConnection(strPostGISConnection))
                    using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, connection))
                    {
                        DataSet   dsPol = new DataSet();
                        DataTable dtPol = new DataTable();
                        dsPol.Reset();
                        da.Fill(dsPol);
                        dtPol = dsPol.Tables[0];

                        if (dtPol == null || dtPol.Rows == null || dtPol.Rows.Count == 0)
                        {
                            return(null);
                        }

                        foreach (DataRow row in dtPol.Rows)
                        {
                            atom.UnitGuid   = row["atom_guid"].ToString();
                            atom.UnitName   = row["atom_name"].ToString();
                            atom.Location   = new DPoint();
                            atom.Location.x = System.Convert.ToDouble(row["pointX"]);
                            atom.Location.y = System.Convert.ToDouble(row["pointY"]);
                        }
                    }


                return(atom);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Exemplo n.º 24
0
        public bool CanUpgrade()
        {
            if (IsMaxLevel())
            {
                return(false);
            }

            for (int i = 0; i < data.cost.Count; i++)   // Validation
            {
                AtomAmo atomCost = data.cost[i];
                if (atomCost.atom == null)
                {
                    continue;
                }

                AtomData atomData = Game.Instance.gameData.FindAtomData(atomCost.atom.GetAtomicNumber());
                if (atomData.GetCurrAmo() < atomCost.amo)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 25
0
    public static void LoadAtoms()
    {
        var text = Resources.Load<TextAsset>("elements");
        var l = new List<AtomData>();
        var r = new StringReader(text.text);
        while (r.Peek() > 0)
        {
            var next = r.ReadLine();
            var data = next.Split(';');

            var atom = new AtomData()
            {
                index = int.Parse(data[0]),
                symbol = data[1],
                name = data[2]
            };

            l.Add(atom);

        }

        Atoms = l.ToArray();
    }
Exemplo n.º 26
0
        public static IEnumerable <AtomData> GetAllAtoms()
        {
            try
            {
                List <AtomData> atoms = new List <AtomData>();
                string          sql   = "select * from AtomObjects";
                using (NpgsqlConnection connection = new NpgsqlConnection(strPostGISConnection))
                    using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, connection))
                    {
                        DataSet   ds = new DataSet();
                        DataTable dt = new DataTable();
                        ds.Reset();
                        da.Fill(ds);
                        dt = ds.Tables[0];

                        if (dt == null || dt.Rows == null || dt.Rows.Count == 0)
                        {
                            return(null);
                        }
                        foreach (DataRow row in dt.Rows)
                        {
                            AtomData atom = new AtomData();
                            atom.UnitGuid   = row["atom_guid"].ToString();
                            atom.UnitName   = row["atom_name"].ToString();
                            atom.Location   = new DPoint();
                            atom.Location.x = System.Convert.ToDouble(row["pointX"]);
                            atom.Location.y = System.Convert.ToDouble(row["pointY"]);
                            atoms.Add(atom);
                        }
                    }
                return(atoms);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Exemplo n.º 27
0
    public void SetDisplay()
    {
        AtomInfo info = Game.Instance.gameData.FindAtomInfo(atom.GetAtomicNumber());
        AtomData data = Game.Instance.gameData.FindAtomData(atom.GetAtomicNumber());

        Atom display = atom;

        if (!data.IsDiscovered())
        {
            info    = Game.Instance.gameData.GetUknownInfo();
            display = Game.Instance.gameData.GetUknown();
        }
        else if (!hasBeenDiscovered)
        {
            exclamationImage.gameObject.SetActive(true);
            hasBeenDiscovered = true;

            clickButton.onClick.RemoveAllListeners();
            clickButton.onClick.AddListener(() => {
                MakeOld();
                ElementsPage.Instance.ClickAtom(atom);
                AudioManager.Instance.PlaySound(clickSound);
            });
        }

        // Display Stuff
        atomNumber.text           = display.GetAtomicNumber() == -1 ? "" : "" + display.GetAtomicNumber();
        atomAbbreviationText.text = display.GetAbbreviation();

        Color c = info.GetCategoryColor();

        background.color = c;
        c  *= .6f;
        c.a = 1f;
        lowBackground.color = c;
    }
Exemplo n.º 28
0
    public void Setup(Atom a)
    {
        atom = a;

        AtomData data = Game.Instance.gameData.FindAtomData(atom.GetAtomicNumber());
        AtomInfo info = Game.Instance.gameData.FindAtomInfo(atom.GetAtomicNumber());

        if (!data.IsDiscovered())
        {
            info = Game.Instance.gameData.GetUknownInfo();
            data = Game.Instance.gameData.GetUknownData();
            a    = Game.Instance.gameData.GetUknown();
        }

        // Display
        nameText.text         = a.GetName();
        atomicNumberText.text = "Atomic Number: \n" + (a.GetAtomicNumber() == -1 ? "?" : "" + a.GetAtomicNumber());
        atomImage.sprite      = info.GetImage();

        // Data
        currAmoText.text        = "Current Amo: " + data.GetCurrAmo();
        passiveGainText.text    = "";// "Passive Gain: " + data.GetPassiveGain(); // What to do with this???
        totalCollectedText.text = "Total Atoms: " + data.GetTotalCollected();
        totalUsedText.text      = "Total Used: " + data.GetTotalUsed();

        // Description
        var size = descriptionText.GetPreferredValues(info.GetDescription(), descriptionText.rectTransform.rect.width, Mathf.Infinity);

        size.x = descriptionContent.sizeDelta.x;
        size.y = Mathf.Abs(size.y) + 5;
        descriptionContent.sizeDelta = size;
        //descriptionText.rectTransform.sizeDelta = size;

        descriptionText.text    = info.GetDescription();
        descriptionScroll.value = 1;
        typeText.text           = "Type: " + info.GetCategoryString();
        weightText.text         = "Weight: " + (info.GetWeight() == -1 ? "???" : "" + info.GetWeight());
        densityText.text        = "Density: " + (info.GetDensity() == -1 ? "???" :
                                                 info.GetDensity() + " g/cm<sup>3</sup>");

        // Isotope
        protonsText.text     = "P: " + (info.GetProtons() == -1 ? "?" : "" + info.GetProtons());
        electronsText.text   = "E: " + (info.GetElectrons() == -1 ? "?" : "" + info.GetElectrons());
        neutronsText.text    = "N: " + (info.GetNeutrons() == -1 ? "?" : "" + info.GetNeutrons());
        radioactiveText.text = "Is Radioactive: " + !info.IsStable();// + " " + info.GetHalfLife() + " " + info.GetStability();

        string isotopeString = "Isotopes:\n<size=80%>\t";
        var    isotopes      = info.GetIsotopes();

        if (isotopes.Length > 0)
        {
            isotopeString += isotopes[0] + "\n\t";
        }
        for (int i = 1; i < isotopes.Length /*&& i < 7*/; i++)    // MAximum of 7 isotopes???
        {
            isotopeString += isotopes[i] + "\n\t";
        }
        isotopeText.text = isotopeString;

        // Area
        string placesString = "Places:\n";
        var    places       = info.GetPlacesToBeFound();

        if (places.Length > 0)
        {
            placesString += "  " + places[0] + "\n";
        }
        for (int i = 1; i < places.Length; i++)
        {
            placesString += "  " + places[i] + "\n";
        }
        placesText.text = placesString;

        string originsString = "Origins:\n";
        var    origins       = info.GetOrigins();

        if (origins.Length > 0)
        {
            originsString += "  " + origins[0] + "\n";
        }
        for (int i = 1; i < origins.Length; i++)
        {
            originsString += "  " + origins[i] + "\n";
        }
        originsText.text = originsString;
    }
Exemplo n.º 29
0
    public void Setup(Atom a)
    {
        atom = a;

        AtomData data = Game.Instance.gameData.FindAtomData(atom.GetAtomicNumber());
        AtomInfo info = Game.Instance.gameData.FindAtomInfo(atom.GetAtomicNumber());

        if (!data.IsDiscovered())
        {
            info = Game.Instance.gameData.GetUknownInfo();
            data = Game.Instance.gameData.GetUknownData();
            a    = Game.Instance.gameData.GetUknown();
        }

        // Color
        Color c = info.GetCategoryColor();

        background.color = c;
        c  *= .6f;
        c.a = 1f;
        darkBackground.color = c;

        var sizeDelta = rect == null ? Vector2.zero : rect.sizeDelta;

        // Name Text
        {
            var size = nameText.GetPreferredValues(a.GetName(), Mathf.Infinity, nameText.rectTransform.rect.height);
            size.y  = nameText.rectTransform.sizeDelta.y;
            size.x += 15f;
            if (size.x > sizeDelta.x)
            {
                sizeDelta.x = size.x;
            }

            nameText.text = a.GetName();
        }

        // Curr Amo Text
        {
            string text = "Amount:\n " + data.GetCurrAmo();

            var size = currAmoText.GetPreferredValues(text, Mathf.Infinity, currAmoText.rectTransform.rect.height);
            size.y  = currAmoText.rectTransform.sizeDelta.y;
            size.x += 15f;
            if (size.x > sizeDelta.x)
            {
                sizeDelta.x = size.x;
            }

            currAmoText.text = text;
        }

        // Passive Gain Text
        {
            string text = "(+" + data.GetPassiveGain() + ")";

            var size = passiveGainText.GetPreferredValues(text, Mathf.Infinity, passiveGainText.rectTransform.rect.height);
            size.y  = passiveGainText.rectTransform.sizeDelta.y;
            size.x += 15f;
            if (size.x > sizeDelta.x)
            {
                sizeDelta.x = size.x;
            }

            passiveGainText.text = text;
        }

        rect.sizeDelta = sizeDelta;
        LateUpdate();
    }
Exemplo n.º 30
0
        /// <summary>
        /// Start with an atom and detect which ring it's part of
        /// </summary>
        /// <param name="startAtom">Atom of degree >= 2</param>
        ///
        private static Ring GetRing(Atom startAtom)
        {
            // Only returns the first ring.
            //
            // Uses the Figueras algorithm
            // Figueras, J, J. Chem. Inf. Comput. Sci., 1996,36, 96, 986-991
            // The algorithm goes as follows:
            //1. Remove node frontNode and its Source from the front of the queue.
            //2. For each node m attached to frontNode, and not equal to Source:
            //If path[m] is null, compute path[m] ) path[frontNode] +[m]
            //and put node m(with its Source, frontNode) on the back of the queue.
            //If path[m] is not null then
            //      1) Compute the intersection path[frontNode]*path[m].
            //      2) If the intersection is a singleton, compute the ring set  path[m]+path[frontNode] and exit.
            //3. Return to step 1.
            //set up the data structures
            Queue <AtomData> atomsSoFar; //needed for BFS
            Dictionary <Atom, HashSet <Atom> > path = new Dictionary <Atom, HashSet <Atom> >();

            //initialise all the paths to empty
            foreach (var atom in startAtom.Parent.Atoms)
            {
                path[atom] = new HashSet <Atom>();
            }
            //set up a new queue
            atomsSoFar = new Queue <AtomData>();

            //set up a front node and shove it onto the queue
            AtomData frontNode;

            //shove the neigbours onto the queue to prime it
            foreach (Atom initialAtom in startAtom.Neighbours)
            {
                var node = new AtomData()
                {
                    Source = startAtom, CurrentAtom = initialAtom
                };
                path[initialAtom] = new HashSet <Atom>()
                {
                    startAtom, initialAtom
                };
                atomsSoFar.Enqueue(node);
            }
            //now scan the Molecule and detect all rings
            while (atomsSoFar.Any())
            {
                frontNode = atomsSoFar.Dequeue();
                foreach (Atom m in frontNode.CurrentAtom.Neighbours)
                {
                    if (m != frontNode.Source)                              //ignore an atom that we've visited
                    {
                        if ((!path.ContainsKey(m)) || (path[m].Count == 0)) //null path
                        {
                            var temp = new HashSet <Atom>();
                            temp.Add(m);
                            temp.UnionWith(path[frontNode.CurrentAtom]);
                            path[m] = temp; //add on the path built up so far
                            AtomData newItem = new AtomData()
                            {
                                Source = frontNode.CurrentAtom, CurrentAtom = m
                            };
                            atomsSoFar.Enqueue(newItem);
                        }
                        else //we've got a collision - is it a ring closure
                        {
                            HashSet <Atom> overlap = new HashSet <Atom>();
                            overlap.UnionWith(path[frontNode.CurrentAtom]); //clone this set
                            overlap.IntersectWith(path[m]);
                            if (overlap.Count == 1)                         //we've had a singleton overlap :  ring closure
                            {
                                var ringAtoms = new HashSet <Atom>();
                                ringAtoms.UnionWith(path[m]);
                                ringAtoms.UnionWith(path[frontNode.CurrentAtom]);

                                return(new Ring(ringAtoms));
                            }
                        }
                    }
                }
            }
            //no collisions therefore no rings detected
            return(null);
        }
Exemplo n.º 31
0
        private async void cmdExit_Click(object sender, RoutedEventArgs e)
        {
            bool isCheckOk = await CheckOk();

            if (isCheckOk == false)
            {
                return;
            }

            DrawPolygonEventArgs arg = new DrawPolygonEventArgs();

            arg.isCancel = false;
            arg.isNew    = true;

            arg.PolygonName = txtRouteName.Text.Trim();

            arg.PolygonPnts = m_PolygonPnts.ToArray <DPoint>();
            //  isOK = true;
            if (EndDrawPolygonEvent != null)
            {
                EndDrawPolygonEvent(this, arg);
            }


            GeneralActivityDTO ActivityDTO = new GeneralActivityDTO();

            ActivityDTO.ActivityType = enumActivity.MovementActivity;

            AtomData atomdata = new AtomData();

            atomdata.UnitName = txPlatformName.Text;
            atomdata.Location = m_PolygonPnts[0];

            ActivityDTO.StartActivityOffset = (TimeSpan)startActivity.Value;
            ActivityDTO.DurationActivity    = (TimeSpan)durationActivity.Value;
            ActivityDTO.Speed = (int)speedUpDown.Value;

            Route route = new Route();

            route.RouteName           = txtRouteName.Text;
            route.Points              = m_PolygonPnts;
            ActivityDTO.RouteActivity = route;

            if (refActivityDTO != null)
            {
                atomdata.UnitGuid      = refActivityDTO.Atom.UnitGuid;
                ActivityDTO.ActivityId = refActivityDTO.ActivityId;
                if (ActivityDTO.RouteActivity != null)
                {
                    ActivityDTO.RouteActivity.RouteGuid = refActivityDTO.RouteActivity.RouteGuid;
                }
            }



            ActivityDTO.Atom = atomdata;



            await SAGSignalR.SaveActivity(VMMainViewModel.Instance.SimulationHubProxy, ActivityDTO);


            this.Close();
        }
Exemplo n.º 32
0
 public MoleculeData(AtomData child, string name) : base(child, name)
 {
 }
Exemplo n.º 33
0
 public MoleculeData(AtomData child) : base(child)
 {
 }
Exemplo n.º 34
0
 public AtomData(AtomData child, string name
     ) : this(child)
 {
     this.name = name;
 }
Exemplo n.º 35
0
 public AtomData(AtomData child)
 {
     this.child = child;
 }