Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

askForXXX函数再造计划 #378

Open
Notify-ctrl opened this issue Oct 14, 2024 · 1 comment
Open

askForXXX函数再造计划 #378

Notify-ctrl opened this issue Oct 14, 2024 · 1 comment
Labels
Lua Something related to Lua Refactor
Milestone

Comments

@Notify-ctrl
Copy link
Collaborator

Notify-ctrl commented Oct 14, 2024

如题,现在Room中的用于发动GameEvent的函数已经分了个mixin出来(并且注释中认为Room继承它),类似的也可以给askForXXX也分一个mixin出来。

如何组织文件?

我的看法是server/下新建一个文件夹,把network.lua(定义Request类的那个)放进来,再在里面定义多个文件放置各种askForXXX,文件组织或可比照requestHandler

如何造出更好用的askForXXX?

和神杀一脉相承的使用参数超多的askForXXX,代价就是用起来也像神杀那样难受,为此最好作出修改;可是怎么改呢?如果Lua有python那种按名字传参就好了可惜没有,所以传表吧?

联想一下request用法:

local request = Request:new(command, {player})
request.accept_cancel = true
request:setData(player, data)
request:ask()
return request.result[player.id]

可见只需要维护data就行了,那直接askForXXX(player, data)

又或者,手动创建Request并且填data,其实代码量比以前少好多了,但我需要插件给提示啊。。怎么办呢怎么让插件根据Command的不同而给出不同的setData提示呢。。。emmmmmmmmmmmmmmmmmmmmmm

@Notify-ctrl Notify-ctrl added Lua Something related to Lua Refactor labels Oct 14, 2024
@Notify-ctrl Notify-ctrl added this to the AI milestone Oct 14, 2024
@Notify-ctrl Notify-ctrl changed the title askForXXX函数搬家计划 askForXXX函数再造计划 Oct 14, 2024
@YoumuKon
Copy link
Collaborator

理论上吧,你真的可以学py那种按名字传参:
function a(method, table)
需要什么参数直接事前在table[名字] = 参数就完事了
不过……这些东西终究还是“为了照顾modder而生”,毕竟大多数askForXXX真正做的就是在里面拼出那个要传给request的table……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lua Something related to Lua Refactor
Projects
None yet
Development

No branches or pull requests

2 participants