Finished Bot Animations and other fixes

This commit is contained in:
Matthew 2024-06-14 21:14:37 -04:00
parent 89e726b963
commit 5c0763f0a9
11 changed files with 57 additions and 46 deletions

View file

@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
import 'package:fluffychat/pangea/models/igc_text_data_model.dart';
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
import 'package:fluffychat/pangea/models/span_data.dart';
@ -30,8 +29,6 @@ class IgcController {
IgcController(this.choreographer);
bool turnOnAutoPlay = false;
Future<void> getIGCTextData({required bool tokensOnly}) async {
try {
if (choreographer.currentText.isEmpty) return clear();
@ -215,12 +212,6 @@ class IgcController {
),
onITStart: () {
if (choreographer.itEnabled && igcTextData != null) {
if (turnOnAutoPlay) {
choreographer.pangeaController.pStoreService.save(
ToolSetting.itAutoPlay.toString(),
true,
);
}
choreographer.onITStart(igcTextData!.matches[firstMatchIndex]);
}
},

View file

@ -45,7 +45,7 @@ class ITBotButton extends StatelessWidget {
);
return IconButton(
icon: const BotFace(width: 40.0, expression: BotExpression.right),
icon: const BotFace(width: 40.0, expression: BotExpression.idle),
onPressed: () => choreographer.pangeaController.instructions.show(
context,
InstructionsEnum.itInstructions,

View file

@ -129,7 +129,7 @@ class ITFeedbackCardView extends StatelessWidget {
children: [
CardHeader(
text: controller.widget.req.chosenContinuance,
botExpression: BotExpression.down,
botExpression: BotExpression.nonGold,
),
Text(
controller.widget.choiceFeedback,

View file

@ -142,7 +142,7 @@ class UserController extends BaseController {
await updateMatrixProfile(
dateOfBirth: dob,
autoPlayMessages: autoPlay ?? false,
autoPlayMessages: autoPlay,
activatedFreeTrial: trial,
interactiveTranslator: interactiveTranslator,
itAutoPlay: itAutoPlay,

View file

@ -73,7 +73,7 @@ class InstructionsController {
children: [
CardHeader(
text: key.title(context),
botExpression: BotExpression.surprised,
botExpression: BotExpression.idle,
onClose: () => {_instructionsClosed[key] = true},
),
const SizedBox(height: 10.0),

View file

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
enum BotExpression { surprised, right, addled, left, down, shocked }
enum BotExpression { gold, nonGold, addled, idle, surprised }
class BotFace extends StatefulWidget {
final double width;
@ -21,7 +21,7 @@ class BotFace extends StatefulWidget {
class BotFaceState extends State<BotFace> {
Artboard? _artboard;
SMINumber? _input;
StateMachineController? _controller;
@override
void initState() {
@ -31,11 +31,11 @@ class BotFaceState extends State<BotFace> {
double mapExpressionToInput(BotExpression expression) {
switch (expression) {
case BotExpression.surprised:
case BotExpression.gold:
return 1.0;
case BotExpression.right:
case BotExpression.nonGold:
return 2.0;
case BotExpression.shocked:
case BotExpression.surprised:
return 3.0;
case BotExpression.addled:
return 4.0;
@ -48,14 +48,13 @@ class BotFaceState extends State<BotFace> {
final riveFile = await RiveFile.asset('assets/pangea/bot_faces/pangea_bot.riv');
final artboard = riveFile.mainArtboard;
final controller = StateMachineController
_controller = StateMachineController
.fromArtboard(artboard, 'BotIconStateMachine');
if (controller != null) {
artboard.addController(controller);
_input = controller.findInput("Enter State") as SMINumber?;
controller.setInputValue(
890, // this should be the id of the input
if (_controller != null) {
artboard.addController(_controller!);
_controller!.setInputValue(
_controller!.stateMachine.inputs[0].id,
mapExpressionToInput(widget.expression),
);
}
@ -79,6 +78,17 @@ class BotFaceState extends State<BotFace> {
: Container(),
);
}
@override
void didUpdateWidget(BotFace oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.expression != widget.expression) {
_controller!.setInputValue(
_controller!.stateMachine.inputs[0].id,
mapExpressionToInput(widget.expression),
);
}
}
}
// extension ParseToString on BotExpressions {

View file

@ -142,7 +142,7 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
Theme.of(context).textTheme.bodyLarge!.color,
child: const BotFace(
width: 30.0,
expression: BotExpression.right,
expression: BotExpression.idle,
),
),
activeColor: AppConfig.activeToggleColor,

View file

@ -85,12 +85,6 @@ class PangeaTextController extends TextEditingController {
cursorOffset: selection.baseOffset,
),
onITStart: () {
if (choreographer.igc.turnOnAutoPlay) {
choreographer.pangeaController.pStoreService.save(
'ToolSetting.itAutoPlay',
true,
);
}
choreographer.onITStart(
choreographer.igc.igcTextData!.matches[matchIndex],
);

View file

@ -15,6 +15,7 @@ import '../../../widgets/matrix.dart';
import '../../choreographer/widgets/choice_array.dart';
import '../../controllers/pangea_controller.dart';
import '../../enum/span_choice_type.dart';
import '../../models/class_model.dart';
import '../../models/span_card_model.dart';
import '../common/bot_face_svg.dart';
import 'card_header.dart';
@ -49,6 +50,8 @@ class SpanCardState extends State<SpanCard> {
bool fetchingData = false;
int? selectedChoiceIndex;
BotExpression currentExpression = BotExpression.nonGold;
//on initState, get SpanDetails
@override
void initState() {
@ -121,7 +124,23 @@ class WordMatchContent extends StatelessWidget {
.choices?[index]
.selected = true;
controller.setState(() => ());
controller.setState(
() => (
controller.currentExpression =
controller
.widget
.scm
.choreographer
.igc
.igcTextData
!.matches[controller.widget.scm.matchIndex]
.match
.choices![index]
.isBestCorrection
? BotExpression.gold
: BotExpression.nonGold
),
);
// if (controller.widget.scm.pangeaMatch.match.choices![index].type ==
// SpanChoiceType.distractor) {
// await controller.getSpanDetails();
@ -166,7 +185,7 @@ class WordMatchContent extends StatelessWidget {
CardHeader(
text: controller.error?.toString() ?? matchCopy.title,
botExpression: controller.error == null
? BotExpression.right
? controller.currentExpression
: BotExpression.addled,
),
Expanded(
@ -284,10 +303,7 @@ class WordMatchContent extends StatelessWidget {
),
if (controller.widget.scm.pangeaMatch!.isITStart)
DontShowSwitchListTile(
value: controller.widget.scm.choreographer.igc.turnOnAutoPlay,
onChanged: ((value) {
controller.widget.scm.choreographer.igc.turnOnAutoPlay = value;
}),
controller: pangeaController,
),
],
);
@ -429,13 +445,11 @@ class StartITButton extends StatelessWidget {
}
class DontShowSwitchListTile extends StatefulWidget {
final bool value;
final ValueChanged<bool> onChanged;
final PangeaController controller;
const DontShowSwitchListTile({
super.key,
required this.value,
required this.onChanged,
required this.controller,
});
@override
@ -448,7 +462,6 @@ class DontShowSwitchListTileState extends State<DontShowSwitchListTile> {
@override
void initState() {
super.initState();
switchValue = widget.value;
}
@override
@ -458,7 +471,10 @@ class DontShowSwitchListTileState extends State<DontShowSwitchListTile> {
title: Text(L10n.of(context)!.interactiveTranslatorAutoPlaySliderHeader),
value: switchValue,
onChanged: (value) => {
widget.onChanged(value),
widget.controller.pStoreService.save(
ToolSetting.itAutoPlay.toString(),
value,
),
setState(() => switchValue = value),
},
);

View file

@ -271,7 +271,7 @@ class GenerateVocabButtonState extends State<GenerateVocabButton> {
ElevatedButton.icon(
icon: const BotFace(
width: 50.0,
expression: BotExpression.right,
expression: BotExpression.idle,
),
label: Text(L10n.of(context)!.generateVocabulary),
onPressed: () async {
@ -464,9 +464,9 @@ class PromptsFieldState extends State<PromptsField> {
// button to call API
ElevatedButton.icon(
icon: const BotFace(
icon: BotFace(
width: 50.0,
expression: BotExpression.right,
expression: BotExpression.idle,
),
label: Text(L10n.of(context)!.generatePrompts),
onPressed: () async {