diff --git a/changeLog_ioGame.md b/changeLog_ioGame.md index 9f8ae38ed..a792a00d2 100644 --- a/changeLog_ioGame.md +++ b/changeLog_ioGame.md @@ -33,7 +33,7 @@ https://github.com/iohao/ioGame/releases/tag/21.22 About examples -1. ioGameServerExample https://github.com/iohao/ioGameExamples/SdkExample +1. ioGameServerExample: https://github.com/iohao/ioGameExamples/tree/main/SdkExample 2. CocosCreatorExample: https://github.com/iohao/ioGameSdkTsExampleCocos 3. VueExample: https://github.com/iohao/ioGameSdkTsExampleVue 4. HtmlExample: https://github.com/iohao/ioGameSdkTsExampleHtml diff --git a/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/beans/property/BooleanProperty.java b/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/beans/property/BooleanProperty.java index 0beea3fa2..3701e8da1 100644 --- a/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/beans/property/BooleanProperty.java +++ b/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/beans/property/BooleanProperty.java @@ -20,6 +20,8 @@ import lombok.ToString; +import java.util.Objects; + /** * bool - 属性具备监听特性。当值发生变更时,会触发监听事件。 *
{@code @@ -57,11 +59,7 @@ public Boolean getValue() { @Override public void setValue(Boolean value) { - if (value == null) { - this.set(false); - } else { - this.set(value); - } + this.set(Objects.requireNonNullElse(value, false)); } /** diff --git a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationContext.java b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationContext.java index bfa02a277..e10885946 100644 --- a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationContext.java +++ b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationContext.java @@ -67,8 +67,10 @@ public class OperationContext implements PlayerOperationContext { */ public void execute() { // 玩法操作业务类,将验证与操作分离 - this.operationHandler.verify(this); - this.operationHandler.process(this); + if (this.operationHandler.processVerify(this)) { + this.operationHandler.verify(this); + this.operationHandler.process(this); + } } /** diff --git a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationHandler.java b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationHandler.java index ecbccebdf..7db6645e2 100644 --- a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationHandler.java +++ b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/OperationHandler.java @@ -48,7 +48,23 @@ public interface OperationHandler { * * @param context 操作上下文 */ - void verify(PlayerOperationContext context); + default void verify(PlayerOperationContext context) { + } + + /** + * 检测验证,验证用户操作步骤是否合法,通过返回值来决定是否执行 {@link OperationHandler#process(PlayerOperationContext)} 方法。 + *+ * 当返回 false 时,不会执行 process 方法,相当于丢弃该请求的处理。 + * 该方法与 {@link OperationHandler#verify(PlayerOperationContext)} 类似, + * 只不过多了一个返回值来决定是否执行 process 方法。 + * + * @param context 操作上下文 + * @return 当返回 true 时,会执行 {@link OperationHandler#process(PlayerOperationContext)} 方法 + * @since 21.23 + */ + default boolean processVerify(PlayerOperationContext context) { + return true; + } /** * 验证通过后, 执行处理 diff --git a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/SimpleOperationFactory.java b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/SimpleOperationFactory.java index 831f1f551..86bbbc4ac 100644 --- a/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/SimpleOperationFactory.java +++ b/widget/light-game-room/src/main/java/com/iohao/game/widget/light/room/operation/SimpleOperationFactory.java @@ -64,7 +64,7 @@ public void mapping(int operation, OperationHandler operationHandler) { } public void mappingUser(int operation, OperationHandler operationHandler) { - this.operationMap.put(operation, operationHandler); + this.mapping(operation, operationHandler); this.userOperationMap.put(operation, operationHandler); }