private void btnImport_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.Title  = "Import Data from File";
            ofd.Filter = "Pathfinder Character Sheet|*.json|All Files|*.*";

            if (ofd.ShowDialog() ?? false == true)
            {
                string         filename = ofd.FileName;
                SentinelsSheet ps       = SentinelsSheet.LoadJsonFile(filename);
                LoadUserData(ps.Player ?? new UserData(true));
            }
        }
Example #2
0
        public static SentinelsSheet LoadJsonText(string text)
        {
            JsonSerializerSettings sss = new JsonSerializerSettings();

            sss.DefaultValueHandling = DefaultValueHandling.Ignore;
            sss.NullValueHandling    = NullValueHandling.Ignore;
            sss.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            sss.Error += (object?sender, Newtonsoft.Json.Serialization.ErrorEventArgs e) => ErrorHandler(sender, e, "");

            SentinelsSheet ss = JsonConvert.DeserializeObject <SentinelsSheet>(text, sss) !;

            ss.SetupSheet();
            return(ss);
        }
Example #3
0
        public static SentinelsSheet CreateNewSheet(string name, int level, int pointsPerLevel = 10, int level0Points = 0, UserData?userdata = null)
        {
            string newjson = "{\"_id\":\"-1\"," +
                             "\"user\":{\"provider\":\"local\",\"id\":\"null\",\"displayName\":\"-\"," +
                             "\"username\":\"\",\"profileUrl\":\"\",\"emails\":[]}," +
                             "\"name\":\"" + name + "\",\"modified\":\"" + string.Concat(DateTime.UtcNow.ToString("s"), ".000Z") +
                             "\",\"charLevel\":" + level + ",\"ecl\":" + level + ",\"pointsPerLevel\":" + level + ",\"pointsLevel0\":" + level + "," +
                             "\"defenseActions\":2 }";

            SentinelsSheet ps = LoadJsonText(newjson);

            if (userdata != null)
            {
                ps.Player = userdata;
            }

            return(ps);
        }
Example #4
0
 public static SentinelsSheet LoadJsonFile(string filename)
 {
     using (StreamReader file = File.OpenText(filename))
     {
         try
         {
             JsonSerializer serializer = new JsonSerializer();
             serializer.DefaultValueHandling = DefaultValueHandling.Ignore;
             serializer.NullValueHandling    = NullValueHandling.Ignore;
             serializer.ContractResolver     = new CamelCasePropertyNamesContractResolver();
             serializer.Error += (object?sender, Newtonsoft.Json.Serialization.ErrorEventArgs e) => ErrorHandler(sender, e, filename);
             SentinelsSheet ss = (SentinelsSheet)serializer.Deserialize(file, typeof(SentinelsSheet)) !;
             ss.SetupSheet();
             return(ss);
         }
         catch (JsonReaderException e)
         {
             throw new InvalidDataException("This file does not match the format for JSON. Check if it isn't corrupted by opening it in Notepad or another text editor.", e);
         }
     }
 }
Example #5
0
        private void btnImportData_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.Title  = "Import Data from File";
            ofd.Filter = "Pathfinder Character Sheet|*.json|All Files|*.*";

            if (ofd.ShowDialog() ?? false == true)
            {
                string         filename = ofd.FileName;
                SentinelsSheet ps       = SentinelsSheet.LoadJsonFile(filename);
                ud = ps.Player ?? new UserData(true);
                if (!string.IsNullOrEmpty(ud.DisplayName))
                {
                    txtPlayerName.Text = ud.DisplayName;
                }
                else
                {
                    txtPlayerName.Text = "(not set)";
                }
            }
        }
Example #6
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCharacterName.Text))
            {
                MessageDialog md = new MessageDialog(ColorScheme);
                md.Image   = MessageDialogImage.Error;
                md.Message = "Please enter a character name before continuing.";
                md.Title   = "Missing Data";
                md.Owner   = this;
                md.ShowDialog();
                return;
            }

            // Create Sentinels sheet
            // Including ability scores
            // (I also set up the RawAbilities property despite it not really being used, in case it may become an issue later on)
            Sheet = SentinelsSheet.CreateNewSheet(txtCharacterName.Text, nudLevel.Value, nudCpLevel.Value, nudCpStart.Value, ud);

            Sheet.Strength   = txtStr.Value;
            Sheet.Perception = txtPer.Value;
            Sheet.Endurance  = txtEnd.Value;
            Sheet.Charisma   = txtCha.Value;
            Sheet.Intellect  = txtInt.Value;
            Sheet.Agility    = txtAgi.Value;
            Sheet.Luck       = txtLuk.Value;

            Sheet.PotStrength   = txtStrp.Value;
            Sheet.PotPerception = txtPerp.Value;
            Sheet.PotEndurance  = txtEndp.Value;
            Sheet.PotCharisma   = txtChap.Value;
            Sheet.PotIntellect  = txtIntp.Value;
            Sheet.PotAgility    = txtAgip.Value;
            Sheet.PotLuck       = txtLukp.Value;

            Dictionary <string, string> abilities = new Dictionary <string, string>
            {
                { "str", txtStr.Value.ToString() },
                { "per", txtPer.Value.ToString() },
                { "end", txtEnd.Value.ToString() },
                { "cha", txtCha.Value.ToString() },
                { "int", txtInt.Value.ToString() },
                { "agi", txtAgi.Value.ToString() },
                { "luk", txtLuk.Value.ToString() }
            };

            Sheet.RawAbilities = abilities;
            Dictionary <string, string> potentials = new Dictionary <string, string>
            {
                { "str", txtStrp.Value.ToString() },
                { "per", txtPerp.Value.ToString() },
                { "end", txtEndp.Value.ToString() },
                { "cha", txtChap.Value.ToString() },
                { "int", txtIntp.Value.ToString() },
                { "agi", txtAgip.Value.ToString() },
                { "luk", txtLukp.Value.ToString() }
            };

            Sheet.RawPotential  = potentials;
            Sheet.PowerStatName = powerStat;

            Sheet.SkillList = cbbSkillList.SelectedIndex switch
            {
                0 => "standard",
                1 => "simplified",
                2 => "pathfinder",
                3 => "none",
                _ => "standard" // TODO: add handling for custom skill list files
            };

            if (!string.IsNullOrEmpty(FileLocation))
            {
                Sheet.SaveJsonFile(FileLocation, App.Settings.IndentJsonData);
            }

            DialogResult = true;
            Close();
        }