diff --git a/Fk/RoomElement/Photo.qml b/Fk/RoomElement/Photo.qml index bbd9bbe4..cb73de73 100644 --- a/Fk/RoomElement/Photo.qml +++ b/Fk/RoomElement/Photo.qml @@ -179,6 +179,7 @@ Item { Image { id: generalImage width: deputyGeneral ? parent.width / 2 : parent.width + Behavior on width { NumberAnimation { duration: 100 } } height: parent.height smooth: true fillMode: Image.PreserveAspectCrop @@ -259,7 +260,8 @@ Item { anchors.fill: photoMaskEffect source: photoMaskEffect saturation: 0 - visible: root.dead || root.surrendered + opacity: (root.dead || root.surrendered) ? 1 : 0 + Behavior on opacity { NumberAnimation { duration: 300 } } } Rectangle { @@ -269,9 +271,10 @@ Item { height: 222 radius: 8 - visible: root.drank > 0 + // visible: root.drank > 0 color: "red" - opacity: 0.4 + Math.log(root.drank) * 0.12 + opacity: (root.drank <= 0 ? 0 : 0.4) + Math.log(root.drank) * 0.12 + Behavior on opacity { NumberAnimation { duration: 300 } } } ColumnLayout { diff --git a/lang/zh_CN.ts b/lang/zh_CN.ts index e5dbf625..371eae03 100644 --- a/lang/zh_CN.ts +++ b/lang/zh_CN.ts @@ -107,6 +107,10 @@ [%1/%2] upgrading package '%3' [%1/%2] 更新拓展包 '%3' + + packages/%1: some error occured. + 拓展包 %1 出了点问题,尝试在管理拓展包中删除之再试试 + diff --git a/lua/server/gameevent.lua b/lua/server/gameevent.lua index e89012b6..b5401faf 100644 --- a/lua/server/gameevent.lua +++ b/lua/server/gameevent.lua @@ -14,6 +14,7 @@ ---@field public exit_func fun(self: GameEvent) @ 事件结束后执行的函数 ---@field public extra_exit_funcs fun(self:GameEvent)[] @ 事件结束后执行的自定义函数 ---@field public exec_ret boolean? @ exec函数的返回值,可能不存在 +---@field public status string @ ready, running, exiting, dead ---@field public interrupted boolean @ 事件是否是因为被中断而结束的,可能是防止事件或者被杀 ---@field public killed boolean @ 事件因为终止一切结算而被中断(所谓的“被杀”) local GameEvent = class("GameEvent") @@ -49,6 +50,7 @@ function GameEvent:initialize(event, ...) self.extra_clear_funcs = Util.DummyTable self.exit_func = GameEvent.exit_funcs[event] or dummyFunc self.extra_exit_funcs = Util.DummyTable + self.status = "ready" self.interrupted = false end @@ -166,6 +168,8 @@ end function GameEvent:exec() local room = self.room local logic = room.logic + if self.status ~= "ready" then return true end + self.parent = logic:getCurrentEvent() if self:prepare_func() then return true end @@ -174,6 +178,7 @@ function GameEvent:exec() local co = coroutine.create(self.main_func) self._co = co + self.status = "running" coroutine.yield(self, "__newEvent") @@ -188,6 +193,7 @@ function GameEvent:exec() end function GameEvent:shutdown() + if self.status ~= "running" then return end -- yield to self and break coroutine.yield(self, "__breakEvent") end diff --git a/lua/server/gamelogic.lua b/lua/server/gamelogic.lua index db8470a1..9e1e340d 100644 --- a/lua/server/gamelogic.lua +++ b/lua/server/gamelogic.lua @@ -441,6 +441,7 @@ function GameLogic:start() e.killed = e ~= jump_to self:clearEvent(e) coroutine.close(e._co) + e.status = "dead" if e == jump_to then jump_to = nil end -- shutdown结束了 e = self:getCurrentCleaner() end @@ -460,6 +461,7 @@ function GameLogic:start() e.interrupted = ret self:clearEvent(e) coroutine.close(e._co) + e.status = "dead" elseif ret == true then -- 跳到越早发生的事件越好 if not jump_to then @@ -543,6 +545,8 @@ end ---@param event GameEvent function GameLogic:clearEvent(event) if event.event == GameEvent.ClearEvent then return end + if event.status == "exiting" then return end + event.status = "exiting" local ce = GameEvent(GameEvent.ClearEvent, event) ce.id = self.current_event_id local co = coroutine.create(ce.main_func) @@ -657,6 +661,7 @@ end function GameLogic:breakTurn() local event = self:getCurrentEvent():findParent(GameEvent.Turn) + if not event then return end event:shutdown() end diff --git a/src/core/packman.cpp b/src/core/packman.cpp index dead59c2..7f3430f0 100644 --- a/src/core/packman.cpp +++ b/src/core/packman.cpp @@ -169,7 +169,11 @@ void PackMan::updatePack(const QString &pack) { int error; error = status(pack); if (error != 0) { - qCritical("packages/%s: Workspace is dirty, or some error occured.", pack.toLatin1().constData()); +#ifndef FK_SERVER_ONLY + if (Backend != nullptr) { + Backend->showToast(tr("packages/%1: some error occured.").arg(pack)); + } +#endif return; } error = pull(pack); @@ -187,7 +191,11 @@ void PackMan::upgradePack(const QString &pack) { return; error = status(pack); if (error != 0) { - qCritical("Workspace is dirty, or some error occured."); +#ifndef FK_SERVER_ONLY + if (Backend != nullptr) { + Backend->showToast(tr("packages/%1: some error occured.").arg(pack)); + } +#endif return; } error = pull(pack); @@ -219,6 +227,12 @@ QString PackMan::listPackages() { const git_error *e = git_error_last(); \ qCritical("Error %d/%d: %s\n", error, e->klass, e->message) +#define GIT_CHK_CLEAN \ + if (error < 0) { \ + GIT_FAIL; \ + goto clean; \ + } + static int transfer_progress_cb(const git_indexer_progress *stats, void *payload) { (void)payload; @@ -290,37 +304,22 @@ int PackMan::pull(const QString &name) { opt2.checkout_strategy = GIT_CHECKOUT_FORCE; error = git_repository_open(&repo, path); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; // first git fetch origin error = git_remote_lookup(&remote, repo, "origin"); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_remote_fetch(remote, NULL, &opt, NULL); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; // then git checkout FETCH_HEAD error = git_repository_set_head(repo, "FETCH_HEAD"); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_checkout_head(repo, &opt2); - if (error < 0) { - GIT_FAIL; - goto clean; - } else { - if (Backend == nullptr) - printf("\n"); - } + GIT_CHK_CLEAN; + + if (Backend == nullptr) + printf("\n"); clean: git_remote_free(remote); @@ -337,25 +336,13 @@ int PackMan::checkout(const QString &name, const QString &hash) { auto path = QString("packages/%1").arg(name).toUtf8(); auto sha = hash.toLatin1(); error = git_repository_open(&repo, path); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_oid_fromstr(&oid, sha); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_repository_set_head_detached(repo, &oid); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_checkout_head(repo, &opt); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; clean: git_repository_free(repo); @@ -369,20 +356,11 @@ int PackMan::checkout_branch(const QString &name, const QString &branch) { git_object *obj = NULL; auto path = QString("packages/%1").arg(name).toUtf8(); error = git_repository_open(&repo, path); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_revparse_single(&obj, repo, branch.toUtf8()); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_checkout_tree(repo, obj, NULL); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; clean: git_object_free(obj); @@ -398,21 +376,19 @@ int PackMan::status(const QString &name) { const git_status_entry *s; auto path = QString("packages/%1").arg(name).toUtf8(); error = git_repository_open(&repo, path); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; error = git_status_list_new(&status_list, repo, NULL); - if (error < 0) { - GIT_FAIL; - goto clean; - } + GIT_CHK_CLEAN; maxi = git_status_list_entrycount(status_list); for (i = 0; i < maxi; ++i) { char *istatus = NULL; s = git_status_byindex(status_list, i); - if (s->status != GIT_STATUS_CURRENT && s->status != GIT_STATUS_IGNORED) + if (s->status != GIT_STATUS_CURRENT && s->status != GIT_STATUS_IGNORED) { + git_status_list_free(status_list); + git_repository_free(repo); + qCritical("Workspace is dirty."); return 1; + } } clean: @@ -425,28 +401,25 @@ QString PackMan::head(const QString &name) { git_repository *repo = NULL; int error; git_object *obj = NULL; + const git_oid *oid; + char buf[42] = {0}; auto path = QString("packages/%1").arg(name).toUtf8(); error = git_repository_open(&repo, path); - if (error < 0) { - GIT_FAIL; - git_object_free(obj); - git_repository_free(repo); - return QString(); - } + GIT_CHK_CLEAN; error = git_revparse_single(&obj, repo, "HEAD"); - if (error < 0) { - GIT_FAIL; - git_object_free(obj); - git_repository_free(repo); - return QString(); - } + GIT_CHK_CLEAN; - const git_oid *oid = git_object_id(obj); - char buf[42]; + oid = git_object_id(obj); git_oid_tostr(buf, 41, oid); git_object_free(obj); git_repository_free(repo); return QString(buf); + +clean: + git_object_free(obj); + git_repository_free(repo); + return QString(); } #undef GIT_FAIL +#undef GIT_CHK_CLEAN