public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var category = new CustomSkillCategory(); var jobject = JObject.Load(reader); //get category name var catProp = jobject.Properties().Where(p => p.Name == "Category").FirstOrDefault(); if (catProp != null) { category.Name = (string)catProp.Value; } //get skills var skillsProp = jobject.Properties().Where(p => p.Name == "Skills").FirstOrDefault(); if (skillsProp != null) { //skillsProp.Value var skills = JsonConvert.DeserializeObject <List <CustomSkillDefinition> >(skillsProp.Value.ToString()); foreach (var skill in skills) { category.Add(skill.Name, skill); } } return(category); }
private void SkillListSubCommand(TSPlayer player, string categoryName = null) { CustomSkillCategory category = null; if (!string.IsNullOrWhiteSpace(categoryName)) { category = CustomSkillDefinitionLoader.TryGetCategory(categoryName); if (category != null) { //const int itemsPerPage = 4; //var lines = category.Select(d => d.Value.Name).ToList(); //var pageCount = lines.PageCount(itemsPerPage); //if (pageNumber < 1 || pageNumber > pageCount) // pageNumber = 1; //var page = lines.GetPage(pageNumber - 1, itemsPerPage);//we display based off of 1 //player.SendInfoMessage($"Page #{pageNumber} of {pageCount}."); //foreach (var l in page) //{ // player.SendInfoMessage(l); //} //player.SendMessage("Use /bank bal <page> or /bank bal <currency> to see more.", Color.Green); //player.SendInfoMessage("Use /bank bal <page> or /bank bal <currency> to see more."); foreach (var kvp in category) { player.SendInfoMessage(kvp.Value.Name); } } else { player.SendErrorMessage($"No such category as '{categoryName}'."); return; } } else { category = CustomSkillDefinitionLoader.TryGetCategory(null); foreach (var def in category.Values) { player.SendInfoMessage(def.Name); } } }
private bool GetCategoryAndSkill(TSPlayer player, string skillName, string categoryName, out CustomSkillCategory category, out CustomSkillDefinition skillDef) { category = null; skillDef = null; if (string.IsNullOrWhiteSpace(skillName)) { player.SendErrorMessage("Expected skill name."); player.SendSyntaxMessage(SyntaxSkillSub); return(false); } if (!string.IsNullOrWhiteSpace(categoryName)) { category = CustomSkillDefinitionLoader.TryGetCategory(categoryName); } else { category = CustomSkillDefinitionLoader.TryGetCategory(); //get default "uncategorized" category... } if (category == null) { player.SendErrorMessage($"No such category '{categoryName}'."); return(false); } category.TryGetValue(skillName, out skillDef); if (skillDef == null) { player.SendErrorMessage($"No such skill as '{skillName}'."); return(false); } return(true); }