feat: 实现起卦、设置与积分系统
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
enum DivinationMethod { manual, auto }
|
||||
|
||||
enum QuestionType {
|
||||
career,
|
||||
love,
|
||||
wealth,
|
||||
fortune,
|
||||
dream,
|
||||
health,
|
||||
study,
|
||||
search,
|
||||
other,
|
||||
}
|
||||
|
||||
enum YaoType { undetermined, youngYang, youngYin, oldYang, oldYin }
|
||||
|
||||
class DivinationParams {
|
||||
const DivinationParams({
|
||||
required this.method,
|
||||
required this.questionType,
|
||||
required this.question,
|
||||
required this.divinationTime,
|
||||
required this.coinBalance,
|
||||
required this.userId,
|
||||
});
|
||||
|
||||
final DivinationMethod method;
|
||||
final QuestionType questionType;
|
||||
final String question;
|
||||
final DateTime divinationTime;
|
||||
final int coinBalance;
|
||||
final String userId;
|
||||
|
||||
DivinationParams copyWith({
|
||||
DivinationMethod? method,
|
||||
QuestionType? questionType,
|
||||
String? question,
|
||||
DateTime? divinationTime,
|
||||
int? coinBalance,
|
||||
String? userId,
|
||||
}) {
|
||||
return DivinationParams(
|
||||
method: method ?? this.method,
|
||||
questionType: questionType ?? this.questionType,
|
||||
question: question ?? this.question,
|
||||
divinationTime: divinationTime ?? this.divinationTime,
|
||||
coinBalance: coinBalance ?? this.coinBalance,
|
||||
userId: userId ?? this.userId,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
return <String, dynamic>{
|
||||
'method': method.name,
|
||||
'questionType': questionType.name,
|
||||
'question': question,
|
||||
'divinationTime': divinationTime.toIso8601String(),
|
||||
'coinBalance': coinBalance,
|
||||
'userId': userId,
|
||||
};
|
||||
}
|
||||
|
||||
String toBinary(List<YaoType> yaoStates) {
|
||||
return yaoStates
|
||||
.map(
|
||||
(v) => switch (v) {
|
||||
YaoType.youngYang || YaoType.oldYang => '1',
|
||||
_ => '0',
|
||||
},
|
||||
)
|
||||
.join();
|
||||
}
|
||||
|
||||
String toChangedBinary(List<YaoType> yaoStates) {
|
||||
return yaoStates
|
||||
.map(
|
||||
(v) => switch (v) {
|
||||
YaoType.youngYang => '1',
|
||||
YaoType.youngYin => '0',
|
||||
YaoType.oldYang => '0',
|
||||
YaoType.oldYin => '1',
|
||||
YaoType.undetermined => '0',
|
||||
},
|
||||
)
|
||||
.join();
|
||||
}
|
||||
}
|
||||
|
||||
class DivinationMockData {
|
||||
static DivinationParams initial() {
|
||||
return DivinationParams(
|
||||
method: DivinationMethod.manual,
|
||||
questionType: QuestionType.career,
|
||||
question: '',
|
||||
divinationTime: DateTime.now(),
|
||||
coinBalance: 8,
|
||||
userId: 'mock_user_10001',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user