Skip to content

Commit 4721144

Browse files
committed
feat: support the second special attribute in rate templates
Points changes toasting is likely broken, this commit tries to update attributes in it but not tested. Update database schema version to 11.
1 parent 4f698e1 commit 4721144

File tree

13 files changed

+76
-6
lines changed

13 files changed

+76
-6
lines changed

lib/features/rate/view/fast_rate_edit_template_page.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class _FastRateTemplateEditPageState extends State<FastRateTemplateEditPage> wit
4545
late final TextEditingController editingControllerTr;
4646
late final TextEditingController editingControllerFh;
4747
late final TextEditingController editingControllerSpecial;
48+
late final TextEditingController editingControllerSpecial2;
4849

4950
/// All current templates, for duplicate check.
5051
final List<FastRateTemplateModel> allTemplates = [];
@@ -72,6 +73,7 @@ class _FastRateTemplateEditPageState extends State<FastRateTemplateEditPage> wit
7273
editingControllerFh = TextEditingController(text: '${widget.initialValue?.fh ?? "0"}');
7374
editingControllerJl = TextEditingController(text: '${widget.initialValue?.jl ?? "0"}');
7475
editingControllerSpecial = TextEditingController(text: '${widget.initialValue?.special ?? "0"}');
76+
editingControllerSpecial2 = TextEditingController(text: '${widget.initialValue?.special2 ?? "0"}');
7577
}
7678

7779
@override
@@ -84,6 +86,7 @@ class _FastRateTemplateEditPageState extends State<FastRateTemplateEditPage> wit
8486
editingControllerTr.dispose();
8587
editingControllerFh.dispose();
8688
editingControllerSpecial.dispose();
89+
editingControllerSpecial2.dispose();
8790
super.dispose();
8891
}
8992

@@ -192,6 +195,14 @@ class _FastRateTemplateEditPageState extends State<FastRateTemplateEditPage> wit
192195
inputFormatters: [numberInputFormatter],
193196
validator: (v) => attributeValidator(v, context),
194197
),
198+
sizedBoxW8H8,
199+
TextFormField(
200+
controller: editingControllerSpecial2,
201+
decoration: InputDecoration(labelText: tr.special2),
202+
keyboardType: const TextInputType.numberWithOptions(signed: true, decimal: true),
203+
inputFormatters: [numberInputFormatter],
204+
validator: (v) => attributeValidator(v, context),
205+
),
195206
if (widget.editType == FastRateTemplateEditType.create) ...[
196207
// Only show override option if drafting new templates.
197208
sizedBoxW8H8,
@@ -219,6 +230,7 @@ class _FastRateTemplateEditPageState extends State<FastRateTemplateEditPage> wit
219230
fh: int.parse(editingControllerFh.text),
220231
jl: int.parse(editingControllerJl.text),
221232
special: int.parse(editingControllerSpecial.text),
233+
special2: int.parse(editingControllerSpecial2.text),
222234
),
223235
);
224236
},

lib/features/rate/view/rate_post_page.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ class _RatePostPageState extends State<RatePostPage> with LoggerMixin {
268268
return;
269269
}
270270

271+
// Flag indicating the first special attribute is used or not.
272+
// Target at the second special attribute when the first one is used and another unknown
273+
// name attribute occurs.
274+
var specialAttrUsed = false;
275+
271276
// Score in `scoreMap` may have score id as key (score1) or score name as key ("威望").
272277
// Here we check the correct attribute name with cached score info in `state.scoreList`.
273278
for (final scoreEntry in scoreMap!.entries) {
@@ -291,7 +296,14 @@ class _RatePostPageState extends State<RatePostPage> with LoggerMixin {
291296
case '精灵':
292297
scoreEntry.value.text = '${pickResult.jl}';
293298
default:
294-
scoreEntry.value.text = '${pickResult.special}';
299+
{
300+
if (specialAttrUsed) {
301+
scoreEntry.value.text = '${pickResult.special2}';
302+
} else {
303+
scoreEntry.value.text = '${pickResult.special}';
304+
specialAttrUsed = true;
305+
}
306+
}
295307
}
296308
}
297309
}

lib/features/rate/widgets/fast_rate_template_card.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class _FastRateTemplateCardState extends State<FastRateTemplateCard> {
144144
nameStyle: nameStyle,
145145
valueStyle: valueStyle,
146146
),
147+
AttrBlock(
148+
name: tr.special2,
149+
value: '${rateTemplate.special2}',
150+
nameStyle: nameStyle,
151+
valueStyle: valueStyle,
152+
),
147153
],
148154
),
149155
],

lib/features/root/bloc/points_changes_cubit.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class PointsChangesValue with PointsChangesValueMappable {
1515
this.fh = 0,
1616
this.jl = 0,
1717
this.specialAttr = 0,
18+
this.specialAttr2 = 0,
1819
});
1920

2021
/// The empty one.
@@ -40,6 +41,9 @@ final class PointsChangesValue with PointsChangesValueMappable {
4041

4142
/// Kind of attribute changes following seasons events.
4243
final int specialAttr;
44+
45+
/// Another kind of attribute changes following seasons events.
46+
final int specialAttr2;
4347
}
4448

4549
/// Cubit of user points changes events.

lib/features/root/view/singleton.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class _RootSingletonState extends State<RootSingleton> with LoggerMixin {
6767
final fh = segments.elementAt(5).parseToInt();
6868
final jl = segments.elementAt(6).parseToInt();
6969
final specialAttr = segments.elementAt(7).parseToInt();
70+
final specialAttr2 = segments.elementAt(8).parseToInt();
7071

7172
if (ww == null || tsb == null || xc == null || tr == null || fh == null || jl == null || specialAttr == null) {
7273
info(
@@ -77,7 +78,16 @@ class _RootSingletonState extends State<RootSingleton> with LoggerMixin {
7778
}
7879

7980
context.read<PointsChangesCubit>().recordsChanges(
80-
PointsChangesValue(ww: ww, tsb: tsb, xc: xc, tr: tr, fh: fh, jl: jl, specialAttr: specialAttr),
81+
PointsChangesValue(
82+
ww: ww,
83+
tsb: tsb,
84+
xc: xc,
85+
tr: tr,
86+
fh: fh,
87+
jl: jl,
88+
specialAttr: specialAttr,
89+
specialAttr2: specialAttr2 ?? 0,
90+
),
8191
);
8292
}
8393

@@ -221,6 +231,9 @@ class _RootSingletonState extends State<RootSingleton> with LoggerMixin {
221231
if (state.specialAttr != 0) {
222232
kinds.add(tr.points.specialAttr(value: state.specialAttr.withSign()));
223233
}
234+
if (state.specialAttr2 != 0) {
235+
kinds.add(tr.points.specialAttr2(value: state.specialAttr2.withSign()));
236+
}
224237
showToast(
225238
kinds.join(tr.sep),
226239
context: context,

lib/i18n/en.i18n.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@
11041104
"tr": "tr ${value: String}",
11051105
"fh": "fh ${value: String}",
11061106
"jl": "jl ${value: String}",
1107-
"specialAttr": "special points ${value: String}"
1107+
"specialAttr": "special points ${value: String}",
1108+
"specialAttr2": "special2 points ${value: String}"
11081109
}
11091110
},
11101111
"fastRateTemplate": {
@@ -1119,6 +1120,7 @@
11191120
"tr": "Natural",
11201121
"fh": "Scheming",
11211122
"special": "Special",
1123+
"special2": "Special2",
11221124
"new": "New",
11231125
"empty": "No rate templates available",
11241126
"delete": "Delete rate template",

lib/i18n/zh-CN.i18n.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@
11041104
"tr": "天然 ${value: String}",
11051105
"fh": "腹黑 ${value: String}",
11061106
"jl": "精灵 ${value: String}",
1107-
"specialAttr": "特殊积分 ${value: String}"
1107+
"specialAttr": "特殊积分 ${value: String}",
1108+
"specialAttr2": "特殊积分2 ${value: String}"
11081109
}
11091110
},
11101111
"fastRateTemplate": {
@@ -1119,6 +1120,7 @@
11191120
"tr": "天然",
11201121
"fh": "腹黑",
11211122
"special": "特殊积分",
1123+
"special2": "特殊积分2",
11221124
"new": "新模板",
11231125
"empty": "没有可用的评分模板",
11241126
"delete": "删除评分模板",

lib/i18n/zh-TW.i18n.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@
11041104
"tr": "天然 ${value: String}",
11051105
"fh": "腹黑 ${value: String}",
11061106
"jl": "精灵 ${value: String}",
1107-
"specialAttr": "特殊积分 ${value: String}"
1107+
"specialAttr": "特殊积分 ${value: String}",
1108+
"specialAttr2": "特殊积分2 ${value: String}"
11081109
}
11091110
},
11101111
"fastRateTemplate": {
@@ -1119,6 +1120,7 @@
11191120
"tr": "天然",
11201121
"fh": "腹黑",
11211122
"special": "特殊積分",
1123+
"special2": "特殊積分2",
11221124
"new": "新範本",
11231125
"empty": "沒有可用的評分範本",
11241126
"delete": "刪除評分範本",

lib/shared/models/fast_rate_template.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class FastRateTemplateModel with FastRateTemplateModelMappable {
1313
required this.fh,
1414
required this.jl,
1515
required this.special,
16+
required this.special2,
1617
});
1718

1819
/// Name of template.
@@ -38,4 +39,7 @@ final class FastRateTemplateModel with FastRateTemplateModelMappable {
3839

3940
/// Special attribute.
4041
final int special;
42+
43+
/// Another special attribute.
44+
final int special2;
4145
}

lib/shared/providers/storage_provider/models/database/database.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class AppDatabase extends _$AppDatabase with LoggerMixin {
3131
AppDatabase(super.e);
3232

3333
@override
34-
int get schemaVersion => 10;
34+
int get schemaVersion => 11;
3535

3636
@override
3737
MigrationStrategy get migration => MigrationStrategy(
@@ -142,6 +142,11 @@ final class AppDatabase extends _$AppDatabase with LoggerMixin {
142142
await m.create(schema.fastReplyTemplate);
143143
info('migrating database schema from 9 to 10... ok!');
144144
},
145+
from10To11: (m, schema) async {
146+
info('migrating database schema from 10 to 11...');
147+
await m.addColumn(schema.fastRateTemplate, schema.fastRateTemplate.special2);
148+
info('migrating database schema from 10 to 11... ok!');
149+
},
145150
),
146151
);
147152
}

0 commit comments

Comments
 (0)