mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 06:56:10 +00:00
Plein de tests
This commit is contained in:
parent
fa0e36faa8
commit
2911bc359b
3 changed files with 204 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -264,3 +264,4 @@ __pycache__/
|
||||||
/AideDeJeu/AideDeJeu.Android/zipalign.bat
|
/AideDeJeu/AideDeJeu.Android/zipalign.bat
|
||||||
/Ignore
|
/Ignore
|
||||||
/AideDeJeu/AideDeJeuWeb/Properties/PublishProfiles/AideDeJeuWeb - Web Deploy.pubxml
|
/AideDeJeu/AideDeJeuWeb/Properties/PublishProfiles/AideDeJeuWeb - Web Deploy.pubxml
|
||||||
|
*.lock
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:aidedejeu_flutter/models/items.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
|
@ -9,23 +10,6 @@ import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class Item {
|
|
||||||
String Id;
|
|
||||||
String Markdown;
|
|
||||||
|
|
||||||
Item({this.Id, this.Markdown});
|
|
||||||
|
|
||||||
factory Item.fromMap(Map<String, dynamic> json) => new Item(
|
|
||||||
Id: json["Id"],
|
|
||||||
Markdown: json["Markdown"],
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> toMap() => {
|
|
||||||
"Id": Id,
|
|
||||||
"Markdown": Markdown,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Database _database;
|
Database _database;
|
||||||
|
|
||||||
Future<Database> get database async {
|
Future<Database> get database async {
|
||||||
|
|
@ -48,7 +32,7 @@ Future<Database> getDatabaseInstance() async {
|
||||||
|
|
||||||
ByteData data = await rootBundle.load(join("assets", "library.db"));
|
ByteData data = await rootBundle.load(join("assets", "library.db"));
|
||||||
List<int> bytes =
|
List<int> bytes =
|
||||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
||||||
|
|
||||||
await File(path).writeAsBytes(bytes, flush: true);
|
await File(path).writeAsBytes(bytes, flush: true);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -66,7 +50,25 @@ Future<Item> getItemWithId(String id) async {
|
||||||
if (response.isEmpty) {
|
if (response.isEmpty) {
|
||||||
print("Id not found");
|
print("Id not found");
|
||||||
}
|
}
|
||||||
return response.isNotEmpty ? Item.fromMap(response.first) : null;
|
return response.isNotEmpty ? itemFromMap(response.first) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Item> loadChildrenItems(Item item) async {
|
||||||
|
print("getChildrenItems " + item.Discriminator);
|
||||||
|
if (item.Discriminator.endsWith("Items")) {
|
||||||
|
String discriminator =
|
||||||
|
item.Discriminator.substring(0, item.Discriminator.length - 1);
|
||||||
|
final db = await database;
|
||||||
|
var response = await db
|
||||||
|
.query("Items", where: "Discriminator = ?", whereArgs: [discriminator]);
|
||||||
|
if (response.isEmpty) {
|
||||||
|
print("Id not found");
|
||||||
|
}
|
||||||
|
item.Children = response.isNotEmpty
|
||||||
|
? itemsFromMapList(response)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
|
|
@ -96,15 +98,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
void setMarkdown(String md) {
|
void setItem(Item item) {
|
||||||
setState(() {
|
setState(() {
|
||||||
markdown = md.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
|
this.item = item;
|
||||||
|
this.markdown =
|
||||||
|
item.Markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String markdown = "";
|
String markdown = "";
|
||||||
|
Item item = null;
|
||||||
MarkdownStyleSheet styleSheet;
|
MarkdownStyleSheet styleSheet;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -125,31 +130,85 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
//styleSheet = MarkdownStyleSheet.fromTheme(theme);
|
//styleSheet = MarkdownStyleSheet.fromTheme(theme);
|
||||||
styleSheet = MarkdownStyleSheet(
|
styleSheet = MarkdownStyleSheet(
|
||||||
|
//p: TextStyle(fontSize: 14.0, fontFamily: 'LinuxLibertine'),
|
||||||
|
|
||||||
tableColumnWidth: IntrinsicColumnWidth(),
|
tableColumnWidth: IntrinsicColumnWidth(),
|
||||||
tableCellsPadding: EdgeInsets.all(0.2));
|
tableCellsPadding: EdgeInsets.all(0.2));
|
||||||
|
|
||||||
getItemWithId(this.id)
|
getItemWithId(this.id)
|
||||||
.then((item) => setMarkdown(item.Markdown))
|
.then((item) => loadChildrenItems(item).then((items) => setItem(item)))
|
||||||
.catchError((error) => print(error));
|
.catchError((error) => print(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Widget svg = SvgPicture.asset("assets/crystal-ball.svg",
|
final Widget svg = SvgPicture.asset(
|
||||||
|
"assets/crystal-ball.svg",
|
||||||
height: 20.0,
|
height: 20.0,
|
||||||
width: 20.0,
|
width: 20.0,
|
||||||
allowDrawingOutsideViewBox: true,
|
allowDrawingOutsideViewBox: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Widget buildMarkdown(BuildContext context) {
|
||||||
|
return Markdown(
|
||||||
|
data: markdown,
|
||||||
|
styleSheet: styleSheet,
|
||||||
|
onTapLink: (link) => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => MyHomePage(id: link)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Widget buildMarkdownBody(BuildContext context) {
|
||||||
|
return MarkdownBody(
|
||||||
|
data: markdown,
|
||||||
|
styleSheet: styleSheet,
|
||||||
|
onTapLink: (link) => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => MyHomePage(id: link)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Widget buildChildTile(BuildContext context, Item item) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(item.Name),
|
||||||
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => MyHomePage(id: item.Id)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
int count = 0;
|
||||||
|
if (item != null && item.Children != null) {
|
||||||
|
count = item.Children.length;
|
||||||
|
}
|
||||||
|
final List<int> _listData = List<int>.generate(count + 1, (i) => i);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.id),
|
title: Text(widget.id),
|
||||||
),
|
),
|
||||||
body: Markdown(
|
body: //Container(
|
||||||
data: markdown,
|
//child: Column(
|
||||||
styleSheet: styleSheet,
|
Stack(
|
||||||
onTapLink: (link) => Navigator.push(context,
|
children: <Widget>[
|
||||||
MaterialPageRoute(builder: (context) => MyHomePage(id: link)))),
|
//Text(markdown)
|
||||||
|
item?.Children != null ?
|
||||||
|
ListView.builder(
|
||||||
|
itemCount: item.Children.length + 1,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return index == 0 ?
|
||||||
|
buildMarkdownBody(context)
|
||||||
|
: buildChildTile(context, item.Children[index - 1]);
|
||||||
|
}) : buildMarkdown(context), //: Text(item.Children[i-1].Name);}).toList()
|
||||||
|
],
|
||||||
|
),
|
||||||
|
//),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
items: const <BottomNavigationBarItem>[
|
items: const <BottomNavigationBarItem>[
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
|
|
|
||||||
115
aidedejeu_flutter/lib/models/items.dart
Normal file
115
aidedejeu_flutter/lib/models/items.dart
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
class Item {
|
||||||
|
String Id;
|
||||||
|
String RootId;
|
||||||
|
String ParentLink;
|
||||||
|
String Name;
|
||||||
|
String NormalizedName;
|
||||||
|
String ParentName;
|
||||||
|
int NameLevel;
|
||||||
|
String Alias;
|
||||||
|
String AliasText;
|
||||||
|
String NormalizedAlias;
|
||||||
|
String Source;
|
||||||
|
String Markdown;
|
||||||
|
String FullText;
|
||||||
|
String Discriminator;
|
||||||
|
List<Item> Children;
|
||||||
|
|
||||||
|
Item({this.Id, this.Name, this.Alias, this.Markdown, this.Discriminator});
|
||||||
|
|
||||||
|
Item.fromMap(Map<String, dynamic> map) {
|
||||||
|
this.Id = map["Id"];
|
||||||
|
this.Name = map["Name"];
|
||||||
|
this.Alias = map["AltName"];
|
||||||
|
this.Markdown = map["Markdown"];
|
||||||
|
this.Discriminator = map["Discriminator"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*factory Item.fromMap(Map<String, dynamic> json) => new Item(
|
||||||
|
Id: json["Id"],
|
||||||
|
Name: json["Name"],
|
||||||
|
Alias: json["AltName"],
|
||||||
|
Markdown: json["Markdown"],
|
||||||
|
Discriminator: json["Discriminator"],
|
||||||
|
);*/
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() => {
|
||||||
|
"Id": Id,
|
||||||
|
"RootId": Id,
|
||||||
|
"Name": Name,
|
||||||
|
"AltName": Alias,
|
||||||
|
"Markdown": Markdown,
|
||||||
|
"Discriminator": Discriminator,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class MonsterItem extends Item {
|
||||||
|
String Family;
|
||||||
|
String Type;
|
||||||
|
String Size;
|
||||||
|
String Alignment;
|
||||||
|
String Terrain;
|
||||||
|
String Legendary;
|
||||||
|
String ArmorClass;
|
||||||
|
String HitPoints;
|
||||||
|
String Speed;
|
||||||
|
String Strength;
|
||||||
|
String Dexterity;
|
||||||
|
String Constitution;
|
||||||
|
String Intelligence;
|
||||||
|
String Wisdom;
|
||||||
|
String Charisma;
|
||||||
|
String SavingThrows;
|
||||||
|
String Skills;
|
||||||
|
String DamageVulnerabilities;
|
||||||
|
String DamageImmunities;
|
||||||
|
String ConditionImmunities;
|
||||||
|
String DamageResistances;
|
||||||
|
String Senses;
|
||||||
|
String Languages;
|
||||||
|
String Challenge;
|
||||||
|
int XP;
|
||||||
|
|
||||||
|
MonsterItem.fromMap(Map<String, dynamic> map)
|
||||||
|
: super.fromMap(map) {
|
||||||
|
this.Family = map["Family"];
|
||||||
|
this.Type = map["Type"];
|
||||||
|
this.Size = map["Size"];
|
||||||
|
this.Alignment = map["Alignment"];
|
||||||
|
this.Terrain = map["Terrain"];
|
||||||
|
this.Legendary = map["Legendary"];
|
||||||
|
this.ArmorClass = map["ArmorClass"];
|
||||||
|
this.HitPoints = map["HitPoints"];
|
||||||
|
this.Speed = map["Speed"];
|
||||||
|
this.Strength = map["Strength"];
|
||||||
|
this.Dexterity = map["Dexterity"];
|
||||||
|
this.Constitution = map["Constitution"];
|
||||||
|
this.Intelligence = map["Intelligence"];
|
||||||
|
this.Wisdom = map["Wisdom"];
|
||||||
|
this.Charisma = map["Charisma"];
|
||||||
|
this.SavingThrows = map["SavingThrows"];
|
||||||
|
this.Skills = map["Skills"];
|
||||||
|
this.DamageVulnerabilities = map["DamageVulnerabilities"];
|
||||||
|
this.DamageImmunities = map["DamageImmunities"];
|
||||||
|
this.ConditionImmunities = map["ConditionImmunities"];
|
||||||
|
this.DamageResistances = map["DamageResistances"];
|
||||||
|
this.Senses = map["Senses"];
|
||||||
|
this.Languages = map["Languages"];
|
||||||
|
this.Challenge = map["Challenge"];
|
||||||
|
this.XP = map["XP"];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item itemFromMap(Map<String, dynamic> map) {
|
||||||
|
switch(map["Discriminator"]) {
|
||||||
|
case "MonsterItem": return MonsterItem.fromMap(map);
|
||||||
|
}
|
||||||
|
return Item.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Item> itemsFromMapList(List<Map<String, dynamic>> mapList) {
|
||||||
|
return List.generate(mapList.length, (i) {
|
||||||
|
return itemFromMap(mapList[i]);
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue