-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from msi-se/paper-plane-animation
Paper plane animation
- Loading branch information
Showing
11 changed files
with
500 additions
and
56 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/de/htwg_konstanz/mobilelearning/services/quiz/socket/Fun.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package de.htwg_konstanz.mobilelearning.services.quiz.socket; | ||
|
||
import org.bson.types.ObjectId; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import de.htwg_konstanz.mobilelearning.helper.ObjectIdTypeAdapter; | ||
|
||
public class Fun { | ||
|
||
public String action; // THROW_PAPER_PLANE | ||
public double percentageX; | ||
public double percentageY; | ||
|
||
public Fun(String message) { | ||
|
||
|
||
Gson gson = new GsonBuilder().registerTypeAdapter(ObjectId.class, new ObjectIdTypeAdapter()).create(); | ||
Fun funString = gson.fromJson(message, Fun.class); | ||
this.action = funString.action; | ||
this.percentageX = funString.percentageX; | ||
this.percentageY = funString.percentageY; | ||
|
||
System.out.println("Fun Action: " + this.action); | ||
System.out.println("Fun percentageX: " + this.percentageX); | ||
System.out.println("Fun percentageY: " + this.percentageY); | ||
} | ||
|
||
public Fun(String action, double percentageX, double percentageY) { | ||
this.action = action; | ||
this.percentageX = percentageX; | ||
this.percentageY = percentageY; | ||
} | ||
|
||
public String toJson() { | ||
Gson gson = new GsonBuilder().registerTypeAdapter(ObjectId.class, new ObjectIdTypeAdapter()).create(); | ||
return gson.toJson(this); | ||
} | ||
|
||
public Fun copy() { | ||
return new Fun(this.action, this.percentageX, this.percentageY); | ||
} | ||
|
||
public static Fun getByJsonWithForm(String message) { | ||
Gson gson = new GsonBuilder().registerTypeAdapter(ObjectId.class, new ObjectIdTypeAdapter()).create(); | ||
return gson.fromJson(message, Fun.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:rive/rive.dart'; | ||
|
||
enum ThrowType { | ||
paperPlane( | ||
filename: "paper_plane.riv", | ||
artboard: "Artboard", | ||
stateMachine: "Hit State Machine", | ||
width: 700, | ||
height: 1200, | ||
hitX: 602, | ||
hitY: 144), | ||
stone( | ||
filename: "stone.riv", | ||
artboard: "New Artboard", | ||
stateMachine: "State Machine 1", | ||
width: 700, | ||
height: 500, | ||
hitX: 614, | ||
hitY: 96), | ||
dart( | ||
filename: "dart.riv", | ||
artboard: "New Artboard", | ||
stateMachine: "State Machine 1", | ||
width: 700, | ||
height: 1000, | ||
hitX: 660, | ||
hitY: 41); | ||
// ball("ball.riv"), | ||
|
||
final String filename; | ||
final String artboard; | ||
final String stateMachine; | ||
final double width; | ||
final double height; | ||
final double hitX; | ||
final double hitY; | ||
|
||
const ThrowType( | ||
{required this.filename, | ||
required this.artboard, | ||
required this.stateMachine, | ||
required this.hitX, | ||
required this.width, | ||
required this.height, | ||
required this.hitY}); | ||
} | ||
|
||
class Throw extends StatefulWidget { | ||
final ThrowType throwType; | ||
final double clickX; | ||
final double clickY; | ||
|
||
const Throw( | ||
{required this.throwType, | ||
required this.clickX, | ||
required this.clickY, | ||
super.key}); | ||
|
||
@override | ||
State<Throw> createState() => _ThrowState(); | ||
} | ||
|
||
class _ThrowState extends State<Throw> { | ||
final riveDirName = 'assets/animations/rive'; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Positioned( | ||
key: UniqueKey(), | ||
left: widget.clickX - widget.throwType.hitX, | ||
top: widget.clickY - widget.throwType.hitY, | ||
child: SizedBox( | ||
width: widget.throwType.width, | ||
height: widget.throwType.height, | ||
child: RiveAnimation.asset( | ||
"$riveDirName/${widget.throwType.filename}", | ||
fit: BoxFit.cover, | ||
artboard: widget.throwType.artboard, | ||
stateMachines: [widget.throwType.stateMachine], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.