game-macro

核心系统文档

核心模块为 Game Macro 应用程序提供基础,处理配置管理、应用程序状态和核心功能。

English Version 中文版本

概述

核心系统负责:

关键组件

AppConfig.ahk

处理应用程序范围的配置管理。

关键函数

配置结构

[General]
Language=zh-CN
Version=0.1.3

[Logging]
Level=DEBUG
RotateSizeMB=10
RotateKeep=5

Core.ahk

管理全局应用程序状态并提供核心功能。

关键函数

应用程序状态结构

global App := Map(
    "ProfilesDir", A_ScriptDir "\\Profiles",
    "ExportDir", A_ScriptDir "\\Exports",
    "ConfigExt", ".ini",
    "CurrentProfile", "",
    "Profiles", [],
    "ProfileData", Core_DefaultProfileData(),
    "IsRunning", false,
    "BoundHotkeys", Map()
)

配置文件数据结构

{
    Name: "Default",
    StartHotkey: "F9",
    PollIntervalMs: 25,
    SendCooldownMs: 250,
    PickHoverEnabled: 1,
    PickHoverOffsetY: -60,
    PickHoverDwellMs: 120,
    PickConfirmKey: "LButton",
    Skills: [],
    Points: [],
    Rules: [],
    Buffs: [],
    Threads: [ { Id: 1, Name: "默认线程" } ],
    DefaultSkill: {
        Enabled: 0,
        SkillIndex: 0,
        CheckReady: 1,
        ThreadId: 1,
        CooldownMs: 600,
        PreDelayMs: 0,
        LastFire: 0
    },
    Rotation: {
        Enabled: 0,
        DefaultTrackId: 1,
        SwapKey: "",
        BusyWindowMs: 200,
        ColorTolBlack: 16,
        RespectCastLock: 1,
        BlackGuard: { 
            Enabled: 1, 
            SampleCount: 5, 
            BlackRatioThresh: 0.7,
            WindowMs: 120, 
            CooldownMs: 600, 
            MinAfterSendMs: 60,
            MaxAfterSendMs: 800, 
            UniqueRequired: 1 
        },
        Opener: { 
            Enabled: 0, 
            MaxDurationMs: 4000, 
            Watch: [] 
        }
    }
}

使用示例

初始化核心系统

#Include "modules\\core\\Core.ahk"
#Include "modules\\core\\AppConfig.ahk"

; 初始化配置
AppConfig_Init()

; 初始化核心系统
Core_Init()

; 加载配置文件
Core_LoadProfile("MyProfile")

访问配置

; 获取语言设置
language := AppConfig_Get("General", "Language", "zh-CN")

; 设置日志级别
AppConfig_Set("Logging", "Level", "DEBUG")

处理应用程序状态

; 检查应用程序是否正在运行
if (App["IsRunning"]) {
    ; 应用程序处于活动状态
}

; 访问当前配置文件数据
profile := App["ProfileData"]
startHotkey := profile["StartHotkey"]

API 参考

AppConfig 函数

AppConfig_Init()

初始化配置系统并加载配置文件。

参数:

返回值:

AppConfig_Get(section, key, default)

检索配置值。

参数:

返回值: 配置值或默认值

Core 函数

Core_Init()

初始化核心应用程序系统。

参数:

返回值:

Core_DefaultProfileData()

返回默认的配置文件数据结构。

参数:

返回值: 包含默认配置文件数据的映射

依赖关系

错误处理

核心系统包含以下错误处理:

最佳实践

  1. 在访问配置之前始终调用 AppConfig_Init()
  2. 使用 Core_DefaultProfileData() 作为新配置文件的模板
  3. 在保存之前验证配置文件数据
  4. 优雅地处理配置错误

相关模块

返回英文版本