chore: upgrade ts2lua-unreal to v0.3.1 with lowercase lib/module.lua & lib/class.lua and commit framework refactor
This commit is contained in:
1 parent
783dccf53d
commit
3572f2da43
206 files changed
+14442
-13186
No files matched your search
@@ -0,0 +1,40 @@
|
||||
local ____exports = __module.env
|
||||
local M__framework_context_game_context = __MODULE__.Import("framework.context.game_context", __module)
|
||||
local GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
|
||||
local M__game_startup = __MODULE__.Import("game.startup", __module)
|
||||
local OpenMiniSettings = M__game_startup.OpenMiniSettings
|
||||
--- PIE / 启动地图玩家入口:绑定 LocalPlayer(0) 的 PlayerController 并打开首期最小设置窗口。
|
||||
function ____exports.OnBeginPlay(pc)
|
||||
local world = pc:GetWorld()
|
||||
local gi = UE.UGameplayStatics.GetGameInstance(pc)
|
||||
if gi == nil then
|
||||
return
|
||||
end
|
||||
local ctx = GetGameInstanceContext(gi)
|
||||
if ctx == nil then
|
||||
return
|
||||
end
|
||||
if world ~= nil and ctx:GetWorldContext().world ~= world then
|
||||
ctx:OnWorldCleanup(world)
|
||||
end
|
||||
ctx:GetOrCreateLocalPlayer(0, pc)
|
||||
OpenMiniSettings(ctx)
|
||||
end
|
||||
function ____exports.OnEndPlay(pc, _endPlayReason)
|
||||
local gi = UE.UGameplayStatics.GetGameInstance(pc)
|
||||
if gi == nil then
|
||||
return
|
||||
end
|
||||
local ctx = GetGameInstanceContext(gi)
|
||||
if ctx == nil then
|
||||
return
|
||||
end
|
||||
local lp = ctx:GetOrCreateLocalPlayer(0)
|
||||
if lp.playerController == pc then
|
||||
lp.playerController = nil
|
||||
end
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
|
||||
OpenMiniSettings = M__game_startup.OpenMiniSettings
|
||||
end
|
||||
@@ -0,0 +1,119 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||||
local ____exports = __module.env
|
||||
local M__share_base_logger = __MODULE__.Import("share.base.logger", __module)
|
||||
local Logger = M__share_base_logger.Logger
|
||||
local M__framework_resource_asset_catalog = __MODULE__.Import("framework.resource.asset_catalog", __module)
|
||||
local ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
||||
local M__framework_ui_ui_config = __MODULE__.Import("framework.ui.ui_config", __module)
|
||||
local RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
||||
local M__framework_ui_ui_window = __MODULE__.Import("framework.ui.ui_window", __module)
|
||||
local UIWindow = M__framework_ui_ui_window.UIWindow
|
||||
local M__game_setting_setting_service = __MODULE__.Import("game.setting.setting_service", __module)
|
||||
local SETTING_KEYS = M__game_setting_setting_service.SETTING_KEYS
|
||||
local logger = Logger("MiniSettingsWindow")
|
||||
____exports.MiniSettingsWindow = __TS__DefineClass("MiniSettingsWindow", __module)
|
||||
local MiniSettingsWindow = ____exports.MiniSettingsWindow
|
||||
MiniSettingsWindow.name = "MiniSettingsWindow"
|
||||
__TS__ClassExtends(MiniSettingsWindow, UIWindow)
|
||||
function MiniSettingsWindow.prototype.____constructor(self, ...)
|
||||
UIWindow.prototype.____constructor(self, ...)
|
||||
self.iconLoaded = false
|
||||
self.toggleClickCount = 0
|
||||
end
|
||||
function MiniSettingsWindow.prototype.OnBindWidgets(self)
|
||||
self.imgIcon = self:RequireWidget("ImgIcon")
|
||||
self.txtStatus = self:RequireWidget("TxtStatus")
|
||||
self.btnToggle = self:RequireWidget("BtnToggle")
|
||||
self.txtToggleLabel = self:RequireWidget("TxtToggleLabel")
|
||||
self.btnClose = self:RequireWidget("BtnClose")
|
||||
self:BindButtonClick(
|
||||
self.btnToggle,
|
||||
function()
|
||||
self:HandleToggleClicked()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnClose,
|
||||
function()
|
||||
self:Close()
|
||||
end
|
||||
)
|
||||
end
|
||||
function MiniSettingsWindow.prototype.OnPreShow(self)
|
||||
local settingSvc = self.ctx:GetService("setting")
|
||||
if settingSvc ~= nil then
|
||||
settingSvc.events.on.OnBoolSettingChanged(
|
||||
function(key, _val)
|
||||
if key == SETTING_KEYS.SOUND_ENABLED then
|
||||
self:RefreshDisplay()
|
||||
end
|
||||
end,
|
||||
self
|
||||
)
|
||||
end
|
||||
self:RefreshDisplay()
|
||||
self:LoadIconTexture()
|
||||
end
|
||||
function MiniSettingsWindow.prototype.LoadIconTexture(self)
|
||||
local resSvc = self.ctx:GetService("resource")
|
||||
if resSvc == nil then
|
||||
return
|
||||
end
|
||||
resSvc:LoadTextureAsync(
|
||||
ASSET_KEYS.MINI_SETTINGS_ICON,
|
||||
self,
|
||||
function(ok, tex, _lease, err)
|
||||
if not ok or tex == nil then
|
||||
logger:Warn("Failed to load MiniSettings icon texture", {err = err})
|
||||
return
|
||||
end
|
||||
self.iconLoaded = true
|
||||
if self.imgIcon ~= nil and self.imgIcon.SetBrushFromTexture ~= nil then
|
||||
self.imgIcon:SetBrushFromTexture(tex, false)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
function MiniSettingsWindow.prototype.HandleToggleClicked(self)
|
||||
self.toggleClickCount = self.toggleClickCount + 1
|
||||
local settingSvc = self.ctx:GetService("setting")
|
||||
if settingSvc ~= nil then
|
||||
local nextVal = settingSvc:ToggleSoundEnabled()
|
||||
logger:Info("Sound setting toggled", {soundEnabled = nextVal})
|
||||
end
|
||||
end
|
||||
function MiniSettingsWindow.prototype.RefreshDisplay(self)
|
||||
local settingSvc = self.ctx:GetService("setting")
|
||||
local ____temp_0
|
||||
if settingSvc ~= nil then
|
||||
____temp_0 = settingSvc:GetSoundEnabled()
|
||||
else
|
||||
____temp_0 = true
|
||||
end
|
||||
local soundEnabled = ____temp_0
|
||||
local statusText = soundEnabled and "Sound: ON" or "Sound: OFF"
|
||||
local btnText = soundEnabled and "Disable Sound" or "Enable Sound"
|
||||
if self.txtStatus ~= nil and self.txtStatus.SetText ~= nil then
|
||||
self.txtStatus:SetText(statusText)
|
||||
end
|
||||
if self.txtToggleLabel ~= nil and self.txtToggleLabel.SetText ~= nil then
|
||||
self.txtToggleLabel:SetText(btnText)
|
||||
end
|
||||
end
|
||||
RegisterUIConfig(____exports.MiniSettingsWindow, {
|
||||
name = "MiniSettingsWindow",
|
||||
assetKey = ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
||||
singleton = true,
|
||||
layer = "popup",
|
||||
type = "popup",
|
||||
cacheTag = "no_cache",
|
||||
blockWorldClick = true
|
||||
})
|
||||
function __module.UpdateImports()
|
||||
Logger = M__share_base_logger.Logger
|
||||
ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
||||
RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
||||
UIWindow = M__framework_ui_ui_window.UIWindow
|
||||
SETTING_KEYS = M__game_setting_setting_service.SETTING_KEYS
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local ____exports = __module.env
|
||||
local M__share_base_scoped_object = __MODULE__.Import("share.base.scoped_object", __module)
|
||||
local ScopedObject = M__share_base_scoped_object.ScopedObject
|
||||
local M__share_event_event_hub = __MODULE__.Import("share.event.event_hub", __module)
|
||||
local EventHub = M__share_event_event_hub.EventHub
|
||||
--- 阶段 0 冻结的首期全局布尔设置键
|
||||
____exports.SETTING_KEYS = {SOUND_ENABLED = "mini_settings.sound_enabled"}
|
||||
____exports.SettingService = __TS__DefineClass("SettingService", __module)
|
||||
local SettingService = ____exports.SettingService
|
||||
SettingService.name = "SettingService"
|
||||
__TS__ClassExtends(SettingService, ScopedObject)
|
||||
function SettingService.prototype.____constructor(self, saveManager, slotIdentity)
|
||||
ScopedObject.prototype.____constructor(self)
|
||||
self.events = __TS__New(EventHub, "SettingEvents")
|
||||
self.store = saveManager:GetOrOpenStore("setting", slotIdentity, 1)
|
||||
end
|
||||
function SettingService.prototype.GetStore(self)
|
||||
return self.store
|
||||
end
|
||||
function SettingService.prototype.GetBool(self, key, defaultValue)
|
||||
local val = self.store:Get(key)
|
||||
if type(val) == "boolean" then
|
||||
return val
|
||||
end
|
||||
return defaultValue
|
||||
end
|
||||
function SettingService.prototype.SetBool(self, key, value)
|
||||
local prev = self:GetBool(key, not value)
|
||||
self.store:Set(key, value)
|
||||
if prev ~= value then
|
||||
self.events.emit.OnBoolSettingChanged(key, value)
|
||||
end
|
||||
end
|
||||
function SettingService.prototype.GetSoundEnabled(self)
|
||||
return self:GetBool(____exports.SETTING_KEYS.SOUND_ENABLED, true)
|
||||
end
|
||||
function SettingService.prototype.SetSoundEnabled(self, enabled)
|
||||
self:SetBool(____exports.SETTING_KEYS.SOUND_ENABLED, enabled)
|
||||
end
|
||||
function SettingService.prototype.ToggleSoundEnabled(self)
|
||||
local nextVal = not self:GetSoundEnabled()
|
||||
self:SetSoundEnabled(nextVal)
|
||||
return nextVal
|
||||
end
|
||||
function SettingService.prototype.Flush(self)
|
||||
return self.store:Flush()
|
||||
end
|
||||
function SettingService.prototype.Dispose(self)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
self.store:Flush()
|
||||
self.events:Dispose()
|
||||
ScopedObject.prototype.Dispose(self)
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
ScopedObject = M__share_base_scoped_object.ScopedObject
|
||||
EventHub = M__share_event_event_hub.EventHub
|
||||
end
|
||||
@@ -0,0 +1,81 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local ____exports = __module.env
|
||||
local M__share_base_logger = __MODULE__.Import("share.base.logger", __module)
|
||||
local Logger = M__share_base_logger.Logger
|
||||
local M__framework_resource_resource_service = __MODULE__.Import("framework.resource.resource_service", __module)
|
||||
local CreateUEResourceService = M__framework_resource_resource_service.CreateUEResourceService
|
||||
local M__framework_storage_local_save = __MODULE__.Import("framework.storage.local_save", __module)
|
||||
local LocalSaveManager = M__framework_storage_local_save.LocalSaveManager
|
||||
local M__framework_storage_storage_backend = __MODULE__.Import("framework.storage.storage_backend", __module)
|
||||
local UEStorageBackend = M__framework_storage_storage_backend.UEStorageBackend
|
||||
local M__framework_ui_ui_delegate_bridge = __MODULE__.Import("framework.ui.ui_delegate_bridge", __module)
|
||||
local CreateUEUIDelegateBridge = M__framework_ui_ui_delegate_bridge.CreateUEUIDelegateBridge
|
||||
local M__framework_ui_ui_manager = __MODULE__.Import("framework.ui.ui_manager", __module)
|
||||
local UIManager = M__framework_ui_ui_manager.UIManager
|
||||
local M__game_setting_mini_settings_window = __MODULE__.Import("game.setting.mini_settings_window", __module)
|
||||
local MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
|
||||
local M__game_setting_setting_service = __MODULE__.Import("game.setting.setting_service", __module)
|
||||
local SettingService = M__game_setting_setting_service.SettingService
|
||||
local logger = Logger("Startup")
|
||||
--- 装配单个 GameInstanceContext 的全部首期框架服务(支持多 PIE 独立实例化):
|
||||
-- - LocalSaveManager(UE ULuaSaveGame + 跨 World 单调时钟 0.1s 合并写 + 退出 FlushAll)
|
||||
-- - SettingService(首期全局布尔设置键)
|
||||
-- - ResourceService(C++ ULuaResourceSubsystem:PIE Content/ 直读 + 发布包热更挂载扩展)
|
||||
-- - UIDelegateBridge(C++ ULuaUIEventSubsystem)
|
||||
-- - 默认 LocalPlayer(0) 的 UIManager
|
||||
function ____exports.AssembleGameInstanceServices(ctx)
|
||||
local storageBackend = __TS__New(UEStorageBackend)
|
||||
local saveManager = __TS__New(LocalSaveManager, storageBackend, ctx.scheduler)
|
||||
ctx:RegisterService("saveManager", saveManager)
|
||||
ctx:AddShutdownHook(function()
|
||||
saveManager:FlushAll()
|
||||
end)
|
||||
local settingService = __TS__New(SettingService, saveManager)
|
||||
ctx:RegisterService("setting", settingService)
|
||||
local resourceService = CreateUEResourceService(ctx)
|
||||
if resourceService ~= nil then
|
||||
ctx:RegisterService("resource", resourceService)
|
||||
end
|
||||
local uiDelegateBridge = CreateUEUIDelegateBridge(ctx)
|
||||
if uiDelegateBridge ~= nil then
|
||||
ctx:RegisterService("uiDelegateBridge", uiDelegateBridge)
|
||||
end
|
||||
local lp0 = ctx:GetOrCreateLocalPlayer(0)
|
||||
if resourceService ~= nil then
|
||||
lp0:RegisterService(
|
||||
"uiManager",
|
||||
__TS__New(UIManager, ctx, lp0, resourceService)
|
||||
)
|
||||
end
|
||||
local ____logger_Info_2 = logger.Info
|
||||
local ____ctx_contextId_1 = ctx.contextId
|
||||
local ____temp_0
|
||||
if resourceService ~= nil then
|
||||
____temp_0 = resourceService:IsPackagedMode()
|
||||
else
|
||||
____temp_0 = false
|
||||
end
|
||||
____logger_Info_2(logger, "Framework services assembled", {contextId = ____ctx_contextId_1, packagedResourceMode = ____temp_0})
|
||||
end
|
||||
function ____exports.GetPrimaryUIManager(ctx)
|
||||
local lp0 = ctx:GetOrCreateLocalPlayer(0)
|
||||
return lp0:GetService("uiManager")
|
||||
end
|
||||
function ____exports.OpenMiniSettings(ctx, onOpened)
|
||||
local uiMgr = ____exports.GetPrimaryUIManager(ctx)
|
||||
if uiMgr == nil then
|
||||
return nil
|
||||
end
|
||||
return uiMgr:ShowUI(MiniSettingsWindow, nil, onOpened)
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
Logger = M__share_base_logger.Logger
|
||||
CreateUEResourceService = M__framework_resource_resource_service.CreateUEResourceService
|
||||
LocalSaveManager = M__framework_storage_local_save.LocalSaveManager
|
||||
UEStorageBackend = M__framework_storage_storage_backend.UEStorageBackend
|
||||
CreateUEUIDelegateBridge = M__framework_ui_ui_delegate_bridge.CreateUEUIDelegateBridge
|
||||
UIManager = M__framework_ui_ui_manager.UIManager
|
||||
MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
|
||||
SettingService = M__game_setting_setting_service.SettingService
|
||||
end
|
||||
Reference in new issue
Block a user