Skip to content

公开 API 速查

本文列出常用公开 API。详细行为请查看对应主题文档。

引擎初始化

go
engine, err := galgo.NewEngine(galgo.Config{...}, nil)

Config 常用字段:

  • ScreenWidth
  • ScreenHeight
  • Title
  • FontPath
  • FontSize
  • SaveDir
  • TypewriterSpeed
  • Style
  • Translator
  • Hooks
  • GalleryCGs
  • GalleryBGMs
  • Achievements
  • StartupEnabled
  • StartupLogoText
  • StartupSubtitle
  • StartupMinFrames
  • LoadingText
  • LoadingMinFrames
  • TitleBgImagePath
  • TitleBgmPath
  • TitleBgmKey
  • TitleMenu
  • Settings
  • Cursor
  • Steam
  • SaveCfg

运行:

go
err := engine.Run(script, "start")

Script

go
script := galgo.NewScript()
script.AddNode("start", []galgo.Step{...})

Step 构造函数

文本:

  • Text(charName, textContent)
  • TextBubble(charName, textContent)
  • TextWithVoice(charName, textContent, voiceKey, voicePath)
  • TextBubbleWithVoice(charName, textContent, voiceKey, voicePath)

场景:

  • Bg(bgKey, bgPath)
  • Sprite(charName, spriteKey, spritePath, pos)
  • HideSprite(charName)
  • Camera(x, y, zoom, duration)

音频:

  • PlayBGM(bgmKey, bgmPath)
  • StopBGM()
  • PlaySE(seKey, sePath)

流程:

  • Choice(options...)
  • Jump(targetID)
  • Callback(func(*Engine) bool)

变量和输入:

  • SetVariable(key, value)
  • Input(varKey, prompt, options...)
  • InputDefault(value)
  • InputPlaceholder(value)
  • InputMaxRunes(max)
  • InputAllowEmpty()
  • InputSubmitLabel(label)
  • InputValidator(validator)

交互和解锁:

  • DragDrop(components, zones, options...)
  • UnlockAchievement(key)
  • SteamAchievementProgress(key, current, max)
  • RefreshSteamDLC(key)
  • MountSteamDLC(key)
  • BranchSteamDLC(key, installedTargetID, missingTargetID, mountIfInstalled)

Engine 常用方法

变量:

  • GetVar(key)
  • SetVar(key, val)
  • GetVariable(key)
  • SetVariable(key, value)
  • HasVar(key)
  • DeleteVar(key)
  • GetStringVar(key, fallback)
  • GetBoolVar(key, fallback)
  • GetIntVar(key, fallback)
  • GetFloatVar(key, fallback)

剧情和场景:

  • ShowDialogue(charName, textContent)
  • ShowDialogueWithMode(speakerID, charName, textContent, mode)
  • ShowChoices(opts)
  • SetBackground(key, path)
  • SetSprite(charName, key, path, pos)
  • HideSprite(charName)
  • JumpToNode(nodeID)
  • MoveCamera(x, y, zoom, durationTicks)
  • Shake(intensity, durationTicks)
  • Flash(color, durationTicks)

UI:

  • ShowToast(msg)
  • DrawText(screen, value, x, y, size, color)
  • ToggleFullscreen()
  • ApplyResolution(idx)
  • UpdateResolutions()

存档:

  • GetSaveState()
  • LoadSaveState(state)

画廊和成就:

  • UnlockCG(key, path)
  • UnlockBGM(key, path)
  • UnlockAchievement(key)
  • IsAchievementUnlocked(key)

Steam:

  • RefreshSteamDLCs()
  • IsSteamDLCInstalled(key)
  • MountSteamDLC(key)
  • SyncSteamAchievement(key)
  • SyncSteamAchievements()

ScreenAction

内置 action:

  • ShowScreen(target)
  • HideScreen()
  • StartGame()
  • ActionJump(nodeID)
  • SetVar(key, value)
  • ToggleVar(key)
  • Action(fn)
  • SensitiveAction(fn, sensitive)
  • Quit()
  • ReturnToTitle()

常用目标菜单:

  • MenuStateTitle
  • MenuStateHistory
  • MenuStateSave
  • MenuStateLoad
  • MenuStateConfig
  • MenuStateCGGallery
  • MenuStateMusicGallery
  • MenuStateAchievementGallery

ScreenValue

内置 value:

  • VariableValue
  • VolumeValue
  • TextSpeedValue
  • FullscreenValue
  • ResolutionValue
  • LanguageValue

这些 value 主要用于设置页组件,也可以用于自定义 UI。

标题页配置

go
title := galgo.DefaultTitleMenuConfig()
title.Items = []galgo.TitleMenuItem{...}
title.Modules = []galgo.TitleModule{...}

传入:

go
galgo.Config{TitleMenu: title}

设置页配置

go
settings := galgo.SettingsConfig{
    Title: "SETTINGS",
    Sections: []galgo.SettingsSection{...},
}

组件类型:

  • SettingsComponentSlider
  • SettingsComponentToggle
  • SettingsComponentOptions
  • SettingsComponentButton
  • SettingsComponentCustom

辅助包

样式:

go
style.DefaultUIStyle()

i18n:

go
i18n.NewTranslator()

配置:

go
config.DefaultPreferences()
config.DefaultSaveConfig("./saves")

文本特效:

go
effect.OutlineEffect(color.White, 2)
effect.ShadowEffect(color.Black, 2, 2)
effect.GlowEffect(color.Cyan, 6)
effect.GradientEffect(color.White, color.Cyan, false)

Released under the project license.