|
|
|
@ -1,8 +1,13 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:rive/rive.dart';
|
|
|
|
|
|
|
|
|
|
|
|
enum BotExpression { surprised, right, addled, left, down, shocked }
|
|
|
|
enum BotExpression { surprised, right, addled, left, down, shocked }
|
|
|
|
|
|
|
|
|
|
|
|
class BotFace extends StatelessWidget {
|
|
|
|
class BotFace extends StatefulWidget {
|
|
|
|
|
|
|
|
final double width;
|
|
|
|
|
|
|
|
final Color? forceColor;
|
|
|
|
|
|
|
|
final BotExpression expression;
|
|
|
|
|
|
|
|
|
|
|
|
const BotFace({
|
|
|
|
const BotFace({
|
|
|
|
super.key,
|
|
|
|
super.key,
|
|
|
|
required this.width,
|
|
|
|
required this.width,
|
|
|
|
@ -10,21 +15,68 @@ class BotFace extends StatelessWidget {
|
|
|
|
this.forceColor,
|
|
|
|
this.forceColor,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
final double width;
|
|
|
|
@override
|
|
|
|
final Color? forceColor;
|
|
|
|
BotFaceState createState() => BotFaceState();
|
|
|
|
final BotExpression expression;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BotFaceState extends State<BotFace> {
|
|
|
|
|
|
|
|
Artboard? _artboard;
|
|
|
|
|
|
|
|
SMINumber? _input;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
_loadRiveFile();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double mapExpressionToInput(BotExpression expression) {
|
|
|
|
|
|
|
|
switch (expression) {
|
|
|
|
|
|
|
|
case BotExpression.surprised:
|
|
|
|
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
case BotExpression.right:
|
|
|
|
|
|
|
|
return 2.0;
|
|
|
|
|
|
|
|
case BotExpression.shocked:
|
|
|
|
|
|
|
|
return 3.0;
|
|
|
|
|
|
|
|
case BotExpression.addled:
|
|
|
|
|
|
|
|
return 4.0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadRiveFile() async {
|
|
|
|
|
|
|
|
final riveFile = await RiveFile.asset('assets/pangea/bot_faces/pangea_bot.riv');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final artboard = riveFile.mainArtboard;
|
|
|
|
|
|
|
|
final 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
|
|
|
|
|
|
|
|
mapExpressionToInput(widget.expression),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
_artboard = artboard;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Image.asset(
|
|
|
|
|
|
|
|
'assets/pangea/bot_faces/${expression.toString().split('.').last}.png',
|
|
|
|
return SizedBox(
|
|
|
|
// 'assets/pangea/bot_faces/surprised.png',
|
|
|
|
width: widget.width,
|
|
|
|
width: width,
|
|
|
|
height: widget.width,
|
|
|
|
height: width,
|
|
|
|
child: _artboard != null
|
|
|
|
// color: forceColor ??
|
|
|
|
? Rive(
|
|
|
|
// (Theme.of(context).brightness == Brightness.light
|
|
|
|
artboard: _artboard!,
|
|
|
|
// ? Theme.of(context).colorScheme.primary
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
// : Theme.of(context).colorScheme.primary),
|
|
|
|
)
|
|
|
|
|
|
|
|
: Container(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|