Modify scripts to seed data

This commit is contained in:
Karol Górzyński 2021-01-03 16:28:13 +01:00
parent 5206a700f8
commit 6f7b71ad70
3 changed files with 359 additions and 0 deletions

View File

@ -85,6 +85,19 @@ namespace SessionCompanion.Database
}
return otherEquipment;
}
protected IEnumerable<Spell> SeedSpell()
{
const string file = "../SessionCompanion.Database/JsonData/spells.json";
List<Spell> spells = new List<Spell>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jspells = JArray.Parse(json);
foreach (dynamic item in jspells)
spells.Add(SeedFromJsons.SingleSpellSeeder(item));
}
return spells;
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
@ -102,6 +115,9 @@ namespace SessionCompanion.Database
builder.Entity<CharacterWeapon>().HasData(SeedData.SeedCharacterWeapon());
builder.Entity<CharacterArmor>().HasData(SeedData.SeedCharacterArmor());
builder.Entity<CharacterOtherEquipment>().HasData(SeedData.SeedCharacterOtherEquipment());
builder.Entity<Spell>().HasData(SeedSpell());
builder.Entity<CharacterSpell>().HasData(SeedData.SeedCharacterSpell());
builder.Entity<CharacterSpellSlots>().HasData(SeedData.SeedCharacterSpellSlot());
}
}
}

View File

@ -388,5 +388,148 @@ namespace SessionCompanion.Database
};
return characterOtherEquipment;
}
static public List<CharacterSpell> SeedCharacterSpell()
{
List<CharacterSpell> characterSpells = new List<CharacterSpell>
{
new CharacterSpell
{
Id = 1,
CharacterId = 1,
SpellId = 2
},
new CharacterSpell
{
Id = 2,
CharacterId = 1,
SpellId = 55
},
new CharacterSpell
{
Id = 3,
CharacterId = 1,
SpellId = 17
},
new CharacterSpell
{
Id = 4,
CharacterId = 1,
SpellId = 78
},
new CharacterSpell
{
Id = 5,
CharacterId = 2,
SpellId = 43
},
new CharacterSpell
{
Id = 6,
CharacterId = 2,
SpellId = 154
},
new CharacterSpell
{
Id = 7,
CharacterId = 2,
SpellId = 123
},
new CharacterSpell
{
Id = 8,
CharacterId = 2,
SpellId = 67
},
new CharacterSpell
{
Id = 9,
CharacterId = 3,
SpellId = 90
},
new CharacterSpell
{
Id = 10,
CharacterId = 2,
SpellId = 44
},
};
return characterSpells;
}
static public List<CharacterSpellSlots> SeedCharacterSpellSlot()
{
List<CharacterSpellSlots> characterSpellSlots = new List<CharacterSpellSlots>
{
new CharacterSpellSlots
{
Id = 1,
CharacterId = 1,
FirstLevelSlots = 4,
FirstLevelSlotsUsed = 0,
SecondLevelSlots = 5,
SecondLevelSlotsUsed = 4,
ThirdLevelSlots = 2,
ThirdLevelSlotsUsed = 1,
FourthLevelSlots = 3,
FourthLevelSlotsUsed = 1,
FifthLevelSlots = 1,
FifthLevelSlotsUsed = 0,
SixthLevelSlots = 0,
SixthLevelSlotsUsed = 0,
SeventhLevelSlots = 0,
SeventhLevelSlotsUsed = 0,
EightLevelSlots = 0,
EightLevelSlotsUsed = 0,
NinthLevelSlots = 0,
NinthLevelSlotsUsed = 0
},
new CharacterSpellSlots
{
Id = 2,
CharacterId = 2,
FirstLevelSlots = 6,
FirstLevelSlotsUsed = 2,
SecondLevelSlots = 3,
SecondLevelSlotsUsed = 2,
ThirdLevelSlots = 3,
ThirdLevelSlotsUsed = 1,
FourthLevelSlots = 2,
FourthLevelSlotsUsed = 2,
FifthLevelSlots = 1,
FifthLevelSlotsUsed = 1,
SixthLevelSlots = 0,
SixthLevelSlotsUsed = 0,
SeventhLevelSlots = 0,
SeventhLevelSlotsUsed = 0,
EightLevelSlots = 0,
EightLevelSlotsUsed = 0,
NinthLevelSlots = 0,
NinthLevelSlotsUsed = 0
},
new CharacterSpellSlots
{
Id = 3,
CharacterId = 3,
FirstLevelSlots = 2,
FirstLevelSlotsUsed = 0,
SecondLevelSlots = 3,
SecondLevelSlotsUsed = 2,
ThirdLevelSlots = 2,
ThirdLevelSlotsUsed = 0,
FourthLevelSlots = 1,
FourthLevelSlotsUsed = 1,
FifthLevelSlots = 1,
FifthLevelSlotsUsed = 0,
SixthLevelSlots = 0,
SixthLevelSlotsUsed = 0,
SeventhLevelSlots = 0,
SeventhLevelSlotsUsed = 0,
EightLevelSlots = 0,
EightLevelSlotsUsed = 0,
NinthLevelSlots = 0,
NinthLevelSlotsUsed = 0
}
};
return characterSpellSlots;
}
}
}

View File

@ -120,5 +120,205 @@ namespace SessionCompanion.Database
return otherEq;
}
static public Spell SingleSpellSeeder(dynamic item)
{
Spell spell = new Spell();
// Id
spell.Id = item.index;
// Name
spell.Name = item.name;
// Description
foreach (dynamic des in item.desc)
spell.Description += des + ";";
if (spell.Description != null)
spell.Description = spell.Description.Remove(spell.Description.Length - 1);
// HigherLevel
if (item.higher_level != null)
{
foreach (dynamic hl in item.higher_level)
spell.HigherLevel += (string)hl + ";";
if (spell.HigherLevel != null)
spell.HigherLevel = spell.HigherLevel.Remove(spell.HigherLevel.Length - 1);
}
// Range
switch ((string)item.range)
{
case "90 feet":
spell.Range = SpellsEnums.Ranges.Feet_90;
break;
case "60 feet":
spell.Range = SpellsEnums.Ranges.Feet_60;
break;
case "30 feet":
spell.Range = SpellsEnums.Ranges.Feet_30;
break;
case "10 feet":
spell.Range = SpellsEnums.Ranges.Feet_10;
break;
case "120 feet":
spell.Range = SpellsEnums.Ranges.Feet_120;
break;
case "150 feet":
spell.Range = SpellsEnums.Ranges.Feet_150;
break;
case "1 mile":
spell.Range = SpellsEnums.Ranges.Miles_1;
break;
case "300 feet":
spell.Range = SpellsEnums.Ranges.Feet_300;
break;
case "500 feet":
spell.Range = SpellsEnums.Ranges.Feet_500;
break;
case "100 feet":
spell.Range = SpellsEnums.Ranges.Feet_100;
break;
case "500 miles":
spell.Range = SpellsEnums.Ranges.Miles_500;
break;
case "5 feet":
spell.Range = SpellsEnums.Ranges.Feet_5;
break;
default:
if (Enum.TryParse<SpellsEnums.Ranges>((string)item.range, true, out SpellsEnums.Ranges RangeType))
if (Enum.IsDefined(typeof(SpellsEnums.Ranges), RangeType))
spell.Range = RangeType;
break;
}
// Components
foreach (dynamic component in item.components)
{
if (Enum.TryParse<SpellsEnums.Components>((string)component, true, out SpellsEnums.Components ComponentType))
if (Enum.IsDefined(typeof(SpellsEnums.Components), ComponentType))
spell.Components += ComponentType + ";";
}
if (spell.Components != null)
spell.Components = spell.Components.Remove(spell.Components.Length - 1);
if (item.material != null)
spell.Material = item.material;
if ((string)item.ritual == "no")
spell.Ritual = false;
else
spell.Ritual = true;
// Duration
switch ((string)item.duration)
{
case "8 hours":
spell.Duration = SpellsEnums.Durations.Hours_8;
break;
case "1 hour":
spell.Duration = SpellsEnums.Durations.Hours_1;
break;
case "24 hours":
spell.Duration = SpellsEnums.Durations.Hours_24;
break;
case "1 minute":
spell.Duration = SpellsEnums.Durations.Minutes_1;
break;
case "10 days":
spell.Duration = SpellsEnums.Durations.Days_10;
break;
case "10 minutes":
spell.Duration = SpellsEnums.Durations.Minutes_10;
break;
case "1 round":
spell.Duration = SpellsEnums.Durations.Round_1;
break;
case "7 days":
spell.Duration = SpellsEnums.Durations.Days_7;
break;
case "30 days":
spell.Duration = SpellsEnums.Durations.Days_30;
break;
case "2 hours":
spell.Duration = SpellsEnums.Durations.Hours_2;
break;
case "Until dispelled":
spell.Duration = SpellsEnums.Durations.Until_dispelled;
break;
default:
if (Enum.TryParse<SpellsEnums.Durations>((string)item.duration, true, out SpellsEnums.Durations DurationType))
if (Enum.IsDefined(typeof(SpellsEnums.Durations), DurationType))
spell.Duration = DurationType;
break;
}
// Concentration
if ((string)item.concentration == "no")
spell.Concentration = false;
else
spell.Concentration = true;
// CastingTime
switch ((string)item.casting_time)
{
case "1 action":
spell.CastingTime = SpellsEnums.CastingTimes.Action_1;
break;
case "1 minute":
spell.CastingTime = SpellsEnums.CastingTimes.Minutes_1;
break;
case "1 hour":
spell.CastingTime = SpellsEnums.CastingTimes.Hours_1;
break;
case "8 hours":
spell.CastingTime = SpellsEnums.CastingTimes.Hours_8;
break;
case "1 bonus action":
spell.CastingTime = SpellsEnums.CastingTimes.Bonus_Action_1;
break;
case "10 minutes":
spell.CastingTime = SpellsEnums.CastingTimes.Minutes_10;
break;
case "1 reaction":
spell.CastingTime = SpellsEnums.CastingTimes.Reaction_1;
break;
case "24 hours":
spell.CastingTime = SpellsEnums.CastingTimes.Hours_24;
break;
case "12 hours":
spell.CastingTime = SpellsEnums.CastingTimes.Hours_12;
break;
}
// Level
spell.Level = (int)item.level;
// School
if (Enum.TryParse<SpellsEnums.Schools>((string)item.school.name, true, out SpellsEnums.Schools SchoolType))
if (Enum.IsDefined(typeof(SpellsEnums.Schools), SchoolType))
spell.School = SchoolType;
// Classes
foreach (dynamic c in item.classes)
{
if (Enum.TryParse<SpellsEnums.Classes>((string)c.name, true, out SpellsEnums.Classes ClassType))
if (Enum.IsDefined(typeof(SpellsEnums.Classes), ClassType))
spell.Classes += ClassType + ";";
}
if (spell.Classes != null)
spell.Classes = spell.Classes.Remove(spell.Classes.Length - 1);
// Subclasses
foreach (dynamic s in item.subclasses)
{
if (Enum.TryParse<SpellsEnums.Subclass>((string)s.name, true, out SpellsEnums.Subclass SubClassType))
if (Enum.IsDefined(typeof(SpellsEnums.Subclass), SubClassType))
spell.Subclasses += SubClassType + ";";
}
if (spell.Subclasses != null)
spell.Subclasses = spell.Subclasses.Remove(spell.Subclasses.Length - 1);
return spell;
}
}
}