Skip to content

Commit

Permalink
1. 添加Build上传功能(试运行),可以通过点击详情页的网上配置按钮浏览自己和他人分享的内容
Browse files Browse the repository at this point in the history
2. 资源文件合并至20220106
3. 修复 劣势性格突破时,竞技场档位计算不准确的问题
4. 修复 部分锻造武器翻译不显示的问题
5. 整合详情页的操作到一个按钮
  • Loading branch information
jay committed Jan 6, 2022
1 parent 485df74 commit 7a6de0b
Show file tree
Hide file tree
Showing 31 changed files with 1,479 additions and 80 deletions.
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

属性算法来源:[Feh | Fire Emblem Wiki | Fandom](https://fireemblem.fandom.com/wiki/Feh)

flutter 版本:2.5.3(理论支持 2.2 到 2.5.3,但是大版本升级存在一些破环性更新,建议使用最新的版本)
flutter 版本:2.8.1

使用说明:

Expand All @@ -26,20 +26,9 @@ flutter 版本:2.5.3(理论支持 2.2 到 2.5.3,但是大版本升级存
3. 编译运行

备注:
1.github 仅作为代码开源仓库,不会随时更新

2.考虑到使用云数据库的安全问题,涉及的网络操作 api 没有公开,可以参考以下代码

```dart
class ApiService extends GetxService {
// eg
Future get(){
}
}
```


1. github 仅作为代码开源仓库,不会随时更新。
2. 考虑到使用云数据库的安全问题,涉及的网络操作 api 没有公开.

截图:

Expand Down
Binary file modified assets/assets.zip
Binary file not shown.
Binary file added assets/static/Frm_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/Frm_Reliance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/Wdw_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/Wdw_Reliance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/n0.webp
Binary file not shown.
Binary file added assets/static/n1.webp
Binary file not shown.
Binary file added assets/static/n2.webp
Binary file not shown.
Binary file added assets/static/no-blessing.webp
Binary file not shown.
33 changes: 33 additions & 0 deletions lib/data_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:convert';
import 'dart:io';
import 'dart:ui' show Locale;

import 'package:archive/archive.dart';
import 'package:cloud_db/cloud_db.dart';
import 'package:feh_rebuilder/models/build_share/favorite_table.dart';
import 'package:feh_rebuilder/models/personBuild/person_build.dart';
import 'package:feh_rebuilder/utils.dart';
import 'package:flutter/services.dart' show rootBundle, ByteData;
Expand Down Expand Up @@ -32,6 +35,7 @@ class DataService extends GetxService {
"currentVersion": "",
"dataVersion": "0",
"favorites": <PersonBuild>[],
"allowGetId": false,
};

Map<String, Locale> languageDict = const {
Expand Down Expand Up @@ -203,4 +207,33 @@ class DataService extends GetxService {
moveBox = GetStorage('moveBox', r"assets\dataBox\moveBox");
await GetStorage.init("moveBox");
}

Map<String, FavoriteTable> favorites = {};
Map<String, String> cloudTags = {};

bool cacheRefreshed = false;

bool get allowGetId => customBox.read("allowGetId") ?? false;

Future refreshCache() async {
await Cloud().login();
var r1 = await Query(table: "favorite", queryParameters: {
"where": jsonEncode({"user": Cloud().currentUser.username})
}).doQuery();

var _favorites = r1.results.map((e) => FavoriteTable.fromJson(e)).toList();
_favorites.sort((a, b) => b.createdAt!.compareTo(a.createdAt!));

for (var item in _favorites) {
favorites.putIfAbsent(item.build!.objectId, () => item);
}
var r2 = await Query(table: "build_tags").doQuery();
r2.results.sort((a, b) => (a["seq"] as int).compareTo(b["seq"] as int));

for (var item in r2.results) {
cloudTags.putIfAbsent(item["objectId"], () => item["value"]);
}

cacheRefreshed = true;
}
}
12 changes: 11 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:io';
import 'package:cloud_db/cloud_db.dart';
import 'package:feh_rebuilder/api_service.dart';
import 'package:feh_rebuilder/data_service.dart';
import 'package:feh_rebuilder/pages/heroBuildShare/bindings.dart';
import 'package:feh_rebuilder/pages/heroBuildShare/view.dart';
import 'package:feh_rebuilder/pages/heroDetail/bindings.dart';
import 'package:feh_rebuilder/pages/home/bindings.dart';
import 'package:feh_rebuilder/pages/home/view.dart';
Expand All @@ -10,7 +13,6 @@ import 'package:feh_rebuilder/utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -39,6 +41,9 @@ void main() async {

await initServices(appDir, tempDir);

// 网络服务初始化,
Cloud().init((err) => Utils.showToast(err.error.toString()));

runApp(const MyApp());
}

Expand Down Expand Up @@ -68,6 +73,11 @@ List<GetPage> pages = [
page: () => const SkillsBrowse(),
binding: SkillsBrowseBindings(),
),
GetPage(
name: "/heroBuildShare",
page: () => const HeroBuildSharePage(),
binding: HeroBuildShareBinding(),
),
];

// for flutter 2.5
Expand Down
137 changes: 137 additions & 0 deletions lib/models/build_share/build_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import 'dart:convert';

import 'package:cloud_db/cloud_db.dart';

import 'like_table.dart';

class HeroBuildTable extends BTable {
HeroBuildTable({
this.creator,
this.title,
this.build,
this.idTag,
this.likes,
// this.dislikes,
this.tags,
ACL? acl,
String? objectId,
DateTime? updatedAt,
DateTime? createdAt,
bool useDefaultAcl = true,
}) : super(
acl: acl ?? ACL(),
objectId: objectId,
createdAt: createdAt,
updatedAt: updatedAt,
useDefaultAcl: useDefaultAcl,
);
String? creator;
String? title;
String? build;
String? idTag;
BPointer<LikeTable>? likes;
// BPointer<DislikeTable>? dislikes;
BArray<String>? tags;

static const String table = "hero_build";

@override
String get tableName => table;

@override
Map<String, dynamic> toJson() {
return {
"creator": creator,
"title": title,
"build": build,
"id_tag": idTag,
"likes": likes?.toJson(),
// "dislikes": dislikes?.toJson(),
"tags": tags?.toJson(),
};
}

@override
String toString() {
return jsonEncode(toJson());
}

factory HeroBuildTable.fromJson(Map<String, dynamic> json) {
return HeroBuildTable()..fromJson(json);
}

/// 新增一个build
Future<PostResult> create() async {
// var r = await Batch(tasks: [
// BatchTask(
// method: BatchMethod.POST,
// path: "/1/classes/likes",
// body: {"count": 0},
// ),
// BatchTask(
// method: BatchMethod.POST,
// path: "/1/classes/dislikes",
// body: {"count": 0},
// ),
// ]).doTasks();
var r = await LikeTable(count: 0).post();
likes = BPointer(className: "likes", objectId: r.objectId!);
// dislikes = BPointer(
// className: "dislikes", objectId: (r[1].result as PostResult).objectId!);
var _r = await post();
return _r;
}

/// 点赞/踩一个BUILD
///
/// [isLike] 表示操作类型:1赞 2踩 0取消
///
/// [isPlus]代表操作,true+1 false-1
// Future likeBuild(int isLike, bool isPlus) async {
// if (objectId != null && likes != null) {
// var r = await Batch(tasks: [
// // favorite添加一条记录
// BatchTask(
// method: BatchMethod.POST,
// path: "/1/classes/favorite",
// body: {
// "user": Cloud().currentUser.username,
// "type": isLike,
// "build":
// BPointer(className: "hero_build", objectId: objectId!).toJson(),
// },
// ),
// // likes表+/-1
// BatchTask(
// method: BatchMethod.PUT,
// path: "/1/classes/likes/${likes!.objectId}",
// body: {
// "count": {"__op": "Increment", "amount": isPlus ? 1 : -1}
// },
// ),
// ]).doTasks();
// }
// }

@override
void fromJson(Map<String, dynamic> json) {
creator = json["creator"];
title = json["title"];
build = json["build"];
idTag = json["id_tag"];

likes = json["likes"] != null
? BPointer.fromJson(json["likes"], (json) => LikeTable.fromJson(json))
: null;
// dislikes = BPointer.fromJson(
// json["dislikes"], (json) => DislikeTable.fromJson(json));
tags = BArray.fromJson((json["tags"] as List? ?? []).cast<String>());

// 父属性
acl = ACL.fromJson(json["ACL"]);
// ? [objectId] 是否应该允许覆盖?
objectId = json["objectId"];
createdAt = DateTime.tryParse(json["createdAt"] ?? "");
updatedAt = DateTime.tryParse(json["updatedAt"] ?? "");
}
}
54 changes: 54 additions & 0 deletions lib/models/build_share/favorite_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:cloud_db/cloud_db.dart';

import 'build_table.dart';

class FavoriteTable extends BTable {
FavoriteTable({
this.build,
this.user,
this.type,
ACL? acl,
String? objectId,
DateTime? updatedAt,
DateTime? createdAt,
bool useDefaultAcl = false,
}) : super(
acl: acl ?? ACL(),
objectId: objectId,
createdAt: createdAt,
updatedAt: updatedAt,
useDefaultAcl: useDefaultAcl,
);
BPointer<HeroBuildTable>? build;
String? user;
int? type;

@override
void fromJson(Map<String, dynamic> json) {
build = json["build"] != null
? BPointer.fromJson(
json["build"], (json) => HeroBuildTable.fromJson(json))
: null;
user = json["user"];
type = json["type"];

acl = ACL.fromJson(json["ACL"]);
// ? [objectId] 是否应该允许覆盖?
objectId = json["objectId"];
createdAt = DateTime.tryParse(json["createdAt"] ?? "");
updatedAt = DateTime.tryParse(json["updatedAt"] ?? "");
}

factory FavoriteTable.fromJson(Map<String, dynamic> json) =>
FavoriteTable()..fromJson(json);

@override
String get tableName => "favorite";

@override
Map<String, dynamic> toJson() => {
"user": user,
"type": type,
"build": build?.toJson(),
};
}
43 changes: 43 additions & 0 deletions lib/models/build_share/like_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:cloud_db/cloud_db.dart';

class LikeTable extends BTable {
LikeTable({
this.count,
ACL? acl,
String? objectId,
DateTime? updatedAt,
DateTime? createdAt,
bool useDefaultAcl = false,
}) : super(
acl: acl ?? ACL(),
objectId: objectId,
createdAt: createdAt,
updatedAt: updatedAt,
useDefaultAcl: useDefaultAcl,
);
int? count;
@override
void fromJson(Map<String, dynamic> json) {
count = json["count"];
acl = ACL.fromJson(json["ACL"]);
// ? [objectId] 是否应该允许覆盖?
objectId = json["objectId"];
createdAt = DateTime.tryParse(json["createdAt"] ?? "");
updatedAt = DateTime.tryParse(json["updatedAt"] ?? "");
}

factory LikeTable.fromJson(Map<String, dynamic> json) =>
LikeTable()..fromJson(json);

@override
String get tableName => "likes";

@override
Map<String, dynamic> toJson() => {"count": count};

Future<void> countChange(bool plus) async {
await put({
"count": {"__op": "Increment", "amount": plus ? 1 : -1}
});
}
}
12 changes: 12 additions & 0 deletions lib/pages/heroBuildShare/bindings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:get/get.dart';

import 'controller.dart';

class HeroBuildShareBinding extends Bindings {
HeroBuildShareBinding();

@override
void dependencies() {
Get.lazyPut(() => HeroBuildSharePageController());
}
}
Loading

0 comments on commit 7a6de0b

Please sign in to comment.