284 lines
5.5 KiB
Dart
284 lines
5.5 KiB
Dart
import 'package:overfast_api/utils/types.dart';
|
|
|
|
class Hero {
|
|
final String name;
|
|
final HeroKey key;
|
|
final String? portrait;
|
|
final Role role;
|
|
|
|
const Hero({
|
|
required this.name,
|
|
required this.key,
|
|
this.portrait,
|
|
required this.role,
|
|
});
|
|
|
|
factory Hero.fromJson(Map<String, dynamic> json) {
|
|
return Hero(
|
|
name: json['name'],
|
|
key: HeroKey.fromString(json['key']),
|
|
portrait: json['portrait'],
|
|
role: Role.fromString(json['role']),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'name': name,
|
|
'key': key.name,
|
|
'portrait': portrait,
|
|
'role': role.toString(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class HeroDetails extends Hero {
|
|
final String location;
|
|
final List<Ability> abilities;
|
|
final Map? hitpoints;
|
|
final Story story;
|
|
final String description;
|
|
final int age;
|
|
final String? birthday;
|
|
|
|
|
|
const HeroDetails({
|
|
required super.name,
|
|
required super.role,
|
|
super.portrait,
|
|
required this.description,
|
|
required this.story,
|
|
required this.location,
|
|
required this.abilities,
|
|
this.hitpoints,
|
|
// Stub
|
|
super.key = HeroKey.eemptyy,
|
|
required this.age,
|
|
required this.birthday,
|
|
});
|
|
|
|
factory HeroDetails.fromJson(Map<String, dynamic> json) {
|
|
return HeroDetails(
|
|
name: json['name'],
|
|
description: (json['description']),
|
|
portrait: json['portrait'],
|
|
role: Role.fromString(json['role']),
|
|
location: json['location'],
|
|
abilities:
|
|
(json['abilities'] as List).map((e) => Ability.fromJson(e)).toList(),
|
|
hitpoints: json['hitpoints'],
|
|
story: Story.fromJson(json['story']),
|
|
age: json['age'],
|
|
birthday: json['birthday'],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'name': name,
|
|
'description': description,
|
|
'portrait': portrait,
|
|
'role': role.toString(),
|
|
'location': location,
|
|
'abilities': abilities.map((e) => e.toJson()).toList(),
|
|
'hitpoints': hitpoints,
|
|
'story': story.toJson(),
|
|
'age': age,
|
|
'birthday': birthday,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Ability {
|
|
final String name;
|
|
final String description;
|
|
final String icon;
|
|
final Video video;
|
|
|
|
const Ability({
|
|
required this.name,
|
|
required this.description,
|
|
required this.icon,
|
|
required this.video,
|
|
});
|
|
|
|
factory Ability.fromJson(Map<String, dynamic> json) {
|
|
return Ability(
|
|
name: json['name'],
|
|
description: json['description'],
|
|
icon: json['icon'],
|
|
video: Video.fromJson(json['video']),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'name': name,
|
|
'description': description,
|
|
'icon': icon,
|
|
'video': video.toJson(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class Video {
|
|
final String thumbnail;
|
|
final Link link;
|
|
|
|
const Video({
|
|
required this.thumbnail,
|
|
required this.link,
|
|
});
|
|
|
|
factory Video.fromJson(Map<String, dynamic> json) {
|
|
return Video(
|
|
thumbnail: json['thumbnail'],
|
|
link: Link.fromJson(json['link']),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'thumbnail': thumbnail,
|
|
'link': link.toJson(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class Link {
|
|
final String mp4;
|
|
final String webm;
|
|
|
|
const Link({
|
|
required this.mp4,
|
|
required this.webm,
|
|
});
|
|
|
|
factory Link.fromJson(Map<String, dynamic> json) {
|
|
return Link(
|
|
mp4: json['mp4'],
|
|
webm: json['webm'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'mp4': mp4,
|
|
'webm': webm,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Story {
|
|
final String summary;
|
|
final Media? media;
|
|
final List<Chapter> chapters;
|
|
|
|
const Story({
|
|
required this.summary,
|
|
required this.media,
|
|
required this.chapters,
|
|
});
|
|
|
|
factory Story.fromJson(Map<String, dynamic> json) {
|
|
return Story(
|
|
summary: json['summary'],
|
|
media: json['media'] != null ? Media.fromJson(json['media']) : null,
|
|
chapters:
|
|
(json['chapters'] as List).map((e) => Chapter.fromJson(e)).toList(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'summary': summary,
|
|
if (media != null) 'media': media!.toJson(),
|
|
'chapters': chapters.map((e) => e.toJson()).toList(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class Media {
|
|
final String type;
|
|
final String link;
|
|
|
|
const Media({
|
|
required this.type,
|
|
required this.link,
|
|
});
|
|
|
|
factory Media.fromJson(Map<String, dynamic> json) {
|
|
return Media(
|
|
type: json['type'],
|
|
link: json['link'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'type': type,
|
|
'link': link,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Chapter {
|
|
final String title;
|
|
final String content;
|
|
final String picture;
|
|
|
|
const Chapter({
|
|
required this.title,
|
|
required this.content,
|
|
required this.picture,
|
|
});
|
|
|
|
factory Chapter.fromJson(Map<String, dynamic> json) {
|
|
return Chapter(
|
|
title: json['title'],
|
|
content: json['content'],
|
|
picture: json['picture'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'title': title,
|
|
'content': content,
|
|
'picture': picture,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Roles {
|
|
final Role key;
|
|
final String name;
|
|
final String icon;
|
|
final String description;
|
|
|
|
const Roles({
|
|
required this.key,
|
|
required this.name,
|
|
required this.icon,
|
|
required this.description,
|
|
});
|
|
|
|
factory Roles.fromJson(Map<String, dynamic> json) {
|
|
return Roles(
|
|
key: Role.fromString(json['key']),
|
|
name: json['name'],
|
|
icon: json['icon'],
|
|
description: json['description'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'key': key.toString(),
|
|
'name': name,
|
|
'icon': icon,
|
|
'description': description,
|
|
};
|
|
}
|
|
} |