Пример #1
0
        public SpeciesData(SpeciesData species)
        {
            species_id    = species.species_id;
            name          = species.name;
            organism_type = species.organism_type;
            description   = species.description;
            biomass       = species.biomass;
            diet_type     = species.diet_type;
            trophic_level = species.trophic_level;

            level = species.level;

            predatorList = new Dictionary <int, string>();
            foreach (KeyValuePair <int, string> predator in species.predatorList)
            {
                predatorList.Add(predator.Key, predator.Value);
            }

            preyList = new Dictionary <int, string>();
            foreach (KeyValuePair <int, string> prey in species.preyList)
            {
                preyList.Add(prey.Key, prey.Value);
            }

            categoryList = new string[0];

            image = species.image;
        }
Пример #2
0
        public SpeciesData(SpeciesData species)
        {
            species_id = species.species_id;
            name = species.name;
            organism_type = species.organism_type;
            description = species.description;
            biomass = species.biomass;
            diet_type = species.diet_type;
            trophic_level = species.trophic_level;

            level = species.level;

            predatorList = new Dictionary<int, string>();
            foreach (KeyValuePair<int, string> predator in species.predatorList) {
            predatorList.Add(predator.Key, predator.Value);
            }

            preyList = new Dictionary<int, string>();
            foreach (KeyValuePair<int, string> prey in species.preyList) {
            preyList.Add(prey.Key, prey.Value);
            }

            categoryList = new string[0];

            image = species.image;
        }
Пример #3
0
        public static NetworkResponse Parse(MemoryStream dataStream)
        {
            ResponseSpeciesList response = new ResponseSpeciesList();

            Dictionary <int, SpeciesData> speciesList = new Dictionary <int, SpeciesData>();

            int size = DataReader.ReadShort(dataStream);

            //Debug.Log ("species list size is: " + size);
            for (int i = 0; i < size; i++)
            {
                SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
                species.level = DataReader.ReadShort(dataStream);
                //Debug.Log ("species list level is: " + species.level);
                species.name        = DataReader.ReadString(dataStream);
                species.description = DataReader.ReadString(dataStream);

                short    numArgs   = DataReader.ReadShort(dataStream);
                string[] extraArgs = new string[numArgs];

                for (int j = 0; j < numArgs; j++)
                {
                    string arg = DataReader.ReadString(dataStream);
                    extraArgs[j] = arg;
                }

                species.biomass       = int.Parse(extraArgs[0]);
                species.diet_type     = short.Parse(extraArgs[1]);
                species.trophic_level = float.Parse(extraArgs[2]);

                Dictionary <int, string> predatorList = species.predatorList;
                foreach (string predator_id in extraArgs[3].Split(new string[] { "," }, StringSplitOptions.None))
                {
                    if (predator_id != "")
                    {
                        predatorList.Add(int.Parse(predator_id), "");
                    }
                }

                Dictionary <int, string> preyList = species.preyList;
                foreach (string prey_id in extraArgs[4].Split(new string[] { "," }, StringSplitOptions.None))
                {
                    if (prey_id != "")
                    {
                        preyList.Add(int.Parse(prey_id), "");
                    }
                }

                species.categoryList = DataReader.ReadString(dataStream).Split(new string[] { ", " }, StringSplitOptions.None);

                speciesList.Add(species.species_id, species);

                //Constants.speciesList = speciesList;
            }
            //Debug.Log("Reached here!!----------" + Constants.speciesList.Count);
            response.speciesList = speciesList;

            return(response);
        }
        public static NetworkResponse Parse(MemoryStream dataStream)
        {
            ResponseSpeciesList response = new ResponseSpeciesList();

            Dictionary<int, SpeciesData> speciesList = new Dictionary<int, SpeciesData>();

            int size = DataReader.ReadShort(dataStream);
            //Debug.Log ("species list size is: " + size);
            for (int i = 0; i < size; i++) {
            SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
            species.level = DataReader.ReadShort(dataStream);
            //Debug.Log ("species list level is: " + species.level);
            species.name = DataReader.ReadString(dataStream);
            species.description = DataReader.ReadString(dataStream);

            short numArgs = DataReader.ReadShort(dataStream);
            string[] extraArgs = new string[numArgs];

            for (int j = 0; j < numArgs; j++) {
                string arg = DataReader.ReadString(dataStream);
                extraArgs[j] = arg;
            }

            species.biomass = int.Parse(extraArgs[0]);
            species.diet_type = short.Parse(extraArgs[1]);
            species.trophic_level = float.Parse(extraArgs[2]);

            Dictionary<int, string> predatorList = species.predatorList;
            foreach (string predator_id in extraArgs[3].Split(new string[]{","}, StringSplitOptions.None)) {
                if (predator_id != "") {
                    predatorList.Add(int.Parse(predator_id), "");
                }
            }

            Dictionary<int, string> preyList = species.preyList;
            foreach (string prey_id in extraArgs[4].Split(new string[]{","}, StringSplitOptions.None)) {
                if (prey_id != "") {
                    preyList.Add(int.Parse(prey_id), "");
                }
            }

            species.categoryList = DataReader.ReadString(dataStream).Split(new string[]{", "}, StringSplitOptions.None);

            speciesList.Add(species.species_id, species);

            //Constants.speciesList = speciesList;
            }
            //Debug.Log("Reached here!!----------" + Constants.speciesList.Count);
            response.speciesList = speciesList;

            return response;
        }
Пример #5
0
        public Card(string name, Texture2D image, SpeciesData species, Rect rect, Color color)
        {
            this.name = name;
            this.image = image;
            this.species = species;
            this.rect = rect;
            this.color = color;

            cardTexture = Resources.Load<Texture2D>("card_bg");
            statTexture = Resources.Load<Texture2D>("chart_dot");
            font = Resources.Load<Font>("Fonts/" + "Chalkboard");

            frameTexture = Resources.Load<Texture2D>("card_highlight");

            float imageWidth = rect.width * 0.8f, imageHeight = rect.width * 0.5f;
            imageRect = new Rect((rect.width - imageWidth) / 2, 35, imageWidth, imageHeight);
            imgTexture = Functions.CreateTexture2D(Color.white);

            startPos.x = currentPos.x = rect.x;
            startPos.y = currentPos.y = rect.y;
        }
Пример #6
0
        public Card(string name, Texture2D image, SpeciesData species, Rect rect, Color color)
        {
            this.name    = name;
            this.image   = image;
            this.species = species;
            this.rect    = rect;
            this.color   = color;

            cardTexture = Resources.Load <Texture2D>("card_bg");
            statTexture = Resources.Load <Texture2D>("chart_dot");
            font        = Resources.Load <Font>("Fonts/" + "Chalkboard");

            frameTexture = Resources.Load <Texture2D>("card_highlight");

            float imageWidth = rect.width * 0.8f, imageHeight = rect.width * 0.5f;

            imageRect  = new Rect((rect.width - imageWidth) / 2, 35, imageWidth, imageHeight);
            imgTexture = Functions.CreateTexture2D(Color.white);

            startPos.x = currentPos.x = rect.x;
            startPos.y = currentPos.y = rect.y;
        }
Пример #7
0
        //public static Dictionary<string, SpeciesData> spNameUpperList = new Dictionary<string, SpeciesData>();
        public static void Initialize()
        {
            SqliteConnection con = new SqliteConnection("URI=file:" + Application.dataPath + "/Database/WoB_DB.db");
            con.Open();

            SqliteCommand cmd = new SqliteCommand(con);
            cmd.CommandText = "" +
            "SELECT *" +
            " FROM `species`";

            cmd.Prepare();
            cmd.ExecuteNonQuery();

            SqliteDataReader reader = cmd.ExecuteReader();

            while (reader.Read()) {
            int species_id = reader.GetInt32(0);

            SpeciesData species = new SpeciesData(species_id);
            species.name = reader.GetString(1);
            species.description = reader.GetString(2);
            species.biomass = reader.GetInt32(3);
            species.diet_type = reader.GetInt16(4);
            species.trophic_level = reader.GetFloat(5);
            species.level = reader.GetInt16(6);

            SqliteCommand subcmd = new SqliteCommand(con);
            subcmd.CommandText = "" +
                "SELECT `predator_id`" +
                " FROM `pp_relations`" +
                " WHERE `prey_id` = @species_id";
            subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

            subcmd.Prepare();
            subcmd.ExecuteNonQuery();
            SqliteDataReader subreader = subcmd.ExecuteReader();

            while (subreader.Read()) {
                int predator_id = subreader.GetInt32(0);

                if (!species.predatorList.ContainsKey(predator_id)) {
                    species.predatorList.Add(predator_id, "");
                }
            }

            subcmd = new SqliteCommand(con);
            subcmd.CommandText = "" +
                "SELECT `prey_id`" +
                " FROM `pp_relations`" +
                " WHERE `predator_id` = @species_id";
            subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

            subcmd.Prepare();
            subcmd.ExecuteNonQuery();
            subreader = subcmd.ExecuteReader();

            while (subreader.Read()) {
                int prey_id = subreader.GetInt32(0);

                if (!species.preyList.ContainsKey(prey_id)) {
                    species.preyList.Add(subreader.GetInt32(0), "");
                }
            }

            species.name = Functions.NormalizeSpeciesName (species.name);
            speciesList.Add(species.species_id, species);
            spNameList.Add(species.name, species);
            //spNameUpperList.Add(species.name.ToUpper (), species);
            }

            foreach (SpeciesData species in speciesList.Values) {
            foreach (int predator_id in new List<int>(species.predatorList.Keys)) {
                if (SpeciesTable.speciesList.ContainsKey(predator_id)) {
                    species.predatorList[predator_id] = SpeciesTable.speciesList[predator_id].name;
                } else {
                    species.predatorList.Remove(predator_id);
                }
            }

            foreach (int prey_id in new List<int>(species.preyList.Keys)) {
                if (SpeciesTable.speciesList.ContainsKey(prey_id)) {
                    species.preyList[prey_id] = SpeciesTable.speciesList[prey_id].name;
                } else {
                    species.preyList.Remove(prey_id);
                }
            }
            }

            reader.Close();
            con.Close();
        }
Пример #8
0
        public static void Update(Dictionary <int, SpeciesData> updateList)
        {
            SqliteConnection con = new SqliteConnection("URI=file:" + Application.dataPath + "/Database/WoB_DB.db");

            con.Open();

            SqliteCommand cmd = new SqliteCommand(con);

            cmd.CommandText = "" +
                              "DELETE FROM `pp_relations`" +
                              " WHERE `predator_id` > 0 OR `prey_id` > 0";

            cmd.Prepare();
            cmd.ExecuteNonQuery();

            foreach (KeyValuePair <int, SpeciesData> entry in updateList)
            {
                int         species_id = entry.Key;
                SpeciesData species    = entry.Value;

                if (speciesList.ContainsKey(species_id))           // If Exists, Delete Record
                {
                    cmd.CommandText = "" +
                                      "DELETE FROM `species`" +
                                      " WHERE `species_id` = @species_id";
                    cmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }

                cmd.CommandText = "" +
                                  "INSERT INTO `species` (`species_id`, `name`, `description`, `biomass`, `diet_type`, `trophic_level`, 'level')" +
                                  " VALUES (@species_id, @name, @description, @biomass, @diet_type, @trophic_level, @level)";
                cmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));
                cmd.Parameters.Add(new SqliteParameter("@name", species.name));
                cmd.Parameters.Add(new SqliteParameter("@description", species.description));
                cmd.Parameters.Add(new SqliteParameter("@biomass", species.biomass));
                cmd.Parameters.Add(new SqliteParameter("@diet_type", species.diet_type));
                cmd.Parameters.Add(new SqliteParameter("@trophic_level", species.trophic_level));
                cmd.Parameters.Add(new SqliteParameter("@level", species.level));

                cmd.Prepare();
                cmd.ExecuteNonQuery();

                foreach (int predator_id in species.predatorList.Keys)
                {
                    cmd.CommandText = "" +
                                      "INSERT INTO `pp_relations` (`predator_id`, `prey_id`)" +
                                      " VALUES (@predator_id, @prey_id)";
                    cmd.Parameters.Add(new SqliteParameter("@predator_id", predator_id));
                    cmd.Parameters.Add(new SqliteParameter("@prey_id", species.species_id));

                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }

                foreach (int prey_id in species.preyList.Keys)
                {
                    cmd.CommandText = "" +
                                      "INSERT INTO `pp_relations` (`predator_id`, `prey_id`)" +
                                      " VALUES (@predator_id, @prey_id)";
                    cmd.Parameters.Add(new SqliteParameter("@predator_id", species.species_id));
                    cmd.Parameters.Add(new SqliteParameter("@prey_id", prey_id));

                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
            }

            con.Close();
        }
Пример #9
0
        //public static Dictionary<string, SpeciesData> spNameUpperList = new Dictionary<string, SpeciesData>();

        public static void Initialize()
        {
            SqliteConnection con = new SqliteConnection("URI=file:" + Application.dataPath + "/Database/WoB_DB.db");

            con.Open();

            SqliteCommand cmd = new SqliteCommand(con);

            cmd.CommandText = "" +
                              "SELECT *" +
                              " FROM `species`";

            cmd.Prepare();
            cmd.ExecuteNonQuery();

            SqliteDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                int species_id = reader.GetInt32(0);

                SpeciesData species = new SpeciesData(species_id);
                species.name          = reader.GetString(1);
                species.description   = reader.GetString(2);
                species.biomass       = reader.GetInt32(3);
                species.diet_type     = reader.GetInt16(4);
                species.trophic_level = reader.GetFloat(5);
                species.level         = reader.GetInt16(6);

                SqliteCommand subcmd = new SqliteCommand(con);
                subcmd.CommandText = "" +
                                     "SELECT `predator_id`" +
                                     " FROM `pp_relations`" +
                                     " WHERE `prey_id` = @species_id";
                subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

                subcmd.Prepare();
                subcmd.ExecuteNonQuery();
                SqliteDataReader subreader = subcmd.ExecuteReader();

                while (subreader.Read())
                {
                    int predator_id = subreader.GetInt32(0);

                    if (!species.predatorList.ContainsKey(predator_id))
                    {
                        species.predatorList.Add(predator_id, "");
                    }
                }

                subcmd             = new SqliteCommand(con);
                subcmd.CommandText = "" +
                                     "SELECT `prey_id`" +
                                     " FROM `pp_relations`" +
                                     " WHERE `predator_id` = @species_id";
                subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

                subcmd.Prepare();
                subcmd.ExecuteNonQuery();
                subreader = subcmd.ExecuteReader();

                while (subreader.Read())
                {
                    int prey_id = subreader.GetInt32(0);

                    if (!species.preyList.ContainsKey(prey_id))
                    {
                        species.preyList.Add(subreader.GetInt32(0), "");
                    }
                }

                species.name = Functions.NormalizeSpeciesName(species.name);
                speciesList.Add(species.species_id, species);
                spNameList.Add(species.name, species);
                //spNameUpperList.Add(species.name.ToUpper (), species);
            }

            foreach (SpeciesData species in speciesList.Values)
            {
                foreach (int predator_id in new List <int>(species.predatorList.Keys))
                {
                    if (SpeciesTable.speciesList.ContainsKey(predator_id))
                    {
                        species.predatorList[predator_id] = SpeciesTable.speciesList[predator_id].name;
                    }
                    else
                    {
                        species.predatorList.Remove(predator_id);
                    }
                }

                foreach (int prey_id in new List <int>(species.preyList.Keys))
                {
                    if (SpeciesTable.speciesList.ContainsKey(prey_id))
                    {
                        species.preyList[prey_id] = SpeciesTable.speciesList[prey_id].name;
                    }
                    else
                    {
                        species.preyList.Remove(prey_id);
                    }
                }
            }

            reader.Close();
            con.Close();
        }
Пример #10
0
        public void SetCard(Card card)
        {
            if (cardList.Count > 0 && card != cardList[0])
            {
                predatorList.Clear();
                preyList.Clear();
            }

            if (cardList.Contains(card))
            {
                int index = cardList.IndexOf(card);
                cardList.RemoveRange(0, index);
            }
            else
            {
                if (cardList.Count > 5)
                {
                    cardList.RemoveAt(cardList.Count - 2);
                }

                cardList.Insert(0, card);
            }

            card.x = (width - card.width) / 2;
            card.y = (height - card.height) / 2;

            for (int i = cardList.Count - 1; i >= 0; i--)
            {
                float y = (height - card.height) / 2 - i * card.height * 0.15f;

                if (cardList.Count > 1 && i == cardList.Count - 1)
                {
                    y -= card.height * 0.15f;
                }

                cardList[i].Translate(cardList[i].x, y, 1.2f);
            }

            List <Card> tempList = new List <Card>();
            GameState   gs       = GameObject.Find("Global Object").GetComponent <GameState> ();

            foreach (int species_id in card.species.predatorList.Keys)
            {
                SpeciesData species = SpeciesTable.speciesList[species_id];
                //for converge game, ignore predators not currently in ecosystem
                if (mode == Constants.MODE_CONVERGE_GAME && !gs.speciesList.ContainsKey(species_id))
                {
                    continue;
                }

                string    name  = manager.MatchSeriesLabel(species.name);
                Texture2D image = Resources.Load <Texture2D>(Constants.IMAGE_RESOURCES_PATH + species.name);
                Card      temp  = new Card(
                    species.name,
                    image,
                    species,
                    new Rect(card.x, card.y, 160, 200),
                    name == null ? Color.red : manager.seriesColors [name]
                    );

                tempList.Add(temp);
            }

            tempList.Sort(SortByName);
            CreateLayout(tempList, predatorList, -1);

            tempList = new List <Card>();

            foreach (int species_id in card.species.preyList.Keys)
            {
                SpeciesData species = SpeciesTable.speciesList[species_id];
                //for converge game, ignore prey not currently in ecosystem
                if (mode == Constants.MODE_CONVERGE_GAME && !gs.speciesList.ContainsKey(species_id))
                {
                    continue;
                }

                string    name  = manager.MatchSeriesLabel(species.name);
                Texture2D image = Resources.Load <Texture2D>(Constants.IMAGE_RESOURCES_PATH + species.name);
                Card      temp  = new Card(
                    species.name,
                    image,
                    species,
                    new Rect(card.x, card.y, 160, 200),
                    name == null ? Color.green : manager.seriesColors [name]
                    );

                tempList.Add(temp);
            }

            tempList.Sort(SortByName);
            CreateLayout(tempList, preyList, 1);

            Expand();
        }
Пример #11
0
 public Card(string name, Texture2D image, SpeciesData species, Rect rect)
     : this(name, image, species, rect, Color.black)
 {
 }
Пример #12
0
 public Card(string name, Texture2D image, SpeciesData species, Rect rect) : this(name, image, species, rect, Color.black)
 {
 }