mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 06:26:02 +00:00
Killer code ^^
This commit is contained in:
parent
e845cf7c7f
commit
28e9aa258f
2 changed files with 131 additions and 40 deletions
|
|
@ -3,7 +3,6 @@ import 'package:aidedejeu_flutter/models/filters.dart';
|
|||
class Item {
|
||||
String id;
|
||||
String rootId;
|
||||
String newId;
|
||||
String parentLink;
|
||||
String name;
|
||||
String normalizedName;
|
||||
|
|
@ -21,7 +20,6 @@ class Item {
|
|||
Item(Map<String, dynamic> map) {
|
||||
this.id = map["Id"];
|
||||
this.rootId = map["RootId"];
|
||||
this.newId = map["NewId"];
|
||||
this.name = map["Name"];
|
||||
this.alias = map["AltName"];
|
||||
this.aliasText = map["AltNameText"];
|
||||
|
|
@ -57,8 +55,7 @@ class MonsterItem extends Item {
|
|||
String challenge;
|
||||
int xp;
|
||||
|
||||
MonsterItem(Map<String, dynamic> map)
|
||||
: super(map) {
|
||||
MonsterItem(Map<String, dynamic> map) : super(map) {
|
||||
this.family = map["Family"];
|
||||
this.type = map["Type"];
|
||||
this.size = map["Size"];
|
||||
|
|
@ -88,17 +85,13 @@ class MonsterItem extends Item {
|
|||
}
|
||||
|
||||
class Items extends Item {
|
||||
|
||||
Items(Map<String, dynamic> map)
|
||||
: super(map) {
|
||||
}
|
||||
Items(Map<String, dynamic> map) : super(map) {}
|
||||
}
|
||||
|
||||
abstract class FilteredItems extends Items {
|
||||
String family;
|
||||
|
||||
FilteredItems(Map<String, dynamic> map)
|
||||
: super(map) {
|
||||
FilteredItems(Map<String, dynamic> map) : super(map) {
|
||||
this.family = map["Family"];
|
||||
}
|
||||
|
||||
|
|
@ -112,33 +105,95 @@ class MonsterItems extends FilteredItems {
|
|||
Filter sources;
|
||||
Filter terrains;
|
||||
|
||||
MonsterItems(Map<String, dynamic> map)
|
||||
: super(map) {
|
||||
this.types = Filter(name: "Type", type: FilterType.Choices, values: map["Types"].toString().split("|"));
|
||||
this.challenges = Filter(name: "Challenge", type: FilterType.Range, values: map["Challenges"].toString().split("|"));
|
||||
this.sizes = Filter(name: "Size", type: FilterType.Range, values: map["Sizes"].toString().split("|"));;
|
||||
this.sources = Filter(name: "Source", type: FilterType.Choices, values: map["Sources"].toString().split("|"));
|
||||
this.terrains = Filter(name: "Terrain", type: FilterType.Choices, values: map["Terrains"].toString().split("|"));
|
||||
MonsterItems(Map<String, dynamic> map) : super(map) {
|
||||
this.types = Filter(
|
||||
name: "Type",
|
||||
type: FilterType.Choices,
|
||||
values: map["Types"].toString().split("|"));
|
||||
this.challenges = Filter(
|
||||
name: "Challenge",
|
||||
type: FilterType.Range,
|
||||
values: map["Challenges"].toString().split("|"));
|
||||
this.sizes = Filter(
|
||||
name: "Size",
|
||||
type: FilterType.Range,
|
||||
values: map["Sizes"].toString().split("|"));
|
||||
;
|
||||
this.sources = Filter(
|
||||
name: "Source",
|
||||
type: FilterType.Choices,
|
||||
values: map["Sources"].toString().split("|"));
|
||||
this.terrains = Filter(
|
||||
name: "Terrain",
|
||||
type: FilterType.Choices,
|
||||
values: map["Terrains"].toString().split("|"));
|
||||
}
|
||||
|
||||
List<Filter> toFilterList() => {
|
||||
types,
|
||||
challenges,
|
||||
sizes,
|
||||
sources,
|
||||
terrains,
|
||||
}.toList();
|
||||
|
||||
types,
|
||||
challenges,
|
||||
sizes,
|
||||
sources,
|
||||
terrains,
|
||||
}.toList();
|
||||
}
|
||||
|
||||
class RaceItem extends Item {
|
||||
RaceItem(Map<String, dynamic> map) : super(map);
|
||||
String fullName;
|
||||
bool hasSubRaces;
|
||||
String strengthBonus;
|
||||
String dexterityBonus;
|
||||
String constitutionBonus;
|
||||
String intelligenceBonus;
|
||||
String wisdomBonus;
|
||||
String charismaBonus;
|
||||
String dispatchedBonus;
|
||||
String maxDispatchedStrengthBonus;
|
||||
String maxDispatchedDexterityBonus;
|
||||
String maxDispatchedConstitutionBonus;
|
||||
String maxDispatchedIntelligenceBonus;
|
||||
String maxDispatchedWisdomBonus;
|
||||
String maxDispatchedCharismaBonus;
|
||||
String abilityScoreIncrease;
|
||||
String age;
|
||||
String alignment;
|
||||
String size;
|
||||
String speed;
|
||||
String darkvision;
|
||||
String languages;
|
||||
|
||||
RaceItem(Map<String, dynamic> map) : super(map) {
|
||||
this.fullName = map["FullName"];
|
||||
this.hasSubRaces = map["HasSubRaces"] == "true";
|
||||
this.strengthBonus = map["StrengthBonus"];
|
||||
this.dexterityBonus = map["DexterityBonus"];
|
||||
this.constitutionBonus = map["ConstitutionBonus"];
|
||||
this.intelligenceBonus = map["IntelligenceBonus"];
|
||||
this.wisdomBonus = map["WisdomBonus"];
|
||||
this.charismaBonus = map["CharismaBonus"];
|
||||
this.dispatchedBonus = map["DispatchedBonus"];
|
||||
this.maxDispatchedStrengthBonus = map["MaxDispatchedStrengthBonus"];
|
||||
this.maxDispatchedDexterityBonus = map["MaxDispatchedDexterityBonus"];
|
||||
this.maxDispatchedConstitutionBonus = map["MaxDispatchedConstitutionBonus"];
|
||||
this.maxDispatchedIntelligenceBonus = map["MaxDispatchedIntelligenceBonus"];
|
||||
this.maxDispatchedWisdomBonus = map["MaxDispatchedWisdomBonus"];
|
||||
this.maxDispatchedCharismaBonus = map["MaxDispatchedCharismaBonus"];
|
||||
this.abilityScoreIncrease = map["AbilityScoreIncrease"];
|
||||
this.age = map["Age"];
|
||||
this.alignment = map["Alignment"];
|
||||
this.size = map["Size"];
|
||||
this.speed = map["Speed"];
|
||||
this.darkvision = map["Darkvision"];
|
||||
this.languages = map["Languages"];
|
||||
}
|
||||
}
|
||||
|
||||
class SubRaceItem extends RaceItem {
|
||||
SubRaceItem(Map<String, dynamic> map) : super(map);
|
||||
String parentRaceId;
|
||||
|
||||
SubRaceItem(Map<String, dynamic> map) : super(map) {
|
||||
this.parentRaceId = map["ParentRaceId"];
|
||||
}
|
||||
}
|
||||
|
||||
class RaceItems extends FilteredItems {
|
||||
|
|
@ -148,16 +203,20 @@ class RaceItems extends FilteredItems {
|
|||
List<Filter> toFilterList() {
|
||||
return [].toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item itemFromMap(Map<String, dynamic> map) {
|
||||
switch(map["ItemType"]) {
|
||||
case "RaceItem": return RaceItem(map);
|
||||
case "SubRaceItem": return SubRaceItem(map);
|
||||
case "RaceItems": return RaceItems(map);
|
||||
case "MonsterItem": return MonsterItem(map);
|
||||
case "MonsterItems": return MonsterItems(map);
|
||||
switch (map["ItemType"]) {
|
||||
case "RaceItem":
|
||||
return RaceItem(map);
|
||||
case "SubRaceItem":
|
||||
return SubRaceItem(map);
|
||||
case "RaceItems":
|
||||
return RaceItems(map);
|
||||
case "MonsterItem":
|
||||
return MonsterItem(map);
|
||||
case "MonsterItems":
|
||||
return MonsterItems(map);
|
||||
}
|
||||
return Item(map);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:aidedejeu_flutter/database.dart';
|
||||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:aidedejeu_flutter/widgets/library.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
|
||||
class PCEditorPage extends StatefulWidget {
|
||||
PCEditorPage({Key key}) : super(key: key);
|
||||
|
|
@ -28,9 +30,21 @@ class _PCEditorPageState extends State<PCEditorPage> {
|
|||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
loadRaces().then((value) => setState(() {
|
||||
_races = value.map((e) => e as RaceItem).toList();
|
||||
}));
|
||||
_initRaces();
|
||||
}
|
||||
|
||||
void _initRaces() async {
|
||||
var races = await loadRaces();
|
||||
setState(() {
|
||||
_races = races.map((e) => e as RaceItem).toList();
|
||||
});
|
||||
}
|
||||
|
||||
void _initSubRaces(RaceItem race) async {
|
||||
var subRaces = await loadSubRaces(race);
|
||||
setState(() {
|
||||
_subRaces = subRaces.map((e) => e as SubRaceItem).toList();
|
||||
});
|
||||
}
|
||||
|
||||
void _setRace(RaceItem race) {
|
||||
|
|
@ -39,9 +53,7 @@ class _PCEditorPageState extends State<PCEditorPage> {
|
|||
this._subRace = null;
|
||||
this._subRaces = null;
|
||||
});
|
||||
loadSubRaces(race).then((value) => setState(() {
|
||||
_subRaces = value.map((e) => e as SubRaceItem).toList();
|
||||
}));
|
||||
_initSubRaces(race);
|
||||
}
|
||||
|
||||
void _setSubRace(SubRaceItem subRace) {
|
||||
|
|
@ -68,6 +80,22 @@ class _PCEditorPageState extends State<PCEditorPage> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _loadRaceSubRaceWidget() {
|
||||
return Column(
|
||||
children: [
|
||||
MarkdownBody(
|
||||
data: (_race?.abilityScoreIncrease ?? "") +
|
||||
"\n\n" +
|
||||
(_subRace?.abilityScoreIncrease ?? ""),
|
||||
onTapLink: (link) => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => LibraryPage(id: link)),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _loadSubRacesWidget() {
|
||||
return _subRaces != null
|
||||
? DropdownButton(
|
||||
|
|
@ -95,7 +123,11 @@ class _PCEditorPageState extends State<PCEditorPage> {
|
|||
title: Text("Personnage"),
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[_loadRacesWidget(), _loadSubRacesWidget()],
|
||||
children: <Widget>[
|
||||
_loadRacesWidget(),
|
||||
_loadSubRacesWidget(),
|
||||
_loadRaceSubRaceWidget()
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue