Search in sources :

Example 1 with EventHandler

use of com.google.web.bindery.event.shared.binder.EventHandler in project playshogi by Tellmarch.

the class ViewKifuActivity method onPositionChangedEvent.

@EventHandler
public void onPositionChangedEvent(final PositionChangedEvent event) {
    GWT.log("ViewKifuActivity handling PositionChangedEvent");
    // TODO: do all this only if we are in mainline
    ShogiPosition position = event.getPosition();
    int moveCount = position.getMoveCount();
    if (!isPreviewOnly()) {
        // Update URL with the new move count
        History.replaceItem("ViewKifu:" + new ViewKifuPlace.Tokenizer().getToken(new ViewKifuPlace(kifuId, moveCount)), false);
    }
    if (analysisResult != null && analysisResult.getEvaluationDetails().length > moveCount) {
        PositionEvaluationDetails detail = analysisResult.getEvaluationDetails()[moveCount];
        Scheduler.get().scheduleDeferred(() -> eventBus.fireEvent(new PositionEvaluationEvent(detail)));
    }
    String gameSetId = "1";
    kifuService.getPositionDetails(SfenConverter.toSFEN(position), gameSetId, new AsyncCallback<PositionDetails>() {

        @Override
        public void onSuccess(final PositionDetails result) {
            GWT.log("VIEW KIFU - GOT POSITION DETAILS ");
            eventBus.fireEvent(new PositionStatisticsEvent(result, position, gameSetId));
        }

        @Override
        public void onFailure(final Throwable caught) {
            GWT.log("VIEW KIFU - ERROR GETTING POSITION STATS");
        }
    });
}
Also used : ViewKifuPlace(com.playshogi.website.gwt.client.place.ViewKifuPlace) PositionDetails(com.playshogi.website.gwt.shared.models.PositionDetails) PositionEvaluationDetails(com.playshogi.website.gwt.shared.models.PositionEvaluationDetails) ShogiPosition(com.playshogi.library.shogi.models.position.ShogiPosition) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 2 with EventHandler

use of com.google.web.bindery.event.shared.binder.EventHandler in project playshogi by Tellmarch.

the class ViewKifuActivity method onRequestKifuEvaluationEvent.

@EventHandler
public void onRequestKifuEvaluationEvent(final RequestKifuEvaluationEvent event) {
    GWT.log("View Kifu Activity Handling RequestKifuEvaluationEvent");
    String usf = UsfFormat.INSTANCE.write(viewKifuView.getNavigationController().getGameNavigation().getGameTree());
    kifuService.requestKifuAnalysis(sessionInformation.getSessionId(), usf, new AsyncCallback<AnalysisRequestStatus>() {

        @Override
        public void onFailure(Throwable throwable) {
            GWT.log("ViewKifu - error requesting kifu evaluation");
        }

        @Override
        public void onSuccess(AnalysisRequestStatus result) {
            GWT.log("ViewKifu - kifu evaluation result: " + result);
            if (result.isDenied()) {
                eventBus.fireEvent(new KifuEvaluationEvent(new AnalysisRequestResult(result), kifuId));
            } else if (result.needToWait()) {
                Timer timer = new Timer() {

                    @Override
                    public void run() {
                        queryKifuAnalysisResults(usf, this);
                    }
                };
                timer.scheduleRepeating(1000);
            } else {
                queryKifuAnalysisResults(usf, null);
            }
        }
    });
}
Also used : Timer(com.google.gwt.user.client.Timer) AnalysisRequestResult(com.playshogi.website.gwt.shared.models.AnalysisRequestResult) AnalysisRequestStatus(com.playshogi.website.gwt.shared.models.AnalysisRequestStatus) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 3 with EventHandler

use of com.google.web.bindery.event.shared.binder.EventHandler in project playshogi by Tellmarch.

the class ViewKifuActivity method onMoveSelectedEvent.

@EventHandler
public void onMoveSelectedEvent(final MoveSelectedEvent event) {
    GWT.log("ViewKifuActivity handling MoveSelectedEvent");
    eventBus.fireEvent(new GameTreeChangedEvent(gameRecord.getGameTree(), event.getMoveNumber()));
}
Also used : GameTreeChangedEvent(com.playshogi.website.gwt.client.events.gametree.GameTreeChangedEvent) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 4 with EventHandler

use of com.google.web.bindery.event.shared.binder.EventHandler 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"));
        }
    }
}
Also used : FireAndForgetCallback(com.playshogi.website.gwt.client.util.FireAndForgetCallback) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 5 with EventHandler

use of com.google.web.bindery.event.shared.binder.EventHandler 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();
    }
}
Also used : FireAndForgetCallback(com.playshogi.website.gwt.client.util.FireAndForgetCallback) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Aggregations

EventHandler (com.google.web.bindery.event.shared.binder.EventHandler)23 ShogiPosition (com.playshogi.library.shogi.models.position.ShogiPosition)5 GameTreeChangedEvent (com.playshogi.website.gwt.client.events.gametree.GameTreeChangedEvent)4 FireAndForgetCallback (com.playshogi.website.gwt.client.util.FireAndForgetCallback)4 PositionDetails (com.playshogi.website.gwt.shared.models.PositionDetails)3 HTMLLIElement (elemental2.dom.HTMLLIElement)3 ShogiMove (com.playshogi.library.shogi.models.moves.ShogiMove)2 PositionChangedEvent (com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent)2 ProblemDetails (com.playshogi.website.gwt.shared.models.ProblemDetails)2 GWT (com.google.gwt.core.shared.GWT)1 PlaceController (com.google.gwt.place.shared.PlaceController)1 Timer (com.google.gwt.user.client.Timer)1 Window (com.google.gwt.user.client.Window)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 com.google.gwt.user.client.ui (com.google.gwt.user.client.ui)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 EventBinder (com.google.web.bindery.event.shared.binder.EventBinder)1 EditMove (com.playshogi.library.shogi.models.moves.EditMove)1