use of com.playshogi.website.gwt.client.util.FireAndForgetCallback in project playshogi by Tellmarch.
the class ViewLessonActivity method onVisitedProgress.
@EventHandler
public void onVisitedProgress(final VisitedProgressEvent event) {
GWT.log("ViewLessonActivity: Handling VisitedProgressEvent");
if (sessionInformation.isLoggedIn()) {
boolean complete = event.getTotal() == event.getVisited();
int newPercentage = 100 * event.getVisited() / event.getTotal();
if ((percentage != 100 && newPercentage == 100) || newPercentage > percentage + 10) {
percentage = newPercentage;
userService.saveLessonProgress(sessionInformation.getSessionId(), place.getLessonId(), duration.elapsedMillis(), complete, percentage, null, new FireAndForgetCallback("saveLessonProgress"));
}
}
}
use of com.playshogi.website.gwt.client.util.FireAndForgetCallback in project playshogi by Tellmarch.
the class ViewLessonActivity method onMarkLessonComplete.
@EventHandler
public void onMarkLessonComplete(final MarkLessonCompleteEvent event) {
GWT.log("ViewLessonActivity: Handling MarkLessonCompleteEvent");
if (sessionInformation.isLoggedIn()) {
percentage = 100;
userService.saveLessonProgress(sessionInformation.getSessionId(), place.getLessonId(), duration.elapsedMillis(), true, percentage, null, new FireAndForgetCallback("saveLessonProgress"));
Notification.createSuccess("Lesson was marked as complete").show();
}
}
use of com.playshogi.website.gwt.client.util.FireAndForgetCallback in project playshogi by Tellmarch.
the class ByoYomiActivity method onUserFinishedProblemEvent.
@EventHandler
void onUserFinishedProblemEvent(final UserFinishedProblemEvent event) {
GWT.log("Finished problem. Success: " + event.isSuccess());
problemsService.saveUserProblemAttempt(sessionInformation.getSessionId(), tsumeId, event.isSuccess(), problemDuration.elapsedMillis(), new FireAndForgetCallback("saveUserProblemAttempt"));
if (stopped) {
return;
}
if (event.isSuccess()) {
solved++;
if (solved % place.getRaiseDifficultyEveryN() == 0 && numMoves < 13 && place.getNumberOfMoves() == 0) {
numMoves += 2;
}
} else {
failed++;
}
if (failed < place.getMaxFailures()) {
loadNextProblem();
} else {
stop();
}
}
use of com.playshogi.website.gwt.client.util.FireAndForgetCallback in project playshogi by Tellmarch.
the class ByoYomiActivity method stop.
private void stop() {
GWT.log("Stop byo yomi activity");
int timeSec = byoYomiDuration.elapsedMillis() / 1000;
if (place.getMaxTimeSec() > 0 && timeSec > place.getMaxTimeSec()) {
timeSec = place.getMaxTimeSec();
}
if (place.isDefault()) {
GWT.log("Saving high score");
String username = sessionInformation.getUsername();
if (username == null || "Guest".equals(username)) {
username = Window.prompt("What is your name?", "Guest");
}
problemsService.saveHighScore(username, solved, new FireAndForgetCallback());
}
eventBus.fireEvent(new ByoYomiSurvivalFinishedEvent(solved, solved, failed, timeSec));
stopTimers();
stopped = true;
}
use of com.playshogi.website.gwt.client.util.FireAndForgetCallback in project playshogi by Tellmarch.
the class ProblemsActivity method loadNextProblem.
private void loadNextProblem() {
if (isTimerRunning()) {
problemIndex++;
if (problemIndex == statuses.length)
problemIndex = 0;
boolean firstPass = true;
while (statuses[problemIndex] == ProblemStatus.SOLVED) {
problemIndex++;
if (problemIndex == statuses.length) {
if (firstPass) {
firstPass = false;
problemIndex = 0;
} else {
break;
}
}
}
} else {
problemIndex++;
}
if (problemIndex >= problems.length) {
if (isTimerRunning()) {
stopTimer();
int time = duration.elapsedMillis();
eventBus.fireEvent(new ActivityTimerEvent(time, false));
Window.alert("Congratulations, you have solved all the problems!");
if (sessionInformation.isLoggedIn()) {
saveTime(time);
}
} else {
Window.alert("You reached the last problem in the collection!");
}
if (lessonId != null && !lessonId.isEmpty() && !"null".equals(lessonId) && sessionInformation.isLoggedIn()) {
userService.saveLessonProgress(sessionInformation.getSessionId(), lessonId, duration == null ? 0 : duration.elapsedMillis(), true, 100, null, new FireAndForgetCallback("saveLessonProgress"));
}
return;
}
loadProblem();
}
Aggregations