Skip to content

Commit

Permalink
perf(room): OperationHandler add processVerify method, used to contro…
Browse files Browse the repository at this point in the history
…l whether to execute the process method
  • Loading branch information
iohao committed Dec 5, 2024
1 parent 8f5f039 commit fc6b207
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion changeLog_ioGame.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import lombok.ToString;

import java.util.Objects;

/**
* bool - 属性具备监听特性。当值发生变更时,会触发监听事件。
* <pre>{@code
Expand Down Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,23 @@ public interface OperationHandler {
*
* @param context 操作上下文
*/
void verify(PlayerOperationContext context);
default void verify(PlayerOperationContext context) {
}

/**
* 检测验证,验证用户操作步骤是否合法,通过返回值来决定是否执行 {@link OperationHandler#process(PlayerOperationContext)} 方法。
* <p>
* 当返回 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;
}

/**
* 验证通过后, 执行处理
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit fc6b207

Please sign in to comment.