Ejemplo n.º 1
0
        public async Task Update()
        {
            if (lamp == null)
            {
                return;
            }

            if (lamp.consumer == null)
            {
                return;
            }

            LampStateGetHueResult hueResult = await this.lamp.consumer.GetHueAsync();

            LampStateGetSaturationResult saturationResult = await this.lamp.consumer.GetSaturationAsync();

            LampStateGetBrightnessResult brigtnessResult = await this.lamp.consumer.GetBrightnessAsync();

            LampStateGetColorTempResult tempResult = await this.lamp.consumer.GetColorTempAsync();

            LampStateGetOnOffResult onOffResult = await this.lamp.consumer.GetOnOffAsync();

            var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                this.hue = HexHelper.ConvertHue(hueResult.Hue);
                this.OnPropertyChanged(HUE_PROPERTY);

                this.saturation = (byte)HexHelper.hexToPercent(saturationResult.Saturation);

                this.onOffState = onOffResult.OnOff;
                this.OnPropertyChanged(ON_OFF_PROPERTY);

                var brightness = (byte)HexHelper.hexToPercent(brigtnessResult.Brightness);
                if (this.brightness != brightness)
                {
                    this.brightness = brightness;
                    this.OnPropertyChanged(BRIGHT_PROPERTY);
                }
                this.temperature = tempResult.ColorTemp;
                this.OnPropertyChanged(TEMP_PROPERTY);

                this.DisplayColour = new SolidColorBrush(ColourHelper.ColorFromHSV(this.Hue, this.saturation, this.brightness));
            });
        }
Ejemplo n.º 2
0
        public static void LoadCountries()
        {
            CountryTagLookup = new Dictionary <string, Country>();

            foreach (string filename in Directory.GetFiles(ModFileReader.ModFile.CommonFolder + "country_tags/"))
            {
                Console.WriteLine(filename);
                ReadCountryTagsFile(filename, true);
            }

            string countryTagsFile = BaseGameReader.BaseGame.CommonFolder + "country_tags\\00_countries.txt";

            ReadCountryTagsFile(countryTagsFile, false);

            StreamReader sr;

            if (File.Exists(ModFileReader.ModFile.CommonFolder + "countries\\colors.txt"))
            {
                sr = new StreamReader(ModFileReader.ModFile.CommonFolder + "countries\\colors.txt");
            }
            else
            {
                sr = new StreamReader(BaseGameReader.BaseGame.CommonFolder + "countries\\colors.txt");
            }

            string fullText = sr.ReadToEnd();

            string[] lines = fullText.Split('\n');
            foreach (string line in lines)
            {
                string cleanLine = (line.IndexOf("#") >= 0 ? line.Remove(line.IndexOf("#")) : line).Trim();
                if (cleanLine.Contains("=") && !cleanLine.StartsWith("color"))
                {
                    string tag                = cleanLine.Split('=')[0].Trim();
                    int    locationOfTag      = fullText.IndexOf(tag);
                    string contentsOfBrackets = TextParser.GetContentsOfBrackets(fullText, tag).Trim();
                    //Console.WriteLine(tag+": "+contentsOfBrackets);
                    string colorText = contentsOfBrackets.Split('\n')[0].Split('=')[1].Trim();
                    string colorVals = colorText.Remove(colorText.IndexOf('}'));
                    colorVals = colorVals.Substring(colorVals.IndexOf('{') + 1).Trim();
                    string[] splitVals = colorVals.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    //Console.WriteLine(tag+": "+ colorText);
                    if (colorText.ToUpper().Contains("RGB") && CountryTagLookup.ContainsKey(tag))
                    {
                        Color countryColour = Color.FromArgb(
                            int.Parse(splitVals[0].Trim()),
                            int.Parse(splitVals[1].Trim()),
                            int.Parse(splitVals[2].Trim()));
                        CountryIndexer.CountryTagLookup[tag].MainColour = countryColour;
                    }
                    else if (colorText.ToUpper().Contains("HSV") && CountryTagLookup.ContainsKey(tag))
                    {
                        Color countryColour = ColourHelper.ColorFromHSV(
                            Convert.ToDouble(splitVals[0].Trim()),
                            Convert.ToDouble(splitVals[1].Trim()),
                            Convert.ToDouble(splitVals[2].Trim()));
                        CountryIndexer.CountryTagLookup[tag].MainColour = countryColour;
                    }
                }
            }
            sr.Close();
        }