mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-29 22:45:44 +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 { | class Item { | ||||||
|   String id; |   String id; | ||||||
|   String rootId; |   String rootId; | ||||||
|   String newId; |  | ||||||
|   String parentLink; |   String parentLink; | ||||||
|   String name; |   String name; | ||||||
|   String normalizedName; |   String normalizedName; | ||||||
|  | @ -21,7 +20,6 @@ class Item { | ||||||
|   Item(Map<String, dynamic> map) { |   Item(Map<String, dynamic> map) { | ||||||
|     this.id = map["Id"]; |     this.id = map["Id"]; | ||||||
|     this.rootId = map["RootId"]; |     this.rootId = map["RootId"]; | ||||||
|     this.newId = map["NewId"]; |  | ||||||
|     this.name = map["Name"]; |     this.name = map["Name"]; | ||||||
|     this.alias = map["AltName"]; |     this.alias = map["AltName"]; | ||||||
|     this.aliasText = map["AltNameText"]; |     this.aliasText = map["AltNameText"]; | ||||||
|  | @ -57,8 +55,7 @@ class MonsterItem extends Item { | ||||||
|   String challenge; |   String challenge; | ||||||
|   int xp; |   int xp; | ||||||
| 
 | 
 | ||||||
|   MonsterItem(Map<String, dynamic> map) |   MonsterItem(Map<String, dynamic> map) : super(map) { | ||||||
|     : super(map) { |  | ||||||
|     this.family = map["Family"]; |     this.family = map["Family"]; | ||||||
|     this.type = map["Type"]; |     this.type = map["Type"]; | ||||||
|     this.size = map["Size"]; |     this.size = map["Size"]; | ||||||
|  | @ -88,17 +85,13 @@ class MonsterItem extends Item { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class Items 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 { | abstract class FilteredItems extends Items { | ||||||
|   String family; |   String family; | ||||||
| 
 | 
 | ||||||
|   FilteredItems(Map<String, dynamic> map) |   FilteredItems(Map<String, dynamic> map) : super(map) { | ||||||
|       : super(map) { |  | ||||||
|     this.family = map["Family"]; |     this.family = map["Family"]; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -112,33 +105,95 @@ class MonsterItems extends FilteredItems { | ||||||
|   Filter sources; |   Filter sources; | ||||||
|   Filter terrains; |   Filter terrains; | ||||||
| 
 | 
 | ||||||
|   MonsterItems(Map<String, dynamic> map) |   MonsterItems(Map<String, dynamic> map) : super(map) { | ||||||
|       : super(map) { |     this.types = Filter( | ||||||
|     this.types = Filter(name: "Type", type: FilterType.Choices, values: map["Types"].toString().split("|")); |         name: "Type", | ||||||
|     this.challenges = Filter(name: "Challenge", type: FilterType.Range, values: map["Challenges"].toString().split("|")); |         type: FilterType.Choices, | ||||||
|     this.sizes = Filter(name: "Size", type: FilterType.Range, values: map["Sizes"].toString().split("|"));; |         values: map["Types"].toString().split("|")); | ||||||
|     this.sources = Filter(name: "Source", type: FilterType.Choices, values: map["Sources"].toString().split("|")); |     this.challenges = Filter( | ||||||
|     this.terrains = Filter(name: "Terrain", type: FilterType.Choices, values: map["Terrains"].toString().split("|")); |         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() => { |   List<Filter> toFilterList() => { | ||||||
|     types, |         types, | ||||||
|     challenges, |         challenges, | ||||||
|     sizes, |         sizes, | ||||||
|     sources, |         sources, | ||||||
|     terrains, |         terrains, | ||||||
|   }.toList(); |       }.toList(); | ||||||
| 
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class RaceItem extends Item { | 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 { | 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 { | class RaceItems extends FilteredItems { | ||||||
|  | @ -148,16 +203,20 @@ class RaceItems extends FilteredItems { | ||||||
|   List<Filter> toFilterList() { |   List<Filter> toFilterList() { | ||||||
|     return [].toList(); |     return [].toList(); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Item itemFromMap(Map<String, dynamic> map) { | Item itemFromMap(Map<String, dynamic> map) { | ||||||
|   switch(map["ItemType"]) { |   switch (map["ItemType"]) { | ||||||
|     case "RaceItem": return RaceItem(map); |     case "RaceItem": | ||||||
|     case "SubRaceItem": return SubRaceItem(map); |       return RaceItem(map); | ||||||
|     case "RaceItems": return RaceItems(map); |     case "SubRaceItem": | ||||||
|     case "MonsterItem": return MonsterItem(map); |       return SubRaceItem(map); | ||||||
|     case "MonsterItems": return MonsterItems(map); |     case "RaceItems": | ||||||
|  |       return RaceItems(map); | ||||||
|  |     case "MonsterItem": | ||||||
|  |       return MonsterItem(map); | ||||||
|  |     case "MonsterItems": | ||||||
|  |       return MonsterItems(map); | ||||||
|   } |   } | ||||||
|   return Item(map); |   return Item(map); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| import 'package:aidedejeu_flutter/database.dart'; | import 'package:aidedejeu_flutter/database.dart'; | ||||||
| import 'package:aidedejeu_flutter/models/items.dart'; | import 'package:aidedejeu_flutter/models/items.dart'; | ||||||
|  | import 'package:aidedejeu_flutter/widgets/library.dart'; | ||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
|  | import 'package:flutter_markdown/flutter_markdown.dart'; | ||||||
| 
 | 
 | ||||||
| class PCEditorPage extends StatefulWidget { | class PCEditorPage extends StatefulWidget { | ||||||
|   PCEditorPage({Key key}) : super(key: key); |   PCEditorPage({Key key}) : super(key: key); | ||||||
|  | @ -28,9 +30,21 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|   void initState() { |   void initState() { | ||||||
|     // TODO: implement initState |     // TODO: implement initState | ||||||
|     super.initState(); |     super.initState(); | ||||||
|     loadRaces().then((value) => setState(() { |     _initRaces(); | ||||||
|           _races = value.map((e) => e as RaceItem).toList(); |   } | ||||||
|         })); | 
 | ||||||
|  |   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) { |   void _setRace(RaceItem race) { | ||||||
|  | @ -39,9 +53,7 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|       this._subRace = null; |       this._subRace = null; | ||||||
|       this._subRaces = null; |       this._subRaces = null; | ||||||
|     }); |     }); | ||||||
|     loadSubRaces(race).then((value) => setState(() { |     _initSubRaces(race); | ||||||
|           _subRaces = value.map((e) => e as SubRaceItem).toList(); |  | ||||||
|         })); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _setSubRace(SubRaceItem subRace) { |   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() { |   Widget _loadSubRacesWidget() { | ||||||
|     return _subRaces != null |     return _subRaces != null | ||||||
|         ? DropdownButton( |         ? DropdownButton( | ||||||
|  | @ -95,7 +123,11 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|         title: Text("Personnage"), |         title: Text("Personnage"), | ||||||
|       ), |       ), | ||||||
|       body: Column( |       body: Column( | ||||||
|         children: <Widget>[_loadRacesWidget(), _loadSubRacesWidget()], |         children: <Widget>[ | ||||||
|  |           _loadRacesWidget(), | ||||||
|  |           _loadSubRacesWidget(), | ||||||
|  |           _loadRaceSubRaceWidget() | ||||||
|  |         ], | ||||||
|       ), |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez