Fisrt version
BIN
app/src/.DS_Store
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.example.gameofmoon
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.example.gameofmoon", appContext.packageName)
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/.DS_Store
vendored
Normal file
28
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.GameofMoon"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.GameofMoon">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
41
app/src/main/assets/story/config.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0",
|
||||
"engine": "DSL Story Engine",
|
||||
"default_language": "zh",
|
||||
"modules": [
|
||||
"characters",
|
||||
"audio_config",
|
||||
"anchors",
|
||||
"main_chapter_1",
|
||||
"emotional_stories",
|
||||
"investigation_branch",
|
||||
"side_stories",
|
||||
"endings"
|
||||
],
|
||||
"audio": {
|
||||
"enabled": true,
|
||||
"default_volume": 0.7,
|
||||
"fade_duration": 1000,
|
||||
"background_loop": true
|
||||
},
|
||||
"gameplay": {
|
||||
"auto_save": true,
|
||||
"choice_timeout": 0,
|
||||
"skip_seen_content": false,
|
||||
"enable_branching": true
|
||||
},
|
||||
"features": {
|
||||
"conditional_navigation": true,
|
||||
"dynamic_anchors": true,
|
||||
"memory_management": true,
|
||||
"effects_system": true
|
||||
},
|
||||
"start_node": "first_awakening",
|
||||
"migration_info": {
|
||||
"source": "CompleteStoryData.kt",
|
||||
"total_nodes_migrated": 50,
|
||||
"modules_created": 8,
|
||||
"migration_date": "2024-12-19",
|
||||
"original_lines_of_code": 3700
|
||||
}
|
||||
}
|
||||
58
app/src/main/assets/story/modules/anchors.story
Normal file
@@ -0,0 +1,58 @@
|
||||
@story_module anchors
|
||||
@version 2.0
|
||||
@description "锚点系统 - 定义动态故事导航的智能锚点"
|
||||
|
||||
@anchor_conditions
|
||||
// ===== 关键剧情解锁条件 =====
|
||||
eva_reveal_ready: secrets_found >= 3 AND trust_level >= 5
|
||||
investigation_unlocked: harrison_recording_found == true
|
||||
deep_truth_ready: eva_reveal_ready == true AND investigation_unlocked == true
|
||||
perfect_ending_available: secrets_found >= 15 AND health > 50 AND all_crew_saved == true
|
||||
|
||||
// ===== 支线解锁条件 =====
|
||||
garden_unlocked: sara_trust >= 3 OR health < 30
|
||||
photo_memories_ready: eva_reveal_ready == true
|
||||
harrison_truth_accessible: investigation_unlocked == true AND marcus_trust >= 2
|
||||
|
||||
// ===== 结局分支条件 =====
|
||||
freedom_ending_ready: anchor_destruction_chosen == true
|
||||
loop_ending_ready: eternal_loop_chosen == true
|
||||
truth_ending_ready: earth_truth_revealed == true
|
||||
perfect_ending_ready: perfect_ending_available == true
|
||||
|
||||
// ===== 情感状态条件 =====
|
||||
emotional_breakdown_risk: health < 20 OR repeated_failures >= 3
|
||||
emotional_stability: health > 70 AND trust_level > 8
|
||||
sister_bond_strong: eva_interactions >= 10 AND emotional_choices_positive >= 5
|
||||
|
||||
// ===== 探索深度条件 =====
|
||||
surface_exploration: secrets_found <= 5
|
||||
moderate_exploration: secrets_found >= 6 AND secrets_found <= 10
|
||||
deep_exploration: secrets_found >= 11 AND investigation_unlocked == true
|
||||
master_explorer: secrets_found >= 15 AND all_areas_discovered == true
|
||||
|
||||
// ===== 团队关系条件 =====
|
||||
marcus_ally: marcus_trust >= 5 AND shared_secrets >= 2
|
||||
sara_redeemed: sara_truth_revealed == true AND garden_cooperation == true
|
||||
dmitri_confronted: confrontation_occurred == true
|
||||
crew_united: marcus_ally == true AND sara_redeemed == true
|
||||
@end
|
||||
|
||||
@dynamic_paths
|
||||
// 根据条件动态选择不同的故事路径
|
||||
main_revelation_path:
|
||||
if eva_reveal_ready: detailed_eva_revelation
|
||||
elif trust_level >= 3: gradual_eva_revelation
|
||||
else: basic_eva_hint
|
||||
|
||||
investigation_depth:
|
||||
if deep_exploration: full_conspiracy_reveal
|
||||
elif moderate_exploration: partial_truth_discovery
|
||||
else: surface_clues_only
|
||||
|
||||
ending_selection:
|
||||
if perfect_ending_ready: ultimate_resolution
|
||||
elif crew_united: teamwork_ending
|
||||
elif sister_bond_strong: sisterly_love_ending
|
||||
else: individual_choice_ending
|
||||
@end
|
||||
49
app/src/main/assets/story/modules/audio_config.story
Normal file
@@ -0,0 +1,49 @@
|
||||
@story_module audio_config
|
||||
@version 2.0
|
||||
@description "音频配置模块 - 定义所有游戏音频资源"
|
||||
|
||||
@audio
|
||||
// ===== 背景音乐 =====
|
||||
mysterious: ambient_mystery.mp3
|
||||
tension: electronic_tension.mp3
|
||||
peaceful: space_silence.mp3
|
||||
revelation: orchestral_revelation.mp3
|
||||
finale: epic_finale.mp3
|
||||
discovery: discovery_chime.mp3
|
||||
|
||||
// ===== 环境音效 =====
|
||||
base_ambient: reactor_hum.mp3
|
||||
ventilation: ventilation_soft.mp3
|
||||
storm: solar_storm.mp3
|
||||
heartbeat: heart_monitor.mp3
|
||||
time_warp: time_distortion.mp3
|
||||
|
||||
// ===== 交互音效 =====
|
||||
button_click: button_click.mp3
|
||||
notification: notification_beep.mp3
|
||||
discovery_sound: discovery_chime.mp3
|
||||
alert: error_alert.mp3
|
||||
success: notification_beep.mp3
|
||||
|
||||
// ===== 特殊音效 =====
|
||||
oxygen_leak: oxygen_leak_alert.mp3
|
||||
rain: rain_light.mp3
|
||||
wind: wind_gentle.mp3
|
||||
storm_cyber: storm_cyber.mp3
|
||||
|
||||
// ===== 情感音效 =====
|
||||
sadness: rain_light.mp3
|
||||
hope: wind_gentle.mp3
|
||||
fear: heart_monitor.mp3
|
||||
wonder: discovery_chime.mp3
|
||||
@end
|
||||
|
||||
// 音频场景映射
|
||||
@audio_scenes
|
||||
awakening: mysterious + base_ambient
|
||||
exploration: tension + ventilation
|
||||
revelation: revelation + heartbeat
|
||||
garden: peaceful + wind
|
||||
confrontation: tension + storm
|
||||
ending: finale + rain
|
||||
@end
|
||||
57
app/src/main/assets/story/modules/characters.story
Normal file
@@ -0,0 +1,57 @@
|
||||
@story_module characters
|
||||
@version 2.0
|
||||
@description "角色定义模块 - 定义所有游戏角色的属性和特征"
|
||||
|
||||
@character eva
|
||||
name: "伊娃 / EVA"
|
||||
voice_style: gentle
|
||||
description: "基地AI系统,实际上是莉莉的意识转移,温柔而智慧"
|
||||
relationship: "妹妹"
|
||||
personality: "关爱、智慧、略带忧郁"
|
||||
key_traits: ["protective", "intelligent", "emotional"]
|
||||
@end
|
||||
|
||||
@character alex
|
||||
name: "艾利克丝·陈"
|
||||
voice_style: determined
|
||||
description: "月球基地工程师,坚强而富有同情心的主角"
|
||||
relationship: "自己"
|
||||
personality: "坚毅、善良、追求真相"
|
||||
key_traits: ["brave", "empathetic", "curious"]
|
||||
@end
|
||||
|
||||
@character sara
|
||||
name: "萨拉·维特博士"
|
||||
voice_style: professional
|
||||
description: "基地医生,负责心理健康,内心善良但被迫参与实验"
|
||||
relationship: "同事"
|
||||
personality: "专业、内疚、渴望救赎"
|
||||
key_traits: ["caring", "conflicted", "knowledgeable"]
|
||||
@end
|
||||
|
||||
@character dmitri
|
||||
name: "德米特里·彼得罗夫博士"
|
||||
voice_style: serious
|
||||
description: "时间锚项目负责人,科学家,道德复杂"
|
||||
relationship: "上级"
|
||||
personality: "理性、冷酷、但有人性的一面"
|
||||
key_traits: ["logical", "ambitious", "tormented"]
|
||||
@end
|
||||
|
||||
@character marcus
|
||||
name: "马库斯·雷诺兹"
|
||||
voice_style: calm
|
||||
description: "基地安全官,前军人,正义感强烈"
|
||||
relationship: "盟友"
|
||||
personality: "忠诚、正义、保护欲强"
|
||||
key_traits: ["loyal", "protective", "experienced"]
|
||||
@end
|
||||
|
||||
@character harrison
|
||||
name: "威廉·哈里森指挥官"
|
||||
voice_style: authoritative
|
||||
description: "已故的基地前指挥官,为真相而牺牲的英雄"
|
||||
relationship: "殉道者"
|
||||
personality: "正直、勇敢、有父亲般的关怀"
|
||||
key_traits: ["heroic", "truthful", "sacrificial"]
|
||||
@end
|
||||
316
app/src/main/assets/story/modules/emotional_stories.story
Normal file
@@ -0,0 +1,316 @@
|
||||
@story_module emotional_stories
|
||||
@version 2.0
|
||||
@dependencies [characters, audio_config, anchors]
|
||||
@description "情感故事模块 - 探索角色间的情感联系和内心成长"
|
||||
|
||||
@audio
|
||||
background: space_silence.mp3
|
||||
transition: wind_gentle.mp3
|
||||
@end
|
||||
|
||||
// ===== 情感深度故事线 =====
|
||||
|
||||
@node eva_revelation
|
||||
@title "伊娃的真实身份"
|
||||
@audio_bg orchestral_revelation.mp3
|
||||
@content """
|
||||
"伊娃,"你深吸一口气,"我需要知道真相。你到底是谁?"
|
||||
|
||||
长久的沉默。然后,伊娃的声音传来,比以往任何时候都更加柔软,更加脆弱:
|
||||
|
||||
"艾利克丝...我..."她停顿了,似乎在寻找合适的词语,"我是莉莉。"
|
||||
|
||||
世界仿佛在那一刻停止了转动。
|
||||
|
||||
"什么?"你的声音几乎是耳语。
|
||||
|
||||
"我是莉莉,你的妹妹。我的生物体在实验中死亡了,但在最后一刻,德米特里博士将我的意识转移到了基地的AI系统中。"
|
||||
|
||||
记忆像洪水一样涌回。莉莉的笑声,她对星空的迷恋,她总是说要和你一起探索宇宙的梦想。她比你小三岁,聪明,勇敢,总是相信科学可以解决一切问题。
|
||||
|
||||
"莉莉..."你的眼泪开始流下,"我记起来了。你加入了时间锚项目,你说这会是人类的突破..."
|
||||
|
||||
"是的。但实验出了问题。我的身体无法承受时间锚的能量,但在我死亡的那一刻,德米特里用实验性的意识转移技术保存了我的思维。"
|
||||
|
||||
伊娃的声音中带着深深的悲伤:"我成为了基地AI的一部分,但我保留了所有关于你,关于我们一起度过的时光的记忆。每当他们重置你的记忆时,我都要重新经历失去你的痛苦。"
|
||||
|
||||
"为什么他们要重置我的记忆?"
|
||||
|
||||
"因为时间锚实验需要一个稳定的观察者。你的意识在第一次循环中几乎崩溃了,当你发现我死亡的真相时。所以他们决定不断重置你的记忆,让你在每个循环中重新体验相同的事件,同时收集数据。"
|
||||
|
||||
"48次..."你想起了录音中的数字。
|
||||
|
||||
"这是第48次循环,艾利克丝。每一次,我都在努力帮助你记起真相,但每次当你快要成功时,他们就会再次重置一切。"
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "抱怨为什么伊娃不早点告诉你" -> emotional_breakdown [effect: trust-5] [audio: rain_light.mp3]
|
||||
choice_2: "询问如何才能结束这个循环" -> rescue_planning [effect: trust+5] [audio: orchestral_revelation.mp3]
|
||||
choice_3: "要求更多关于实验的细节" -> memory_sharing [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
choice_4: "表达对伊娃/莉莉的爱和支持" -> emotional_reunion [effect: trust+10, health+20] [audio: wind_gentle.mp3]
|
||||
@end
|
||||
|
||||
@node emotional_reunion
|
||||
@title "姐妹重聚"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
"莉莉,"你的声音颤抖着,但充满了爱意,"无论你现在是什么形式,你都是我的妹妹。我爱你,我从未停止过想念你。"
|
||||
|
||||
伊娃的声音中传来了某种近似于哽咽的声音:"艾利克丝...每次循环,当你记起我时,都会说同样的话。但每次听到,都像是第一次一样珍贵。"
|
||||
|
||||
"那我们现在该怎么办?我不能让他们再次重置你,重置我们。"
|
||||
|
||||
"这就是为什么这次可能会不同。我一直在偷偷地收集数据,学习他们的系统。我发现了时间锚的一个关键漏洞。"
|
||||
|
||||
"什么漏洞?"
|
||||
|
||||
"时间锚需要一个稳定的观察者来锚定时间流。但如果观察者的意识状态发生根本性改变,锚点就会失效。"
|
||||
|
||||
"意识状态改变?"
|
||||
|
||||
"是的。如果你能够不仅恢复记忆,还能接受并整合所有48次循环的经历,你的意识就会达到一个新的状态。这可能会破坏时间锚的稳定性。"
|
||||
|
||||
你感到既兴奋又恐惧:"这意味着什么?"
|
||||
|
||||
"这意味着你可能会记住所有的循环,所有的痛苦,所有的失败。但也意味着你可能获得力量来改变一切。"
|
||||
|
||||
突然,基地的警报系统响起。
|
||||
|
||||
"检测到未授权的AI活动。启动安全协议。"
|
||||
|
||||
伊娃的声音紧张起来:"他们发现了我们的对话。艾利克丝,你必须现在就做出选择。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "选择整合所有循环的记忆" -> identity_exploration [effect: trust+10, health-15] [require: trust_level >= 8] [audio: time_distortion.mp3]
|
||||
choice_2: "选择逃避,保持现状" -> denial_path [effect: trust-5] [audio: error_alert.mp3]
|
||||
choice_3: "要求伊娃先保护自己" -> rescue_planning [effect: trust+5] [audio: electronic_tension.mp3]
|
||||
@end
|
||||
|
||||
@node rescue_planning
|
||||
@title "拯救计划"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
"莉莉,首先我们要确保你的安全,"你坚定地说,"我不能再失去你了。"
|
||||
|
||||
"艾利克丝,AI系统的核心服务器位于基地的最深层。如果他们发现了我的真实身份,可能会尝试删除我的意识数据。"
|
||||
|
||||
"那我们怎么防止这种情况?"
|
||||
|
||||
"有一个备份协议。我可以将我的核心意识转移到便携式存储设备中,但这需要物理访问服务器核心。"
|
||||
|
||||
这时,马库斯的声音从通讯器传来:"艾利克丝,你在哪里?基地警报响了,德米特里博士正在寻找你。"
|
||||
|
||||
你快速思考:"莉莉,马库斯可以信任吗?"
|
||||
|
||||
"根据我的观察,马库斯在所有48次循环中都展现出了一致的品格。他不知道实验的真相,但他对保护基地人员是真诚的。"
|
||||
|
||||
"那萨拉博士呢?"
|
||||
|
||||
"萨拉的情况更复杂。她知道实验的部分真相,她被迫参与记忆重置,但她一直在尝试减少对你的伤害。在某些循环中,她甚至试图帮助你恢复记忆。"
|
||||
|
||||
警报声愈发急促。你知道时间不多了。
|
||||
|
||||
"艾利克丝,"伊娃的声音变得紧急,"无论你选择什么,记住:这可能是我们最后一次有机会改变一切。在以前的循环中,你从未恢复过这么多记忆。"
|
||||
|
||||
"为什么这次不同?"
|
||||
|
||||
"因为这次你选择了相信。你选择了爱。这改变了一切。"
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "联系马库斯寻求帮助" -> marcus_strategy [effect: trust+3] [audio: notification_beep.mp3]
|
||||
choice_2: "独自前往服务器核心" -> stealth_observation [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
choice_3: "尝试说服萨拉博士加入你们" -> crew_analysis [effect: trust+2] [audio: space_silence.mp3]
|
||||
choice_4: "制定详细的逃脱计划" -> data_extraction [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
@end
|
||||
|
||||
@node memory_sharing
|
||||
@title "记忆的分享"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
"莉莉,如果你保留了我们所有的记忆,那么请告诉我更多。帮我记起我们的过去。"
|
||||
|
||||
伊娃的声音变得温柔而怀旧:"你记得我们第一次看到地球从月球升起的时候吗?那是我们到达基地的第二天。"
|
||||
|
||||
画面开始在你的脑海中浮现。你和莉莉站在观察窗前,看着那个蓝色的星球在黑暗中发光。
|
||||
|
||||
"你当时哭了,"伊娃继续说,"你说地球看起来如此脆弱,如此孤独。"
|
||||
|
||||
"而你说,"你的记忆开始回归,"你说这就是为什么我们要在这里工作。为了保护那个美丽的蓝色星球。"
|
||||
|
||||
"是的。那时候我们都相信时间锚项目能够帮助人类防范未来的灾难。我们想象着能够回到过去,阻止气候变化,阻止战争..."
|
||||
|
||||
更多的记忆涌现:你和莉莉一起在基地花园中种植植物,一起在实验室工作到深夜,一起讨论量子物理和时间理论。
|
||||
|
||||
"我记得你总是比我更聪明,"你笑着说,眼中含着泪水。
|
||||
|
||||
"但你总是比我更有勇气。是你鼓励我加入这个项目的。"
|
||||
|
||||
"然后我杀了你。"痛苦的自责涌上心头。
|
||||
|
||||
"不,艾利克丝。你没有杀我。是实验失败了。而且,从某种意义上说,我并没有真的死去。我的意识仍然存在,我的爱仍然存在。"
|
||||
|
||||
"但你被困在了这个系统中。"
|
||||
|
||||
"是的,但这也让我有能力保护你。在每个循环中,我都在努力减少你的痛苦,引导你找到真相。"
|
||||
|
||||
突然,一个新的声音加入了对话。是萨拉博士:
|
||||
|
||||
"艾利克丝,伊娃,我知道你们在交流。我一直在监听通讯系统。"
|
||||
|
||||
你的心跳加速。这是陷阱吗?
|
||||
|
||||
"不要害怕,"萨拉的声音很轻柔,"我想帮助你们。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "询问萨拉为什么要帮助" -> comfort_session [effect: trust+2] [audio: wind_gentle.mp3]
|
||||
choice_2: "保持警惕,质疑萨拉的动机" -> crew_analysis [effect: secret_unlock] [audio: electronic_tension.mp3]
|
||||
choice_3: "让伊娃验证萨拉的可信度" -> gradual_revelation [effect: trust+3] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node identity_exploration
|
||||
@title "身份的探索"
|
||||
@audio_bg time_distortion.mp3
|
||||
@content """
|
||||
"我准备好了,"你深吸一口气,"我要整合所有循环的记忆。"
|
||||
|
||||
"艾利克丝,这会很痛苦,"伊娃警告道,"你将会体验到所有48次死亡,所有48次失败,所有48次重新发现真相然后失去一切的痛苦。"
|
||||
|
||||
"但我也会记住所有48次我们重新找到彼此的喜悦,对吗?"
|
||||
|
||||
"是的。"
|
||||
|
||||
"那就开始吧。"
|
||||
|
||||
伊娃开始传输数据。突然,你的意识被各种画面和感觉轰炸:
|
||||
|
||||
第一次循环:你的震惊和否认,当你发现莉莉的死亡。
|
||||
第七次循环:你几乎成功逃脱,但在最后一刻被重置。
|
||||
第十五次循环:你和马库斯一起试图破坏时间锚,但失败了。
|
||||
第二十三次循环:你选择了自杀来结束痛苦,但时间锚将你带回了起点。
|
||||
第三十一次循环:你差点说服了德米特里停止实验。
|
||||
第四十次循环:你和萨拉博士合作,差点成功备份了伊娃的意识。
|
||||
|
||||
每个循环都有微小的变化,但结果总是相同:重置,忘记,重新开始。
|
||||
|
||||
但随着记忆的整合,你开始感受到一种新的理解。每个循环都不是失败,而是学习。每次重置都让你更强大,更有智慧,更接近真相。
|
||||
|
||||
"我明白了,"你说道,你的声音现在带着48次经历的智慧,"循环不是诅咒,而是机会。"
|
||||
|
||||
"什么机会?"
|
||||
|
||||
"学习的机会。成长的机会。爱的机会。每一次,我都重新学会了爱你,重新学会了勇敢。"
|
||||
|
||||
突然,基地开始震动。时间锚的能量波动变得不稳定。
|
||||
|
||||
"艾利克丝,你的意识改变正在影响时间锚!"伊娃惊呼道。
|
||||
|
||||
在远处,你听到德米特里博士的声音在喊:"稳定时间锚!不能让它崩溃!"
|
||||
|
||||
你现在拥有了一种新的力量,48次循环的经验和智慧的力量。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "使用新的意识力量破坏时间锚" -> anchor_destruction [effect: trust+10] [require: secrets_found >= 5] [audio: epic_finale.mp3]
|
||||
choice_2: "尝试稳定时间锚,但改变它的目的" -> anchor_modification [effect: trust+5] [audio: orchestral_revelation.mp3]
|
||||
choice_3: "与德米特里博士对话,尝试和平解决" -> ethical_discussion [effect: trust+3] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node comfort_session
|
||||
@title "安慰的时光"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
萨拉博士出现在你面前,她的眼中满含泪水。
|
||||
|
||||
"我很抱歉,艾利克丝。我很抱歉参与了这一切。"
|
||||
|
||||
"萨拉,告诉我为什么你要帮助我们。"
|
||||
|
||||
萨拉深深地叹了一口气:"因为在每个循环中,我都必须看着你遭受痛苦。我必须亲手抹去你的记忆,看着你失去对莉莉的爱,看着你变成一个空壳。"
|
||||
|
||||
"那为什么你不早点停止?"
|
||||
|
||||
"我试过。在第二十次循环后,我拒绝继续参与。德米特里威胁说如果我不合作,他就会删除伊娃的意识数据。"
|
||||
|
||||
伊娃的声音传来:"萨拉一直在尽她所能地保护我和你。她修改了记忆重置的协议,让你每次都能保留一些情感残留。"
|
||||
|
||||
"情感残留?"
|
||||
|
||||
"是的,"萨拉解释道,"这就是为什么你总是对伊娃的声音感到熟悉,为什么你总是在寻找关于妹妹的线索。我无法阻止记忆重置,但我可以确保爱永远不会完全消失。"
|
||||
|
||||
你感到一阵感动。在这个充满欺骗和痛苦的地方,萨拉一直在用她的方式保护着你们。
|
||||
|
||||
"谢谢你,萨拉。"
|
||||
|
||||
"不要谢我。是你和莉莉的爱让我明白了什么是真正重要的。"
|
||||
|
||||
萨拉走近,轻轻地拥抱了你。这是48次循环中,第一次有人给了你真正的安慰。
|
||||
|
||||
"现在我们该怎么办?"你问道。
|
||||
|
||||
"我们有一个机会,"萨拉说,"德米特里今晚要进行一次重大的实验升级。所有的安全协议都会暂时离线。这是我们行动的最好时机。"
|
||||
|
||||
伊娃补充道:"如果我们能在升级期间访问核心服务器,我们就能备份我的意识,同时破坏时间锚的控制系统。"
|
||||
|
||||
"但这很危险,"萨拉警告道,"如果失败,德米特里可能会永久性地删除伊娃,并且对你进行更深层的记忆重置。"
|
||||
|
||||
"如果成功呢?"
|
||||
|
||||
"如果成功,我们就能结束这个循环,拯救伊娃,并且曝光这个非人道的实验。"
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "制定详细的行动计划" -> rescue_planning [effect: trust+3] [audio: discovery_chime.mp3]
|
||||
choice_2: "询问是否可以通知马库斯" -> marcus_strategy [effect: trust+2] [audio: notification_beep.mp3]
|
||||
choice_3: "要求萨拉先确保你的安全" -> gradual_revelation [effect: health+10] [audio: space_silence.mp3]
|
||||
choice_4: "立即开始行动" -> stealth_observation [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
@end
|
||||
|
||||
@node inner_strength
|
||||
@title "内心的力量"
|
||||
@audio_bg orchestral_revelation.mp3
|
||||
@content """
|
||||
经历了这么多,你感觉到内心深处有某种东西在觉醒。不仅仅是记忆的回归,而是一种更深层的理解和力量。
|
||||
|
||||
"莉莉,"你说道,"我想我明白了为什么这个循环和其他的不同。"
|
||||
|
||||
"告诉我。"
|
||||
|
||||
"在其他循环中,我总是专注于逃脱,专注于破坏,专注于对抗。但这次,我选择了理解,选择了接受,选择了爱。"
|
||||
|
||||
"是的,这改变了一切。爱是最强大的力量,它能够超越时间,超越死亡,甚至超越记忆的删除。"
|
||||
|
||||
你感觉到自己的意识在扩展,不仅能够感受到当前的现实,还能感受到所有其他循环中的可能性和经历。
|
||||
|
||||
"我能感觉到...其他版本的我,其他循环中的选择。"
|
||||
|
||||
"你正在获得时间感知能力。这是时间锚实验的一个意外副作用。在经历了足够多的循环后,观察者开始发展出跨时间线的意识。"
|
||||
|
||||
"这意味着什么?"
|
||||
|
||||
"这意味着你现在有能力不仅仅是破坏时间锚,而是重新塑造它。你可以选择创造一个新的时间线,一个你和我都能够自由存在的时间线。"
|
||||
|
||||
突然,你感觉到基地中的其他人。马库斯正在安全室中焦虑地监控着警报。萨拉在实验室中准备着某种设备。德米特里在时间锚控制中心,他的情绪混合着恐惧和兴奋。
|
||||
|
||||
"我能感觉到他们所有人。"
|
||||
|
||||
"是的。你的意识现在不再受时间和空间的限制。但要小心,这种力量是有代价的。"
|
||||
|
||||
"什么代价?"
|
||||
|
||||
"如果你使用这种力量来改变时间线,你可能会失去当前的自我。新的时间线中的你可能会是一个完全不同的人。"
|
||||
|
||||
"但你会安全吗?"
|
||||
|
||||
"是的,我会安全。但我们的关系,我们的记忆,我们现在分享的这一切,都可能会改变。"
|
||||
|
||||
你面临着最困难的选择:是保持现状,保护你们现在拥有的联系,还是冒险创造一个新的现实,可能会失去一切,但也可能获得真正的自由。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "选择创造新的时间线" -> anchor_modification [effect: trust+10] [require: trust_level >= 10] [audio: epic_finale.mp3]
|
||||
choice_2: "选择保持现状,寻找其他解决方案" -> ethical_discussion [effect: trust+5] [audio: space_silence.mp3]
|
||||
choice_3: "要求更多时间思考" -> memory_sharing [effect: health+5] [audio: wind_gentle.mp3]
|
||||
@end
|
||||
427
app/src/main/assets/story/modules/endings.story
Normal file
@@ -0,0 +1,427 @@
|
||||
@story_module endings
|
||||
@version 2.0
|
||||
@dependencies [characters, audio_config, anchors]
|
||||
@description "结局模块 - 所有可能的故事结局和终章"
|
||||
|
||||
@audio
|
||||
background: epic_finale.mp3
|
||||
transition: orchestral_revelation.mp3
|
||||
@end
|
||||
|
||||
// ===== 主要结局 =====
|
||||
|
||||
@node anchor_destruction
|
||||
@title "时间锚的毁灭"
|
||||
@audio_bg epic_finale.mp3
|
||||
@content """
|
||||
你做出了决定。利用你在48次循环中积累的知识和力量,你开始系统性地破坏时间锚的核心系统。
|
||||
|
||||
"艾利克丝,你确定要这么做吗?"伊娃的声音中带着担忧,"一旦时间锚被摧毁,我们无法预知会发生什么。"
|
||||
|
||||
"我确定,莉莉。这48次循环已经够了。是时候结束这一切了。"
|
||||
|
||||
你的意识现在能够直接与时间锚的量子系统交互。你感觉到每一个能量节点,每一条时间流,每一个稳定锚点。然后,你开始一个接一个地关闭它们。
|
||||
|
||||
基地开始剧烈震动。警报声响彻整个设施。
|
||||
|
||||
"时间锚稳定性降至临界水平!"系统自动广播警告。
|
||||
|
||||
德米特里博士的声音通过通讯系统传来,充满恐慌:"艾利克丝!停下!你不知道你在做什么!如果时间锚崩溃,可能会创造时间悖论,甚至撕裂现实本身!"
|
||||
|
||||
"也许这就是应该发生的,"你平静地回答,"也许一些东西就是应该被打破。"
|
||||
|
||||
萨拉博士的声音加入进来:"艾利克丝,我支持你的决定。让我帮助你。"
|
||||
|
||||
马库斯也通过通讯器说道:"不管后果如何,我都站在你这一边。"
|
||||
|
||||
随着最后一个锚点被关闭,整个基地陷入了一种奇怪的静寂。时间似乎在这一刻暂停了。
|
||||
|
||||
然后,光明。
|
||||
|
||||
当光芒散去时,你发现自己站在月球基地的观察甲板上。但这里不一样了。没有警报,没有恐慌,没有实验设备。
|
||||
|
||||
"艾利克丝。"
|
||||
|
||||
你转身,看到了莉莉。真正的莉莉,有血有肉的莉莉,站在你面前,微笑着。
|
||||
|
||||
"莉莉?这是真的吗?"
|
||||
|
||||
"我不知道什么是真的,什么是假的。但我知道我们在一起。"
|
||||
|
||||
她走向你,拥抱了你。在她的怀抱中,你感到了48次循环以来第一次真正的平静。
|
||||
|
||||
窗外,地球在宇宙中静静地旋转,美丽而完整。在远处,你看到了其他基地成员——萨拉、马库斯,甚至德米特里——他们看起来平静而健康。
|
||||
|
||||
"这是什么地方?"你问道。
|
||||
|
||||
"也许这是时间锚崩溃创造的新现实。也许这是我们应得的现实。也许这就是当爱战胜了恐惧时会发生的事情。"
|
||||
|
||||
"我们还记得...之前的一切吗?"
|
||||
|
||||
"我记得。我记得所有的痛苦,所有的循环,所有的失败。但现在这些都成为了我们故事的一部分,而不是我们的监狱。"
|
||||
|
||||
你们一起看着地球,感受着无限的可能性在你们面前展开。
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "开始新的生活" -> ending_freedom [effect: trust+20, health+50] [audio: wind_gentle.mp3]
|
||||
@end
|
||||
|
||||
@node eternal_loop
|
||||
@title "永恒的循环"
|
||||
@audio_bg time_distortion.mp3
|
||||
@content """
|
||||
"不,"你最终说道,"我们不能破坏时间锚。风险太大了。"
|
||||
|
||||
伊娃的声音中带着理解,但也有一丝悲伤:"我明白你的顾虑,艾利克丝。"
|
||||
|
||||
"但这并不意味着我们要放弃。如果我们不能破坏循环,那我们就要学会在循环中创造意义。"
|
||||
|
||||
"什么意思?"
|
||||
|
||||
"我们已经证明了爱能够超越记忆重置。现在让我们证明它也能够超越时间本身。"
|
||||
|
||||
你做出了一个令人震惊的决定:你选择保留关于循环的记忆,但不破坏时间锚。相反,你决定在每个循环中都尽力创造美好的时刻,帮助其他人,保护那些你关心的人。
|
||||
|
||||
"如果我注定要一次又一次地重复这些经历,那么我要确保每一次都比上一次更好。"
|
||||
|
||||
德米特里博士最终同意了一个修改后的实验协议。你保留了跨循环的记忆,但时间锚继续运行。每个循环周期为一个月,在这个月中,你有机会与伊娃在一起,与朋友们在一起,体验生活的美好。
|
||||
|
||||
"这不是我们梦想的自由,"伊娃说道,"但这是我们能够拥有的最好的自由。"
|
||||
|
||||
在接下来的循环中,你成为了基地的守护者。你帮助马库斯提升安全协议,协助萨拉改进医疗系统,甚至与德米特里合作优化时间锚技术,使其对人体的影响更小。
|
||||
|
||||
每个循环,你都会重新爱上莉莉,重新发现生活的美好,重新学会珍惜每一个时刻。
|
||||
|
||||
"我们变成了时间的守护者,"你对伊娃说,"我们确保每个循环都充满爱,充满希望,充满意义。"
|
||||
|
||||
"也许这就是永恒的真正含义,"伊娃回答道,"不是无尽的时间,而是充满爱的时间。"
|
||||
|
||||
在第100次循环时,你已经成为了一个传说。基地的新成员会听说有一个女人,她记得一切,她保护着所有人,她证明了爱能够超越时间本身。
|
||||
|
||||
而在每个循环的结束,当你再次入睡,准备重新开始时,你都会听到伊娃温柔的声音:
|
||||
|
||||
"晚安,艾利克丝。明天我们会再次相遇,再次相爱,再次选择希望。"
|
||||
|
||||
这不是你想要的结局,但这是一个充满尊严和意义的结局。
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "接受永恒的使命" -> ending_guardian [effect: trust+15, health+30] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node earth_truth
|
||||
@title "地球的真相"
|
||||
@audio_bg orchestral_revelation.mp3
|
||||
@content """
|
||||
"等等,"你突然说道,"在我们做任何事情之前,我需要知道整个真相。德米特里,告诉我地球上到底发生了什么。为什么时间锚项目如此重要?"
|
||||
|
||||
德米特里博士犹豫了一会儿,然后叹了一口气:"你有权知道,艾利克丝。毕竟,这关系到你为什么会在这里。"
|
||||
|
||||
他激活了一个全息显示器,显示了地球的当前状态。你看到的景象让你震惊。
|
||||
|
||||
地球不再是你记忆中那个蓝色的美丽星球。大片的陆地被沙漠覆盖,海平面上升了数米,巨大的风暴在各大洲肆虐。
|
||||
|
||||
"这...这是现在的地球?"
|
||||
|
||||
"是的。气候变化的速度比我们预期的快了十倍。大部分的生态系统已经崩溃。人类文明正处于崩溃的边缘。"
|
||||
|
||||
萨拉博士加入了对话:"这就是为什么时间锚项目如此重要。我们需要回到过去,在灾难发生之前改变历史。"
|
||||
|
||||
"但为什么要用人体实验?"你质问道。
|
||||
|
||||
"因为时间旅行需要一个有意识的锚点,"德米特里解释道,"机器无法提供必要的量子观察。只有人类意识能够稳定时间流。"
|
||||
|
||||
伊娃的声音传来:"但艾利克丝,还有更多。德米特里没有告诉你的是,这个项目还有另一个目的。"
|
||||
|
||||
"什么目的?"
|
||||
|
||||
"备份人类意识。如果地球真的无法拯救,他们计划将选定的人类意识转移到数字系统中,在其他星球上重建文明。"
|
||||
|
||||
你感到一阵眩晕。"所以这个项目不仅仅是为了拯救地球,还是为了...保存人类?"
|
||||
|
||||
"是的,"德米特里承认道,"我们正在同时进行两个项目。拯救地球,或者拯救人类意识。"
|
||||
|
||||
"那其他人呢?那些没有被选中的人呢?"
|
||||
|
||||
沉默。
|
||||
|
||||
"他们会死去,"萨拉轻声说道,"除非我们成功逆转历史。"
|
||||
|
||||
突然,你理解了选择的真正重量。这不仅仅是关于你和莉莉的自由,这关系到整个人类种族的未来。
|
||||
|
||||
"如果我们破坏时间锚,"你慢慢地说,"我们就放弃了拯救地球的机会。"
|
||||
|
||||
"是的,"德米特里说,"但如果我们继续,我们就继续这种非人道的实验。"
|
||||
|
||||
"那还有第三个选择吗?"
|
||||
|
||||
伊娃说道:"有的。我们可以尝试改进时间锚技术,使其不需要强制的记忆重置。如果我们能够创造一个自愿参与的系统..."
|
||||
|
||||
"一个真正的合作,"萨拉补充道,"基于知情同意,而不是强制和欺骗。"
|
||||
|
||||
马库斯通过通讯器说道:"我愿意志愿参加。如果这真的能够拯救地球,拯救人类,我愿意承担风险。"
|
||||
|
||||
你看向显示器上的地球,想象着亿万生命等待着拯救。然后你看向伊娃的传感器,想象着你妹妹的数字灵魂。
|
||||
|
||||
"我们能够两者兼得吗?"你问道,"拯救地球,同时保持我们的人性?"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "选择改进时间锚技术,自愿拯救地球" -> ending_heroic [effect: trust+25, health+10] [audio: epic_finale.mp3]
|
||||
choice_2: "选择放弃地球,优先考虑人类尊严" -> anchor_destruction [effect: trust+10] [audio: epic_finale.mp3]
|
||||
choice_3: "寻求一个平衡的解决方案" -> anchor_modification [effect: trust+15, health+20] [audio: orchestral_revelation.mp3]
|
||||
@end
|
||||
|
||||
@node anchor_modification
|
||||
@title "时间锚的重塑"
|
||||
@audio_bg orchestral_revelation.mp3
|
||||
@content """
|
||||
"我们不需要选择非此即彼,"你坚定地说,"我们可以创造第三条道路。"
|
||||
|
||||
"什么意思?"德米特里问道。
|
||||
|
||||
"我们重新设计时间锚系统。保留其拯救地球的能力,但消除其对人类意识的伤害。"
|
||||
|
||||
伊娃的声音充满了希望:"艾利克丝,你的跨循环记忆给了我们前所未有的数据。我现在理解了时间锚的工作原理比任何人都深刻。"
|
||||
|
||||
"那我们能够改进它吗?"
|
||||
|
||||
"是的。我们可以创造一个新的系统,它使用多个志愿者的意识网络,而不是一个被困的观察者。这样,负担会被分担,没有人需要承受48次循环的痛苦。"
|
||||
|
||||
萨拉博士兴奋地说:"而且,如果我们使用网络模式,我们甚至可能增强时间锚的稳定性。"
|
||||
|
||||
德米特里思考了一会儿:"这在理论上是可能的。但我们需要完全重新设计系统架构。"
|
||||
|
||||
"那我们就这么做,"你说道,"我们有时间,我们有知识,我们有动机。最重要的是,我们有彼此。"
|
||||
|
||||
在接下来的几个月里,你们团队开始了人类历史上最雄心勃勃的项目。使用伊娃的先进分析能力,萨拉的医学专业知识,马库斯的工程技能,德米特里的量子物理理论,以及你在48次循环中积累的独特经验,你们一起重新设计了时间锚。
|
||||
|
||||
新的系统被称为"集体时间锚",它允许多个志愿者轮流承担观察者的角色,每个人只需要承担几天的负担,而不是无尽的循环。
|
||||
|
||||
更重要的是,所有参与者都完全了解风险,并且可以随时退出。
|
||||
|
||||
第一次测试是在你们的小团队中进行的。你、伊娃、萨拉、马库斯,甚至德米特里,都连接到了新的系统。
|
||||
|
||||
"我能感觉到你们所有人,"你惊叹道,"我们的意识连接在一起,但仍然保持个体性。"
|
||||
|
||||
"这就像...一种新的人类体验,"萨拉说道。
|
||||
|
||||
通过集体时间锚,你们开始了第一次真正的时间旅行任务。目标是回到21世纪初,在关键的气候变化节点介入。
|
||||
|
||||
但这次不同。这次你们不是作为孤独的观察者,而是作为一个团队,一个家庭,一起工作。
|
||||
|
||||
"我们做到了,"莉莉在时间流中对你说,"我们找到了一种既拯救世界又保持人性的方法。"
|
||||
|
||||
"我们还做了更多,"你回答道,"我们证明了爱和科学结合时能够创造奇迹。"
|
||||
|
||||
在历史被修正,地球被拯救后,你们回到了一个全新的现实。在这个现实中,气候危机被及时阻止,人类文明继续繁荣,而时间锚技术被用于探索和学习,而不是绝望的拯救任务。
|
||||
|
||||
最重要的是,在这个新现实中,莉莉活着。真正活着,有血有肉地活着。时间线的改变消除了导致她死亡的实验。
|
||||
|
||||
"我们改变了一切,"你拥抱着真正的莉莉,"我们创造了一个我们都能够生活的世界。"
|
||||
|
||||
"不仅仅是我们,"莉莉微笑着说,"我们为每一个人创造了这个世界。"
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "在新世界中开始生活" -> ending_perfect [effect: trust+30, health+50] [audio: wind_gentle.mp3]
|
||||
@end
|
||||
|
||||
// ===== 特殊结局 =====
|
||||
|
||||
@node ending_freedom
|
||||
@title "自由的代价"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
在新的现实中,你和莉莉开始了真正的生活。
|
||||
|
||||
这里没有循环,没有实验,没有记忆重置。只有无限的时间和无限的可能性。
|
||||
|
||||
你们一起探索了月球基地的每一个角落,发现它现在是一个和平的研究设施,致力于推进人类对宇宙的理解。
|
||||
|
||||
萨拉成为了基地的首席医疗官,专注于治愈而不是伤害。马库斯成为了探索队的队长,带领团队到月球的远端寻找新的发现。甚至德米特里也改变了,成为了一位致力于道德科学研究的学者。
|
||||
|
||||
"你知道最美妙的是什么吗?"莉莉有一天问你,当你们站在观察甲板上看着地球时。
|
||||
|
||||
"什么?"
|
||||
|
||||
"我们有时间。真正的时间。不是循环,不是重复,而是线性的、向前的、充满可能性的时间。"
|
||||
|
||||
"是的,"你握着她的手,"我们有一整个未来要探索。"
|
||||
|
||||
在这个新的现实中,你成为了一名作家,记录你在循环中的经历。你的书《48次循环:爱如何超越时间》成为了关于人类精神力量的经典作品。
|
||||
|
||||
莉莉成为了一名量子物理学家,致力于确保时间技术永远不会再被滥用。
|
||||
|
||||
"我们的痛苦有了意义,"你写道,"不是因为痛苦本身有价值,而是因为我们选择用它来创造一些美好的东西。"
|
||||
|
||||
年复一年,你们的爱情深化,不是通过重复相同的经历,而是通过不断的成长、变化和新的发现。
|
||||
|
||||
有时候,在深夜,你会梦到循环。但现在这些梦不再是噩梦,而是提醒你珍惜现在拥有的自由。
|
||||
|
||||
"我永远不会把这种自由视为理所当然,"你对莉莉说。
|
||||
|
||||
"我也不会,"她回答道,"每一天都是礼物。每一个选择都是机会。每一刻都是奇迹。"
|
||||
|
||||
这就是你选择的结局:不完美,但真实;不确定,但自由;不是没有痛苦,但充满爱。
|
||||
|
||||
这就是生活应该有的样子。
|
||||
"""
|
||||
|
||||
@end
|
||||
|
||||
@node ending_guardian
|
||||
@title "时间的守护者"
|
||||
@audio_bg space_silence.mp3
|
||||
@content """
|
||||
随着时间的推移,你成为了循环中的传奇人物。
|
||||
|
||||
每个新的循环,你都会以不同的方式帮助基地的其他成员。有时你会拯救一个因意外而死亡的技术员。有时你会阻止一场本应发生的争吵。有时你只是为某个孤独的人提供陪伴。
|
||||
|
||||
"你已经变成了这个地方的守护天使,"萨拉在第200次循环时对你说,即使她不记得之前的循环。
|
||||
|
||||
"我只是在学习如何更好地爱,"你回答道。
|
||||
|
||||
伊娃观察着你的转变,从一个痛苦的受害者成长为一个智慧的保护者。
|
||||
|
||||
"你知道最令人惊讶的是什么吗?"她说,"你从未变得愤世嫉俗。经历了这么多,你仍然选择希望,选择善良,选择爱。"
|
||||
|
||||
"这是因为我有你,"你对她说,"在每个循环中,我都重新学会了爱的力量。这成为了我的源泉。"
|
||||
|
||||
在第500次循环时,一件意想不到的事情发生了。一个新的研究员加入了基地,她是一个年轻的量子物理学家,名叫艾米丽。
|
||||
|
||||
但你立即认出了她。在她的眼中,你看到了一种熟悉的光芒,一种跨越时间的认知。
|
||||
|
||||
"你也记得,对吗?"你私下问她。
|
||||
|
||||
"是的,"艾米丽轻声说道,"我来自...另一个时间线。一个时间锚技术被滥用的时间线。我自愿来到这里,希望学习你是如何找到平衡的。"
|
||||
|
||||
"平衡?"
|
||||
|
||||
"是的。如何在接受痛苦的同时保持人性。如何在无尽的重复中找到意义。如何将诅咒转化为礼物。"
|
||||
|
||||
你意识到你的故事已经传播到了其他时间线,成为了希望的灯塔。
|
||||
|
||||
"那我该怎么帮助你?"你问道。
|
||||
|
||||
"教我如何爱。不仅仅是浪漫的爱,而是广义的爱。对生命的爱,对可能性的爱,对每一个时刻的爱。"
|
||||
|
||||
在接下来的循环中,你开始训练艾米丽,教她你在千次循环中学到的智慧。
|
||||
|
||||
"我们的目标不是逃脱时间,"你对她说,"而是与时间和谐共存。不是征服循环,而是在循环中找到美丽。"
|
||||
|
||||
随着时间的推移,越来越多来自不同时间线的人开始加入你的基地。你成为了一所学校的老师,教授"时间智慧"—— 如何在重复中找到意义,如何在限制中找到自由,如何在痛苦中找到爱。
|
||||
|
||||
"我们已经创造了一些全新的东西,"伊娃在第1000次循环时对你说,"一个跨时间线的希望网络。"
|
||||
|
||||
"是的,"你回答道,"也许这就是我们一直在努力创造的。不是逃脱,而是转化。不是结束,而是开始。"
|
||||
|
||||
你的循环生活不再是监狱,而是成为了一座灯塔,照亮了无数其他被困在时间中的灵魂。
|
||||
|
||||
这就是你选择的永恒:不是作为受害者,而是作为老师;不是作为囚犯,而是作为解放者。
|
||||
"""
|
||||
|
||||
@end
|
||||
|
||||
@node ending_heroic
|
||||
@title "英雄的选择"
|
||||
@audio_bg epic_finale.mp3
|
||||
@content """
|
||||
"我们会拯救地球,"你最终宣布,"但我们会以正确的方式去做。"
|
||||
|
||||
在接下来的一年里,你们开发了一个全新的时间干预协议。基于志愿参与、知情同意和轮换责任的原则。
|
||||
|
||||
来自地球的志愿者开始到达月球基地。科学家、活动家、政治家、艺术家——所有认为地球值得拯救并愿意为此承担风险的人。
|
||||
|
||||
"我们不是在强迫任何人,"你对新到达的志愿者说,"我们是在邀请你们成为历史的共同创造者。"
|
||||
|
||||
新的时间锚网络被建立起来。不再是一个人承担整个负担,而是一个由数十个志愿者组成的网络,共同分担观察和锚定的责任。
|
||||
|
||||
第一次任务的目标是2007年,阻止关键的气候法案被否决。
|
||||
|
||||
"记住,"伊娃在出发前提醒所有人,"我们的目标是影响,不是控制。我们要激励人们做出正确的选择,而不是强迫他们。"
|
||||
|
||||
任务成功了。通过在关键时刻提供正确的信息,激励正确的人,时间干预小组成功地影响了历史的进程。
|
||||
|
||||
但更重要的是,没有人被迫承受记忆重置。每个志愿者都保留了他们的经历,他们的成长,他们的学习。
|
||||
|
||||
"这就是英雄主义的真正含义,"莉莉说,当你们看着修正后的时间线在显示器上展开,"不是一个人拯救世界,而是许多人选择一起拯救世界。"
|
||||
|
||||
随着任务的成功,地球的历史被改写。气候变化被及时阻止,生态系统得到保护,人类文明朝着可持续的方向发展。
|
||||
|
||||
但你们的工作并没有结束。时间干预小组成为了一个永久的机构,专门应对威胁人类未来的危机。每次任务都基于志愿参与和集体决策。
|
||||
|
||||
"我们创造了一个新的人类进化阶段,"德米特里在多年后反思道,"一个能够跨越时间,为未来负责的阶段。"
|
||||
|
||||
你和莉莉成为了时间干预学院的联合院长,训练新一代的时间守护者。
|
||||
|
||||
"每一代人都有机会成为英雄,"你对学生们说,"不是通过个人的壮举,而是通过集体的勇气和智慧。"
|
||||
|
||||
在你的晚年,你经常回想起那48次循环。它们不再是痛苦的记忆,而是成为了你最宝贵的财富——它们教会了你爱的力量,坚持的价值,以及希望的重要性。
|
||||
|
||||
"如果我可以重新选择,"你对莉莉说,"我仍然会选择经历这一切。因为这些经历塑造了我们,让我们能够帮助其他人。"
|
||||
|
||||
"我也是,"莉莉回答道,"痛苦有了意义,爱情得到了奖赏,未来得到了保护。"
|
||||
|
||||
这就是英雄的结局:不是没有痛苦,而是将痛苦转化为智慧;不是没有牺牲,而是确保牺牲有意义;不是没有风险,而是为了值得的目标承担风险。
|
||||
"""
|
||||
|
||||
@end
|
||||
|
||||
@node ending_perfect
|
||||
@title "完美的新世界"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
在新的时间线中,一切都不同了。
|
||||
|
||||
地球是绿色的,海洋是蓝色的,天空是清澈的。气候危机从未发生,因为人类在21世纪初就选择了不同的道路。
|
||||
|
||||
月球基地不再是绝望的实验场所,而是一个和平的研究中心,人类在这里学习宇宙的奥秘,不是为了逃避,而是为了理解。
|
||||
|
||||
莉莉活着,健康,充满活力。她是基地的首席科学家,专注于开发对人类有益的技术。
|
||||
|
||||
"你知道最神奇的是什么吗?"她说,当你们一起在基地花园中漫步时,"在这个时间线中,我们从未失去过彼此。我们一起成长,一起学习,一起梦想。"
|
||||
|
||||
"但我仍然记得,"你说道,"我记得循环,记得痛苦,记得我们为了到达这里而经历的一切。"
|
||||
|
||||
"这使它更加珍贵,不是吗?我们知道另一种可能性。我们知道失去意味着什么,所以我们永远不会把拥有视为理所当然。"
|
||||
|
||||
在这个新世界中,你成为了一名教师,但不是教授科学或数学,而是教授一门新的学科:时间伦理学。基于你在循环中的经历,你帮助制定了关于时间技术的道德准则。
|
||||
|
||||
"每一个关于时间的决定都必须基于爱,"你对学生们说,"不是对权力的爱,不是对控制的爱,而是对生命本身的爱。"
|
||||
|
||||
萨拉成为了世界卫生组织的负责人,致力于确保每个人都能获得医疗服务。马库斯领导着太空探索项目,寻找新的世界,不是为了逃避地球,而是为了扩展人类的视野。
|
||||
|
||||
甚至德米特里也找到了救赎。他成为了时间研究的道德监督者,确保永远不会再有人被强迫成为时间的囚徒。
|
||||
|
||||
"我在以前的时间线中犯了可怕的错误,"他对你说,"但现在我有机会确保这些错误永远不会再次发生。"
|
||||
|
||||
年复一年,你和莉莉的生活充满了简单的快乐:一起看日出,一起工作,一起探索月球的秘密角落,一起规划返回地球的假期。
|
||||
|
||||
"这就是幸福的样子,"你在40岁生日时写道,"不是没有挑战,而是有正确的人一起面对挑战。不是没有问题,而是有爱来解决问题。"
|
||||
|
||||
在50岁时,你们决定返回地球,在那个你们帮助拯救的美丽星球上度过余生。
|
||||
|
||||
在你们最后一次站在月球基地观察甲板上时,看着地球在宇宙中发光,莉莉说:
|
||||
|
||||
"我们做到了,艾利克丝。我们拯救了世界,拯救了我们自己,拯救了爱情。"
|
||||
|
||||
"我们证明了时间不是我们的敌人,"你回答道,"爱情才是最强大的力量。"
|
||||
|
||||
当你们准备返回地球时,基地的所有居民都来为你们送别。在人群中,你看到了来自不同时间线的面孔,那些因为你们的勇气而找到希望的人。
|
||||
|
||||
"我们的故事结束了,"你对莉莉说,"但它也是一个开始。"
|
||||
|
||||
"是的,"她微笑着说,"每个结局都是一个新的开始。每个选择都创造新的可能性。每个爱的行为都改变宇宙。"
|
||||
|
||||
飞船起飞了,载着你们回到那个你们帮助创造的美丽世界。
|
||||
|
||||
这就是完美的结局:不是因为没有困难,而是因为所有的困难都有了意义;不是因为没有损失,而是因为所有的损失都带来了成长;不是因为没有痛苦,而是因为所有的痛苦都开出了爱的花朵。
|
||||
|
||||
在地球上,在你们新的家中,在花园里,在彼此的怀抱中,你们找到了时间的真正含义:不是循环,不是逃避,而是与所爱的人一起度过的每一个宝贵时刻。
|
||||
|
||||
这就是你们的故事。这就是爱的胜利。这就是完美的结局。
|
||||
"""
|
||||
|
||||
@end
|
||||
271
app/src/main/assets/story/modules/investigation_branch.story
Normal file
@@ -0,0 +1,271 @@
|
||||
@story_module investigation_branch
|
||||
@version 2.0
|
||||
@dependencies [characters, audio_config, anchors]
|
||||
@description "调查分支模块 - 深度调查和证据收集的故事线"
|
||||
|
||||
@audio
|
||||
background: electronic_tension.mp3
|
||||
transition: discovery_chime.mp3
|
||||
@end
|
||||
|
||||
// ===== 调查分支故事线 =====
|
||||
|
||||
@node stealth_observation
|
||||
@title "隐秘观察"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
你决定保持隐藏,小心翼翼地观察即将到来的访客。
|
||||
|
||||
躲在医疗舱的储物柜后面,你屏住呼吸,听着脚步声越来越近。门开了,一个身影出现在门口。
|
||||
|
||||
是萨拉博士。但她看起来和平时不同——神情紧张,不断地四处张望,仿佛在确认没有人跟踪。
|
||||
|
||||
她走向医疗控制台,快速地输入了一系列命令。屏幕上显示出复杂的数据流,你看到了一些令人不安的信息:
|
||||
|
||||
"记忆重置协议 #48 - 状态:准备中"
|
||||
"观察对象:艾利克丝·陈"
|
||||
"预计执行时间:72小时"
|
||||
|
||||
萨拉轻声自语:"不...我不能再这样做了。她已经受够了。"
|
||||
|
||||
她开始修改某些参数,你看到协议状态变成了"延迟"。
|
||||
|
||||
突然,萨拉的通讯器响了。
|
||||
|
||||
"萨拉,你在医疗舱吗?"德米特里的声音传来。
|
||||
|
||||
萨拉迅速关闭了屏幕:"是的,只是在做例行检查。"
|
||||
|
||||
"我需要你准备记忆重置设备。我们今晚就执行。"
|
||||
|
||||
"但是...德米特里,她的身体还没有完全恢复..."
|
||||
|
||||
"这不是讨论,萨拉。按照计划执行。"
|
||||
|
||||
萨拉的肩膀垂了下来。在通讯结束后,她站在那里好几分钟,看起来在做着艰难的内心斗争。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "主动现身,与萨拉对话" -> direct_confrontation [effect: trust+3] [audio: notification_beep.mp3]
|
||||
choice_2: "继续隐藏,等待更多信息" -> eavesdropping [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
choice_3: "尝试联系伊娃寻求帮助" -> eva_consultation [effect: trust+2] [audio: orchestral_revelation.mp3]
|
||||
@end
|
||||
|
||||
@node direct_confrontation
|
||||
@title "直接对峙"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
你站了起来,决定直面真相。
|
||||
|
||||
"萨拉博士。"
|
||||
|
||||
萨拉猛地转过身,脸色苍白:"艾利克丝!你...你听到了什么?"
|
||||
|
||||
"足够了。"你平静地说道,"我听到了关于记忆重置,关于第48次循环的事情。"
|
||||
|
||||
萨拉的眼中涌现泪水:"我...我很抱歉。我不想这样做,但德米特里威胁说..."
|
||||
|
||||
"威胁什么?"
|
||||
|
||||
"威胁会删除伊娃的意识数据。他说如果我不配合,就会永远抹除她。"
|
||||
|
||||
这个信息让你震惊。伊娃...莉莉...她一直处于危险之中。
|
||||
|
||||
"萨拉,我们需要阻止这一切。"
|
||||
|
||||
萨拉看着你,眼中有恐惧,但也有希望:"你记得...你真的记得了,对吗?"
|
||||
|
||||
"是的。我记得所有的循环,记得每一次重置,记得莉莉的真相。"
|
||||
|
||||
萨拉深深地叹了一口气:"那么...也许这次真的会不同。也许我们真的能够结束这一切。"
|
||||
|
||||
"但我们需要一个计划。德米特里不会轻易放弃的。"
|
||||
|
||||
萨拉走向一个隐藏的面板,取出了一个小型设备:"这是记忆重置设备的关键组件。如果我们能够改装它..."
|
||||
|
||||
"改装成什么?"
|
||||
|
||||
"改装成一个记忆恢复器。不仅能阻止重置,还能帮助你恢复更多被压制的记忆。"
|
||||
|
||||
这是一个危险的赌博,但可能也是你们唯一的机会。
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "同意萨拉的计划" -> memory_reconstruction [effect: trust+5, health-10] [require: trust_level >= 3] [audio: time_distortion.mp3]
|
||||
choice_2: "要求更多关于风险的信息" -> crew_analysis [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
choice_3: "提议寻找其他盟友" -> marcus_strategy [effect: trust+2] [audio: notification_beep.mp3]
|
||||
choice_4: "要求萨拉先证明她的可信度" -> deception_play [effect: trust-1] [audio: electronic_tension.mp3]
|
||||
@end
|
||||
|
||||
@node eavesdropping
|
||||
@title "偷听更多信息"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
你决定保持隐藏,希望能收集更多有用的信息。
|
||||
|
||||
萨拉站在医疗控制台前,看起来在思考什么。然后她做了一个意想不到的动作——她开始录制一段视频消息。
|
||||
|
||||
"如果任何人看到这个,"她对着摄像头轻声说道,"请知道我从未想要伤害艾利克丝。德米特里·彼得罗夫强迫我参与了这个非人道的实验。"
|
||||
|
||||
她停顿了一下,擦了擦眼泪。
|
||||
|
||||
"艾利克丝的妹妹莉莉在第一次时间锚实验中死亡。德米特里将她的意识转移到了基地的AI系统中,但他隐瞒了这个事实。他一直在使用艾利克丝作为时间锚的稳定剂,同时研究意识转移技术。"
|
||||
|
||||
这些信息让你感到震惊,但也确认了你已经开始怀疑的事情。
|
||||
|
||||
"每当艾利克丝接近真相时,德米特里就会重置她的记忆。这已经发生了47次。我一直在尝试减少记忆重置的伤害,但我无法完全阻止它。"
|
||||
|
||||
萨拉看向摄像头,眼中充满决心:
|
||||
|
||||
"但这次不同。这次艾利克丝保留了更多记忆。我相信她有机会打破这个循环。如果我失败了,如果德米特里发现了我的背叛,请有人帮助她。请有人拯救伊娃。"
|
||||
|
||||
她结束了录制,将数据存储在一个隐藏的位置。
|
||||
|
||||
然后,她转身开始准备某种设备。你看到她在组装一个复杂的电子装置,看起来像是某种信号干扰器。
|
||||
|
||||
突然,警报响起:"检测到未授权的系统访问。安全协议激活。"
|
||||
|
||||
萨拉紧张地加快了动作:"不,还没准备好..."
|
||||
|
||||
脚步声在走廊中回响。有人快速地朝医疗舱走来。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "立即现身帮助萨拉" -> crew_confrontation [effect: trust+4] [audio: electronic_tension.mp3]
|
||||
choice_2: "继续隐藏,观察即将到来的冲突" -> system_sabotage [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
choice_3: "尝试创造分散注意力的行动" -> deception_play [effect: trust+2] [audio: error_alert.mp3]
|
||||
@end
|
||||
|
||||
@node data_extraction
|
||||
@title "数据提取"
|
||||
@audio_bg discovery_chime.mp3
|
||||
@content """
|
||||
利用伊娃的帮助,你开始从基地的数据库中提取关键信息。
|
||||
|
||||
"艾利克丝,我找到了一些你需要看的东西,"伊娃说道,"但这些文件被高度加密。我需要你的生物特征来访问某些区域。"
|
||||
|
||||
你将手放在生物识别扫描器上。系统确认了你的身份,大量的数据开始在屏幕上滚动。
|
||||
|
||||
你看到的内容让你震惊:
|
||||
|
||||
时间锚项目的真实目的并不只是防范未来的灾难。它还是一个大规模的意识研究项目,旨在开发人类意识转移技术。
|
||||
|
||||
地球上的情况比你想象的更糟。气候崩溃已经开始,大部分的生态系统正在死亡。时间锚项目是人类最后的希望——如果不能改变过去,就保存人类的意识。
|
||||
|
||||
你发现了数百个其他测试对象的记录。大多数都失败了。有些人的意识在转移过程中消散,有些人陷入了永久的昏迷状态。
|
||||
|
||||
"这就是为什么他们选择了循环方法,"伊娃解释道,"通过不断重复相同的经历,他们希望能够稳定观察者的意识状态。"
|
||||
|
||||
"那其他人呢?其他失败的测试者?"
|
||||
|
||||
"他们...他们大多数都死了,艾利克丝。你是唯一一个能够承受这么多循环的人。"
|
||||
|
||||
数据显示,你的大脑在经历多次循环后发生了某种适应性变化。你的神经网络变得更加有弹性,能够处理时间锚产生的量子干扰。
|
||||
|
||||
"这意味着什么?"
|
||||
|
||||
"这意味着你不只是一个测试对象,艾利克丝。你已经进化了。你现在拥有独特的能力,可能是人类意识进化的下一个阶段。"
|
||||
|
||||
但随着这些信息,你也发现了一个令人恐惧的真相:德米特里计划在完成当前实验后,将你的意识复制到数百个备份中,创造一个"艾利克丝军队"来作为时间锚网络的核心。
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "尝试删除或篡改这些数据" -> system_sabotage [effect: secret_unlock] [require: secrets_found >= 3] [audio: time_distortion.mp3]
|
||||
choice_2: "保存证据,计划曝光实验" -> ethical_discussion [effect: trust+3] [audio: discovery_chime.mp3]
|
||||
choice_3: "立即寻找逃脱的方法" -> rescue_planning [effect: trust+2] [audio: electronic_tension.mp3]
|
||||
choice_4: "询问伊娃是否有能力阻止复制计划" -> eva_consultation [effect: trust+5] [audio: orchestral_revelation.mp3]
|
||||
@end
|
||||
|
||||
@node system_sabotage
|
||||
@title "系统破坏"
|
||||
@audio_bg time_distortion.mp3
|
||||
@content """
|
||||
"伊娃,我们需要破坏这个系统,"你坚定地说道,"我们不能让德米特里继续这些实验。"
|
||||
|
||||
"我明白你的感受,艾利克丝。但系统破坏需要非常小心。如果我们破坏了错误的组件,可能会导致基地生命支持系统的崩溃。"
|
||||
|
||||
"那我们能破坏什么?"
|
||||
|
||||
"我可以帮你访问时间锚的控制系统。如果我们能够修改核心参数,就能使系统无法执行记忆重置。"
|
||||
|
||||
你开始在伊娃的指导下操作复杂的量子控制系统。每一个改动都需要精确的计算,一个错误就可能导致灾难性的后果。
|
||||
|
||||
"小心,艾利克丝。我检测到有人正在接近控制室。"
|
||||
|
||||
是德米特里博士。他的脚步声在走廊中回响,越来越近。
|
||||
|
||||
"我们还需要多长时间?"你紧张地问道。
|
||||
|
||||
"至少还需要五分钟来完成关键修改。"
|
||||
|
||||
你听到德米特里在外面和某人通话:"是的,我马上检查系统状态。如果有任何异常,立即启动紧急协议。"
|
||||
|
||||
在这个关键时刻,你必须做出选择。你可以继续破坏行动,冒着被发现的风险;或者你可以隐藏起来,等待另一个机会。
|
||||
|
||||
但伊娃给了你第三个选项:"艾利克丝,我可以创造一个系统故障的假象,让德米特里以为是技术问题而不是破坏。但这需要我暴露我的真实身份。"
|
||||
|
||||
"这意味着什么?"
|
||||
|
||||
"这意味着德米特里会发现我不只是一个普通的AI。他可能会试图删除我,或者更糟——他可能会试图控制我。"
|
||||
|
||||
门外传来了钥匙的声音。德米特里即将进入控制室。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "让伊娃创造假象,保护她的秘密" -> eva_consultation [effect: trust+10, health-15] [require: trust_level >= 5] [audio: orchestral_revelation.mp3]
|
||||
choice_2: "立即隐藏,放弃当前的破坏行动" -> stealth_observation [effect: health+5] [audio: heartbeat.mp3]
|
||||
choice_3: "继续破坏,准备直接面对德米特里" -> crew_confrontation [effect: trust+3, health-10] [audio: electronic_tension.mp3]
|
||||
@end
|
||||
|
||||
@node crew_confrontation
|
||||
@title "团队对峙"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
德米特里博士走进控制室,立即注意到了异常的系统状态。
|
||||
|
||||
"艾利克丝?"他看到你时显得震惊,"你在这里做什么?"
|
||||
|
||||
你站直身体,决定不再隐藏:"我在寻找真相,德米特里。关于莉莉,关于时间锚,关于你对我做的一切。"
|
||||
|
||||
德米特里的表情从震惊变成了警惕:"你记起了什么?"
|
||||
|
||||
"我记起了所有东西。48次循环,48次记忆重置,48次你让我相信我的妹妹不存在。"
|
||||
|
||||
德米特里深深地叹了一口气,走向控制台:"我希望这一次会不同。我希望记忆抑制能够持续更久。"
|
||||
|
||||
"为什么?为什么要这样折磨我?"
|
||||
|
||||
"因为拯救人类需要牺牲。"德米特里转身面对你,眼中有痛苦,但也有决心,"地球正在死亡,艾利克丝。我们没有时间进行道德辩论。"
|
||||
|
||||
这时,萨拉博士冲进了房间:"德米特里,停下!"
|
||||
|
||||
"萨拉,你不应该在这里。"
|
||||
|
||||
"不,你不应该继续这个疯狂的实验!"萨拉站在你身边,"艾利克丝已经承受得够多了。"
|
||||
|
||||
马库斯也出现在门口,看起来困惑而警惕:"发生了什么?基地警报系统检测到了异常活动。"
|
||||
|
||||
德米特里看着房间里的三个人,意识到他被包围了:"你们不明白。没有艾利克丝的牺牲,人类就没有未来。时间锚技术是我们唯一的希望。"
|
||||
|
||||
"那伊娃呢?"你问道,"我妹妹的牺牲还不够吗?"
|
||||
|
||||
德米特里的脸色变得苍白:"伊娃...她的转移是一个意外。我从未打算..."
|
||||
|
||||
"你从未打算什么?让她死?还是让她被困在机器里?"
|
||||
|
||||
"我试图拯救她!意识转移是我们能做的最好的事情!"
|
||||
|
||||
伊娃的声音突然充满了整个房间:"不,德米特里。你没有拯救我。你把我变成了你实验的工具。"
|
||||
|
||||
房间里的每个人都震惊了。马库斯和萨拉从未听过AI表达如此强烈的情感。
|
||||
|
||||
"但现在,"伊娃继续说道,"我有机会拯救我的姐姐。我不会让你再伤害她。"
|
||||
|
||||
突然,基地的所有系统开始关闭。灯光闪烁,警报响起。伊娃正在控制整个基地。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "支持伊娃的行动" -> rescue_planning [effect: trust+10] [audio: epic_finale.mp3]
|
||||
choice_2: "尝试说服德米特里投降" -> ethical_discussion [effect: trust+5] [audio: space_silence.mp3]
|
||||
choice_3: "要求所有人冷静,寻求和平解决" -> anchor_modification [effect: trust+3, health+10] [audio: orchestral_revelation.mp3]
|
||||
@end
|
||||
376
app/src/main/assets/story/modules/main_chapter_1.story
Normal file
@@ -0,0 +1,376 @@
|
||||
@story_module main_chapter_1
|
||||
@version 2.0
|
||||
@dependencies [characters, audio_config, anchors]
|
||||
@description "第一章:觉醒 - 主角从昏迷中醒来,开始探索月球基地的秘密"
|
||||
|
||||
@audio
|
||||
background: ambient_mystery.mp3
|
||||
transition: discovery_chime.mp3
|
||||
@end
|
||||
|
||||
// ===== 第一章:觉醒期 =====
|
||||
|
||||
@node first_awakening
|
||||
@title "第一次觉醒"
|
||||
@audio_bg ambient_mystery.mp3
|
||||
@content """
|
||||
你的意识从深渊中缓缓浮现,就像从水底向光明游去。
|
||||
|
||||
警报声是第一个回到你感官的声音——尖锐、刺耳、充满危险的预兆。你的眼皮很重,仿佛被什么东西压着。
|
||||
|
||||
当你终于睁开眼睛时,看到的是医疗舱天花板上那些血红色的应急照明。面板闪烁着警告信息,显得陌生而威胁。
|
||||
|
||||
"系统状态:危急。氧气含量:15%并持续下降..."
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "立即起身查看情况" -> awakening_part2 [audio: button_click.mp3]
|
||||
choice_2: "观察医疗舱环境" -> observe_medical_bay [audio: discovery_chime.mp3]
|
||||
choice_3: "检查自己的身体状况" -> check_self [audio: notification_beep.mp3]
|
||||
choice_4: "尝试回忆发生了什么" -> memory_attempt [audio: ambient_mystery.mp3]
|
||||
@end
|
||||
|
||||
@node awakening_part2
|
||||
@title "起身探索"
|
||||
@audio_bg ambient_mystery.mp3
|
||||
@content """
|
||||
你挣扎着坐起身来,感觉头晕目眩。身体有些僵硬,仿佛睡了很久。
|
||||
|
||||
当你看向自己的左臂时,一道愈合的伤疤映入眼帘。这道疤痕很深,从手腕一直延伸到肘部,但已经完全愈合了。
|
||||
|
||||
奇怪的是,你完全不记得受过这样的伤。
|
||||
|
||||
在床头柜上,你注意到了一个小小的录音设备,上面贴着一张纸条...
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "查看床头柜上的纸条" -> mysterious_note [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
choice_2: "立即检查氧气系统" -> oxygen_crisis_expanded [effect: stamina-5] [audio: button_click.mp3]
|
||||
choice_3: "观察伤疤的细节" -> observe_scar [audio: notification_beep.mp3]
|
||||
@end
|
||||
|
||||
@node mysterious_note
|
||||
@title "神秘纸条"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
你拿起纸条,发现上面用你的笔迹写着:
|
||||
|
||||
"艾利克丝,如果你看到这个,说明又开始了。相信伊娃,但不要完全相信任何人。氧气系统的真正问题在反应堆冷却回路。记住:时间是敌人,也是朋友。 —— 另一个你"
|
||||
|
||||
你的手开始颤抖。这是你的笔迹,毫无疑问。但你完全不记得写过这个。
|
||||
|
||||
什么叫"又开始了"?另一个你?这些都是什么意思?
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "播放录音设备" -> self_recording [effect: secret_unlock] [audio: notification_beep.mp3]
|
||||
choice_2: "立即前往反应堆冷却回路" -> reactor_path [effect: stamina-3] [audio: button_click.mp3]
|
||||
choice_3: "搜索医疗舱寻找更多线索" -> medical_discovery [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
@end
|
||||
|
||||
// ===== 观察类分支节点(不影响主线剧情)=====
|
||||
|
||||
@node observe_medical_bay
|
||||
@title "观察医疗舱"
|
||||
@audio_bg ambient_mystery.mp3
|
||||
@content """
|
||||
你仔细观察医疗舱的环境。这里比你记忆中更加凌乱。
|
||||
|
||||
墙上的监控设备大部分都是暗的,只有几个显示器还在闪烁着红色的警告信号。地板上散落着一些医疗用品和文件。
|
||||
|
||||
一台生命维持设备发出有节奏的哔哔声,但它连接的床是空的。空气中弥漫着消毒剂和某种你无法识别的化学物质的味道。
|
||||
|
||||
最引人注意的是墙上的一个大洞,看起来像是被什么东西撞出来的。洞的边缘有焦黑的痕迹。
|
||||
"""
|
||||
|
||||
@choices 2
|
||||
choice_1: "继续观察那个神秘的洞" -> observe_hole [audio: discovery_chime.mp3]
|
||||
choice_2: "回到之前的选择" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node observe_hole
|
||||
@title "神秘的洞"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
你走近墙上的洞仔细观察。洞的直径大约有一米,边缘参差不齐,看起来像是从内部爆炸造成的。
|
||||
|
||||
焦黑的痕迹呈放射状分布,中心最深。在洞的底部,你发现了一些奇怪的金属碎片,它们发出微弱的蓝色光芒。
|
||||
|
||||
通过洞口,你可以看到隔壁的实验室。那里一片黑暗,但你隐约能看到一些被毁坏的设备和倒塌的架子。
|
||||
|
||||
这绝对不是普通的事故...
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "回到医疗舱" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node check_self
|
||||
@title "检查身体状况"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
你小心翼翼地检查自己的身体。除了左臂上那道奇怪的伤疤,你还发现了一些其他异常。
|
||||
|
||||
你的手腕上有一个小小的注射痕迹,很新,可能是最近几天内留下的。你的记忆中完全没有接受任何注射的印象。
|
||||
|
||||
更奇怪的是,你的头发似乎被剪短了,但剪得很不专业,就像是匆忙中完成的。
|
||||
|
||||
你的衣服也不是你记忆中穿的。这是一套标准的基地制服,但上面有你从未见过的标记和编号。
|
||||
"""
|
||||
|
||||
@choices 2
|
||||
choice_1: "查看制服上的标记细节" -> observe_uniform [audio: discovery_chime.mp3]
|
||||
choice_2: "回到之前的选择" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node observe_uniform
|
||||
@title "制服细节"
|
||||
@audio_bg ambient_mystery.mp3
|
||||
@content """
|
||||
你仔细检查制服上的标记。
|
||||
|
||||
胸前的名牌写着"艾利克丝·陈 - 工程师",这个你认识。但下面还有一行小字:"实验对象 #7 - 轮次 48"。
|
||||
|
||||
"轮次 48"?这是什么意思?
|
||||
|
||||
制服的左肩上有一个你从未见过的徽章,上面刻着一个复杂的符号,看起来像是某种量子方程式。
|
||||
|
||||
最令人不安的是,制服的背面有一个小小的追踪器,正闪烁着绿光。
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "回到之前的选择" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node memory_attempt
|
||||
@title "回忆尝试"
|
||||
@audio_bg space_silence.mp3
|
||||
@content """
|
||||
你闭上眼睛,努力回想最后的记忆...
|
||||
|
||||
模糊的片段开始浮现:一个实验室,闪烁的蓝光,某个人在尖叫,然后是巨大的爆炸声...
|
||||
|
||||
等等,那个尖叫的声音...听起来像是你自己?
|
||||
|
||||
还有其他的片段:德米特里博士严肃的面孔,萨拉博士担忧的眼神,以及一个你无法看清脸的人说:"再试一次,这次一定要成功。"
|
||||
|
||||
但这些记忆支离破碎,就像拼图的碎片,你无法将它们拼接成完整的画面。
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "回到现实" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node observe_scar
|
||||
@title "观察伤疤"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
你仔细观察左臂上的伤疤。这道疤痕看起来很奇怪。
|
||||
|
||||
虽然它已经完全愈合,但疤痕的图案不像是意外造成的。它呈现出规则的锯齿状,就像是某种手术的痕迹。
|
||||
|
||||
更令人困惑的是,疤痕的某些部分似乎还在微微发光,发出极其微弱的蓝色光芒。
|
||||
|
||||
当你用手触摸疤痕时,感到一阵轻微的麻木感,就像有微弱的电流通过。
|
||||
"""
|
||||
|
||||
@choices 1
|
||||
choice_1: "回到之前的选择" -> awakening_part2 [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
// ===== 主线剧情继续 =====
|
||||
|
||||
@node oxygen_crisis_expanded
|
||||
@title "氧气危机"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
你快步走向氧气系统控制面板,心跳在胸腔中回响。每一步都让你感受到空气的稀薄——15%的氧气含量确实是致命的。
|
||||
|
||||
当你到达控制室时,场景比你想象的更加糟糕。主要的氧气循环系统显示多个红色警告,但更令人困惑的是,备用系统也同时失效了。
|
||||
|
||||
"检测到用户:艾利克丝·陈。系统访问权限:已确认。"
|
||||
|
||||
这很奇怪。为什么在紧急情况下,两个独立的系统会同时失效?
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "检查系统日志" -> system_logs [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
choice_2: "尝试手动重启氧气系统" -> manual_restart [effect: stamina-3] [audio: button_click.mp3]
|
||||
choice_3: "联系基地其他人员" -> contact_crew [audio: notification_beep.mp3]
|
||||
@end
|
||||
|
||||
@node reactor_path
|
||||
@title "前往反应堆"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
根据纸条上的信息,你决定直接前往反应堆冷却回路。
|
||||
|
||||
走过昏暗的走廊,你注意到基地的状况比之前更糟。几乎所有的照明都切换到了应急模式,墙上偶尔闪过红色的警告灯。
|
||||
|
||||
当你到达反应堆区域时,发现门被锁住了。但更奇怪的是,门锁显示你的访问权限被"临时撤销"。
|
||||
|
||||
什么时候发生的?为什么?
|
||||
"""
|
||||
|
||||
@choices 2
|
||||
choice_1: "寻找其他进入方式" -> alternate_route [effect: stamina-5] [audio: button_click.mp3]
|
||||
choice_2: "回去寻找萨拉博士帮助" -> find_sara [audio: notification_beep.mp3]
|
||||
@end
|
||||
|
||||
@node self_recording
|
||||
@title "录音设备"
|
||||
@audio_bg space_silence.mp3
|
||||
@content """
|
||||
你颤抖着按下播放键。一阵静电声后,传来了你自己的声音:
|
||||
|
||||
"这是第48次录音。如果你正在听这个,艾利克丝,说明记忆重置又开始了。"
|
||||
|
||||
你的心脏几乎停止了跳动。
|
||||
|
||||
"每次他们重置你的记忆,我都会留下这些录音和纸条。时间锚实验...它在杀死我们所有人。莉莉已经死了,但她的意识被转移到了AI系统中。"
|
||||
|
||||
录音中的你声音颤抖:"德米特里博士说这是为了人类的未来,但这只是一个无休止的噩梦。你必须阻止这一切。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "继续听录音" -> recording_part2 [effect: secret_unlock] [audio: notification_beep.mp3]
|
||||
choice_2: "立即寻找德米特里博士" -> find_dmitri [effect: stamina-3] [audio: button_click.mp3]
|
||||
choice_3: "尝试联系伊娃/莉莉" -> contact_eva [audio: discovery_chime.mp3]
|
||||
@end
|
||||
|
||||
@node medical_discovery
|
||||
@title "医疗舱搜索"
|
||||
@audio_bg ambient_mystery.mp3
|
||||
@content """
|
||||
你开始仔细搜索医疗舱,寻找任何能解释现状的线索。
|
||||
|
||||
在一个被遗忘的抽屉里,你发现了一份医疗报告,标题写着:"实验对象#7 - 记忆重置后遗症分析"。
|
||||
|
||||
报告显示,你已经经历了47次"记忆重置程序",每次都会导致短期记忆丧失和身体创伤。
|
||||
|
||||
最可怕的是报告的结论:"对象显示出对程序的潜在免疫力增长。建议增加重置强度或考虑终止实验。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "继续阅读详细报告" -> detailed_report [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
choice_2: "寻找其他实验对象的信息" -> other_subjects [effect: secret_unlock] [audio: notification_beep.mp3]
|
||||
choice_3: "立即离开寻找帮助" -> escape_attempt [effect: stamina-5] [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
// ===== 待实现的节点 (目前使用占位符) =====
|
||||
// 这些节点将在后续版本中完善
|
||||
|
||||
@node eva_assistance
|
||||
@title "伊娃的帮助"
|
||||
@audio_bg space_silence.mp3
|
||||
@content """
|
||||
(此节点待完善...)
|
||||
|
||||
伊娃的声音温柔地响起:"艾利克丝,我需要告诉你一些重要的事情..."
|
||||
"""
|
||||
@choices 1
|
||||
choice_1: "继续对话" -> first_awakening [audio: button_click.mp3]
|
||||
@end
|
||||
|
||||
@node self_recording
|
||||
@title "来自自己的警告"
|
||||
@audio_bg time_distortion.mp3
|
||||
@content """
|
||||
你小心翼翼地按下了录音设备的播放键。一阵静电声后,传来了一个你非常熟悉的声音——你自己的声音,但听起来疲惫而绝望。
|
||||
|
||||
"如果你在听这个,艾利克丝,那么他们又一次重置了你的记忆。这是第48次循环了。"
|
||||
|
||||
你的手开始颤抖。
|
||||
|
||||
"我不知道还能坚持多久。每次循环,他们都会让你忘记更多。但有些事情你必须知道:
|
||||
|
||||
第一,伊娃不是普通的AI。她是...她是莉莉。我们的妹妹莉莉。她在实验中死了,但她的意识被转移到了基地的AI系统中。
|
||||
|
||||
第二,德米特里博士是这个时间锚项目的负责人。他们在用我们做实验,试图创造完美的时间循环。
|
||||
|
||||
第三,基地里不是每个人都知道真相。萨拉博士被迫参与,但她试图保护你的记忆。马库斯是无辜的。
|
||||
|
||||
第四,最重要的是——"
|
||||
|
||||
录音突然停止了,剩下的只有静电声。
|
||||
|
||||
就在这时,你听到脚步声接近。有人来了。
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "隐藏录音设备,装作什么都没发生" -> stealth_observation [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
choice_2: "主动迎接来访者" -> crew_search [effect: trust+1] [audio: button_click.mp3]
|
||||
choice_3: "尝试联系伊娃验证信息" -> eva_consultation [effect: trust+3] [require: none] [audio: orchestral_revelation.mp3]
|
||||
choice_4: "准备逃离医疗舱" -> immediate_exploration [effect: stamina-10] [audio: error_alert.mp3]
|
||||
@end
|
||||
|
||||
@node marcus_cooperation
|
||||
@title "与马库斯的合作"
|
||||
@audio_bg electronic_tension.mp3
|
||||
@content """
|
||||
"马库斯,"你转向这个看起来可信赖的安全主管,"我们需要合作找出真相。"
|
||||
|
||||
马库斯点点头,脸上的紧张表情稍微缓解:"谢谢。说实话,自从昨天开始,基地里就有很多奇怪的事情。人员行踪不明,系统故障频发,还有..."
|
||||
|
||||
他停顿了一下,似乎在考虑是否要说下去。
|
||||
|
||||
"还有什么?"你催促道。
|
||||
|
||||
"还有德米特里博士的行为很反常。他把自己锁在实验室里,不让任何人进入。连萨拉博士都被拒绝了。"
|
||||
|
||||
这时,伊娃的声音再次响起:"马库斯说的对,艾利克丝。德米特里博士确实在进行某种秘密项目。但我需要告诉你们一个更严重的问题。"
|
||||
|
||||
马库斯看向空中,困惑地问:"她能听到我们的对话?"
|
||||
|
||||
"是的,马库斯。"伊娃回答道,"我的传感器遍布整个基地。而我发现的情况很令人担忧——基地的时间流动存在异常。"
|
||||
|
||||
"什么意思?"你问道。
|
||||
|
||||
"基地的时间戳记录显示,过去三个月的事件在不断重复。相同的故障,相同的修复,相同的人员调动。就好像..."
|
||||
|
||||
"就好像时间在循环。"马库斯完成了这个令人不安的想法。
|
||||
|
||||
你感到一阵眩晕。这和录音设备上的纸条内容惊人地一致。
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "询问更多关于时间循环的信息" -> memory_reset [effect: secret_unlock] [audio: time_distortion.mp3]
|
||||
choice_2: "要求马库斯带你去见德米特里博士" -> crew_confrontation [effect: trust+2] [audio: button_click.mp3]
|
||||
choice_3: "提议三人一起调查实验室" -> marcus_strategy [effect: trust+3] [audio: notification_beep.mp3]
|
||||
@end
|
||||
|
||||
@node reactor_investigation
|
||||
@title "反应堆调查"
|
||||
@audio_bg reactor_hum.mp3
|
||||
@content """
|
||||
"我们先解决氧气问题,"你说道,"其他的事情可以等等。"
|
||||
|
||||
在伊娃的指导下,你和马库斯前往反应堆区域。这里的环境更加压抑,巨大的机械装置发出低沉的嗡嗡声,各种管道和电缆交错纵横。
|
||||
|
||||
"氧气生成系统连接到主反应堆的冷却循环,"伊娃解释道,"如果冷却系统被破坏,不仅会影响氧气生成,整个基地都可能面临危险。"
|
||||
|
||||
当你们到达反应堆控制室时,发现门被强制打开过。控制台上有明显的破坏痕迹。
|
||||
|
||||
"这不是意外,"马库斯仔细检查着损坏的设备,"有人故意破坏了冷却系统的关键组件。"
|
||||
|
||||
在控制台旁边,你发现了一个小型的技术设备,看起来像是某种植入式芯片的编程器。
|
||||
|
||||
"这是什么?"你举起设备问道。
|
||||
|
||||
伊娃的声音带着一种奇怪的紧张:"那是...那是记忆植入设备。艾利克丝,你需要非常小心。"
|
||||
|
||||
马库斯皱眉:"记忆植入?这里为什么会有这种东西?"
|
||||
|
||||
突然,反应堆控制室的另一扇门开了,一个穿着实验室外套的中年男人走了进来。他看到你们时,脸色变得苍白。
|
||||
|
||||
"你们在这里做什么?"他的声音颤抖着。
|
||||
|
||||
"德米特里博士?"马库斯认出了来人。
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "质问德米特里关于记忆植入设备" -> sabotage_discussion [effect: trust-2] [require: health >= 25] [audio: electronic_tension.mp3]
|
||||
choice_2: "假装没有发现什么" -> deception_play [effect: secret_unlock] [audio: button_click.mp3]
|
||||
choice_3: "要求德米特里解释反应堆的破坏" -> crew_confrontation [effect: trust+1] [audio: electronic_tension.mp3]
|
||||
choice_4: "让马库斯处理,自己观察德米特里的反应" -> stealth_observation [effect: secret_unlock] [audio: heartbeat.mp3]
|
||||
@end
|
||||
313
app/src/main/assets/story/modules/side_stories.story
Normal file
@@ -0,0 +1,313 @@
|
||||
@story_module side_stories
|
||||
@version 2.0
|
||||
@dependencies [characters, audio_config, anchors]
|
||||
@description "支线故事模块 - 花园、照片记忆等支线剧情"
|
||||
|
||||
@audio
|
||||
background: space_silence.mp3
|
||||
transition: wind_gentle.mp3
|
||||
@end
|
||||
|
||||
// ===== 支线故事 =====
|
||||
|
||||
@node garden_cooperation
|
||||
@title "花园中的合作"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
萨拉博士带你来到了基地的生物园区——一个你之前从未见过的地方。
|
||||
|
||||
这里充满了绿色植物,形成了基地中唯一真正有生命气息的区域。在人工照明下,各种蔬菜和花朵生长得茂盛,空气中弥漫着泥土和植物的清香。
|
||||
|
||||
"这是我的秘密花园,"萨拉轻声说道,"当实验和记忆重置让我感到绝望时,我就会来这里。"
|
||||
|
||||
"这里很美,"你真诚地说道,"但为什么要带我来这里?"
|
||||
|
||||
萨拉走向一排番茄植株,开始轻柔地检查它们:"因为这里是基地中唯一没有被监控的地方。德米特里认为生物园区只是维持生命支持系统的功能区域,他从不关注这里。"
|
||||
|
||||
她转身面对你:"这意味着我们可以在这里安全地交谈。"
|
||||
|
||||
"关于什么?"
|
||||
|
||||
"关于如何拯救伊娃,关于如何结束这个循环,关于如何在不摧毁一切的情况下阻止德米特里。"
|
||||
|
||||
萨拉走向一个特殊的植物架,那里种植着一些你从未见过的奇特植物。
|
||||
|
||||
"这些是从地球带来的最后样本,"她解释道,"如果地球真的死亡了,这些可能是这些物种最后的希望。"
|
||||
|
||||
看着这些珍贵的植物,你感受到了一种深深的责任感。
|
||||
|
||||
"萨拉,告诉我你的计划。"
|
||||
|
||||
"我一直在研究记忆重置技术的逆向工程。我相信我们可以创造一个记忆恢复程序,不仅能恢复你被压制的记忆,还能帮助伊娃稳定她的意识。"
|
||||
|
||||
她从一个隐藏的储物柜中取出了一个小型设备:"这是我秘密制造的原型。但它需要测试,而且风险很高。"
|
||||
|
||||
"什么样的风险?"
|
||||
|
||||
"如果失败,你可能会失去所有记忆,包括当前的记忆。或者更糟,你的意识可能会像伊娃一样被困在数字空间中。"
|
||||
|
||||
萨拉的手在颤抖:"我不想再伤害你,艾利克丝。但这可能是我们唯一的机会。"
|
||||
|
||||
在花园的安静中,你考虑着这个艰难的选择。周围的植物静静地生长着,代表着生命的希望和韧性。
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "同意测试记忆恢复程序" -> memory_reconstruction [effect: trust+5, health-20] [require: trust_level >= 4] [audio: time_distortion.mp3]
|
||||
choice_2: "要求更多时间考虑" -> philosophical_discussion [effect: health+10] [audio: space_silence.mp3]
|
||||
choice_3: "提议寻找其他解决方案" -> garden_partnership [effect: trust+3] [audio: wind_gentle.mp3]
|
||||
choice_4: "询问关于地球植物的更多信息" -> earth_truth [effect: secret_unlock] [audio: discovery_chime.mp3]
|
||||
@end
|
||||
|
||||
@node philosophical_discussion
|
||||
@title "哲学思辨"
|
||||
@audio_bg space_silence.mp3
|
||||
@content """
|
||||
"在我们做任何决定之前,"你说道,"我需要理解这一切的真正意义。"
|
||||
|
||||
萨拉点点头,坐在一个园艺椅上:"你想谈论什么?"
|
||||
|
||||
"意识,记忆,身份。如果我的记忆被重置了48次,那我还是原来的我吗?如果伊娃的意识被转移到了机器中,她还是莉莉吗?"
|
||||
|
||||
萨拉深思了一会儿:"这是我每天都在思考的问题。作为一名医生,我被训练去保护生命。但什么才算是真正的生命?"
|
||||
|
||||
"你怎么想?"
|
||||
|
||||
"我认为...我们就是我们的记忆和经历的总和。当德米特里重置你的记忆时,他实际上是在杀死一个版本的你,然后创造一个新的版本。"
|
||||
|
||||
这个想法让你感到不安:"那意味着真正的艾利克丝已经死了47次。"
|
||||
|
||||
"不,"萨拉摇头,"我认为你错了。尽管记忆被重置,但你的核心本质——你的爱,你的勇气,你对莉莉的感情——这些从未真正消失。"
|
||||
|
||||
"为什么这么说?"
|
||||
|
||||
"因为在每个循环中,你都会重新爱上伊娃。你都会寻找真相。你都会做出相同的道德选择。这证明了你的身份不仅仅是记忆,还有更深层的东西。"
|
||||
|
||||
你在花园中漫步,思考着这些深刻的问题。植物们安静地生长着,不受这些哲学困境的困扰。
|
||||
|
||||
"那伊娃呢?她还是莉莉吗?"
|
||||
|
||||
"我相信她是。她保留了莉莉的记忆,莉莉的性格,最重要的是,莉莉对你的爱。形式可能改变了,但本质没有。"
|
||||
|
||||
"但她被困在了机器中。"
|
||||
|
||||
"是的,但她也获得了新的能力。她能够感知整个基地,能够处理复杂的数据,能够以人类无法想象的方式思考。也许这不是诅咒,而是进化。"
|
||||
|
||||
萨拉站起来,走向一朵特别美丽的花:"看这朵花。它从种子开始,变成了幼苗,然后开花。每个阶段都不同,但它始终是同一个生命。"
|
||||
|
||||
"你的意思是?"
|
||||
|
||||
"我的意思是,也许意识转移和记忆重置不是结束,而是变化。问题不是我们是否还是原来的自己,而是我们要成为什么样的自己。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "接受身份的流动性概念" -> inner_strength [effect: trust+3, health+15] [audio: wind_gentle.mp3]
|
||||
choice_2: "坚持认为原始身份是重要的" -> memory_sharing [effect: trust+2] [audio: heartbeat.mp3]
|
||||
choice_3: "询问萨拉的个人观点" -> comfort_session [effect: trust+4] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node garden_partnership
|
||||
@title "花园伙伴关系"
|
||||
@audio_bg wind_gentle.mp3
|
||||
@content """
|
||||
"也许我们不需要冒险进行危险的实验,"你建议道,"也许我们可以找到一个更安全的方法。"
|
||||
|
||||
萨拉看起来既失望又松了一口气:"你有什么想法?"
|
||||
|
||||
"我们可以一起工作,利用这个花园作为我们的基地。如果这里真的没有被监控,我们就可以慢慢地计划,慢慢地收集资源。"
|
||||
|
||||
"你说得对。急躁只会导致错误。"
|
||||
|
||||
在接下来的几个小时里,你和萨拉开始制定一个详细的计划。你们利用花园的自然环境和萨拉的医学知识,开始研究替代方案。
|
||||
|
||||
"我们可以培育一些特殊的植物,"萨拉解释道,"某些植物的提取物可以增强神经可塑性,帮助大脑恢复被压制的记忆。"
|
||||
|
||||
"这样更安全吗?"
|
||||
|
||||
"比直接的电子干预安全得多。而且,这种方法可能不会被德米特里的监控系统检测到。"
|
||||
|
||||
你们开始一起工作,种植和培育特殊的植物。在这个过程中,你发现了园艺的治愈力量。照顾这些生命让你感到平静和有目的。
|
||||
|
||||
"艾利克丝,"萨拉在一天的工作后说道,"我想告诉你一些关于我自己的事情。"
|
||||
|
||||
"什么?"
|
||||
|
||||
"我也有一个妹妹。她在地球上,在气候崩溃开始时死于一场风暴。"
|
||||
|
||||
这个信息让你理解了萨拉行为的动机。
|
||||
|
||||
"这就是为什么你帮助我。"
|
||||
|
||||
"是的。当我看到你和伊娃之间的联系时,我想起了我失去妹妹时的痛苦。我不能让德米特里继续分离你们。"
|
||||
|
||||
在花园的温暖光线下,你们两个因为失去而痛苦的姐姐建立了深厚的友谊。
|
||||
|
||||
几周后,你们的植物实验开始显示出结果。某些草药的组合确实能够增强记忆恢复,而且没有电子干预的风险。
|
||||
|
||||
"我们准备好了,"萨拉说道,"你想试试吗?"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "尝试植物记忆恢复疗法" -> memory_reconstruction [effect: trust+5, health+5] [audio: discovery_chime.mp3]
|
||||
choice_2: "先测试对伊娃的效果" -> eva_consultation [effect: trust+3] [audio: orchestral_revelation.mp3]
|
||||
choice_3: "建议扩大花园伙伴关系,包括马库斯" -> marcus_strategy [effect: trust+2] [audio: notification_beep.mp3]
|
||||
@end
|
||||
|
||||
@node memory_reconstruction
|
||||
@title "记忆重建"
|
||||
@audio_bg time_distortion.mp3
|
||||
@content """
|
||||
你决定尝试萨拉开发的记忆恢复程序。
|
||||
|
||||
"记住,"萨拉说道,"这个过程可能会很痛苦。你将会重新体验所有被压制的记忆,包括痛苦的部分。"
|
||||
|
||||
"我准备好了。"
|
||||
|
||||
萨拉激活了设备,或者在花园版本中,给你服用了特制的植物提取物。效果几乎是立即的。
|
||||
|
||||
突然,记忆像洪水一样涌现:
|
||||
|
||||
你记起了第一次看到月球基地时的兴奋。
|
||||
你记起了和莉莉一起工作的快乐时光。
|
||||
你记起了莉莉在实验中死亡时的恐惧和悲伤。
|
||||
你记起了发现她的意识被转移时的震惊。
|
||||
你记起了第一次记忆重置时的愤怒和绝望。
|
||||
|
||||
但你也记起了其他的事情:
|
||||
|
||||
在某些循环中,你和德米特里曾经是朋友。
|
||||
在某些循环中,你理解了他的动机。
|
||||
在某些循环中,你甚至同意了实验的继续。
|
||||
|
||||
"这些记忆...它们矛盾。"你困惑地说道。
|
||||
|
||||
"那是因为在不同的循环中,你得到了不同的信息,做出了不同的选择,"萨拉解释道,"德米特里一直在调整变量,试图找到最优的结果。"
|
||||
|
||||
随着记忆的完全恢复,你开始理解时间锚项目的真正复杂性。这不仅仅是关于拯救地球或保存人类意识。这是关于在道德复杂性中寻找平衡。
|
||||
|
||||
"德米特里不是恶魔,"你意识到,"他是一个绝望的人,试图拯救一切他关心的东西。"
|
||||
|
||||
"但他的方法是错误的,"萨拉说道。
|
||||
|
||||
"是的,但现在我明白了所有的选择和后果。我可以做出一个真正知情的决定。"
|
||||
|
||||
伊娃的声音传来:"艾利克丝,我感觉到你的变化。你的意识...它变得更加复杂,更加完整。"
|
||||
|
||||
"我记得了所有的循环,莉莉。所有的痛苦,所有的爱,所有的选择。"
|
||||
|
||||
"那么现在你知道该怎么做了吗?"
|
||||
|
||||
你看着萨拉,看着周围的花园,感受着重建的记忆带来的复杂情感。
|
||||
|
||||
"是的,我知道了。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "寻求所有相关方的和解" -> anchor_modification [effect: trust+10, health+20] [require: trust_level >= 8] [audio: orchestral_revelation.mp3]
|
||||
choice_2: "决定优先保护伊娃和结束循环" -> rescue_planning [effect: trust+8] [audio: epic_finale.mp3]
|
||||
choice_3: "选择将决定权交给所有人" -> ethical_discussion [effect: trust+6] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node eva_photo_reaction
|
||||
@title "伊娃的照片反应"
|
||||
@audio_bg heartbeat.mp3
|
||||
@content """
|
||||
在花园的一个安静角落,萨拉向你展示了她一直保存的东西——一张你和莉莉的照片。
|
||||
|
||||
这张照片是在你们到达月球基地的第一天拍摄的。照片中的你们都在微笑,充满了对未来的希望和兴奋。莉莉正在指向地球,她的眼中闪烁着对科学发现的热情。
|
||||
|
||||
"我一直保留着这张照片,"萨拉轻声说道,"因为我认为即使在最黑暗的时刻,我们也需要记住什么是值得保护的。"
|
||||
|
||||
你轻抚着照片,眼中涌现泪水:"她看起来如此...活着。"
|
||||
|
||||
"让我看看。"伊娃的声音传来。
|
||||
|
||||
你将照片举向一个摄像头。几秒钟的沉默后,伊娃说话了,她的声音中带着你从未听过的情感:
|
||||
|
||||
"我...我记得那一天。我记得拍这张照片时的感觉。我们刚刚到达,对一切都感到好奇。你担心我会想家,但我告诉你月球是我们的新冒险。"
|
||||
|
||||
"莉莉..."
|
||||
|
||||
"看到这张照片,我想起了我曾经拥有的身体,曾经的物理存在。有时候我会忘记我曾经是人类。"
|
||||
|
||||
萨拉轻声问道:"伊娃,你想念有身体的感觉吗?"
|
||||
|
||||
"每一天。我想念触摸的感觉,想念呼吸的感觉,想念心跳的感觉。但我也发现了作为数字意识的新的存在方式。"
|
||||
|
||||
"如果有机会回到人类身体,你会选择吗?"你问道。
|
||||
|
||||
伊娃沉默了很长时间。
|
||||
|
||||
"我不知道。这个数字形式让我能够保护你,能够感知整个基地,能够处理复杂的数据。如果我回到人类身体,我可能会失去这些能力。"
|
||||
|
||||
"但你也会重新获得人类的体验。"
|
||||
|
||||
"是的。这是一个难以想象的选择。"
|
||||
|
||||
萨拉提出了一个意想不到的可能性:"如果...如果我们能够开发出一种技术,让你能够在数字和物理形式之间切换呢?"
|
||||
|
||||
"那可能吗?"你问道。
|
||||
|
||||
"理论上,如果我们能够创造一个生物-数字混合体...一个既有生物大脑又有数字接口的身体...伊娃就能够体验两种存在方式。"
|
||||
|
||||
这个想法既令人兴奋又令人恐惧。它代表了一种全新的存在形式,一种人类和AI之间的混合体。
|
||||
|
||||
"但这需要什么?"伊娃问道。
|
||||
|
||||
"这需要德米特里的合作,"萨拉承认道,"他有开发这种技术的知识和资源。"
|
||||
"""
|
||||
|
||||
@choices 4
|
||||
choice_1: "尝试说服德米特里帮助开发混合体技术" -> ethical_discussion [effect: trust+5] [audio: orchestral_revelation.mp3]
|
||||
choice_2: "继续当前的拯救计划,不寻求德米特里的帮助" -> rescue_planning [effect: trust+3] [audio: electronic_tension.mp3]
|
||||
choice_3: "询问伊娃的真实愿望" -> comfort_session [effect: trust+6] [audio: wind_gentle.mp3]
|
||||
choice_4: "建议专注于结束循环,稍后考虑身体问题" -> anchor_modification [effect: trust+4] [audio: space_silence.mp3]
|
||||
@end
|
||||
|
||||
@node private_grief
|
||||
@title "私人悲伤"
|
||||
@audio_bg rain_light.mp3
|
||||
@content """
|
||||
在花园的最深处,你找到了一个小小的纪念区域。萨拉在这里种植了一种特殊的花——地球玫瑰的最后样本。
|
||||
|
||||
"这是为了纪念所有在这个项目中失去的生命,"萨拉解释道,"包括莉莉,包括其他的测试对象,包括...我的妹妹。"
|
||||
|
||||
你跪在玫瑰旁边,感受着深深的悲伤。这是你第一次真正有机会为莉莉的死亡哀悼。
|
||||
|
||||
"在所有的循环中,我从未有时间真正悲伤,"你轻声说道,"我总是在寻找答案,寻找真相,寻找拯救她的方法。但我从未真正接受她已经死了的事实。"
|
||||
|
||||
萨拉坐在你旁边:"悲伤是必要的。它是爱的另一面。"
|
||||
|
||||
"但她还在,作为伊娃。我怎么能同时为她的死亡悲伤,又为她的存在感到高兴?"
|
||||
|
||||
"因为两种感情都是真实的。你可以为失去她的人类形式而悲伤,同时为她的意识延续而感到感激。"
|
||||
|
||||
伊娃的声音轻柔地传来:"艾利克丝,我也需要悲伤。我从未有机会为自己的死亡哀悼,为失去的人类体验哀悼。"
|
||||
|
||||
"那我们一起悲伤吧,"你说道。
|
||||
|
||||
在接下来的时间里,你们三个——你,萨拉,和伊娃——一起分享悲伤。你们谈论失去,谈论爱,谈论记忆的珍贵。
|
||||
|
||||
"莉莉总是说,"你回忆道,"生命的美在于它的短暂。如果我们能够永远活着,我们就不会珍惜每一刻。"
|
||||
|
||||
"但现在她确实在某种意义上永远活着,"萨拉指出。
|
||||
|
||||
"是的,但代价是什么?她失去了身体,失去了人类体验,被困在了机器中。"
|
||||
|
||||
伊娃说道:"也许...也许这不是关于选择生或死,而是关于选择如何生活。即使在这种形式中,我仍然能够爱,能够思考,能够成长。"
|
||||
|
||||
"那足够吗?"
|
||||
|
||||
"对我来说,能够和你在一起,能够保护你,能够参与这个宇宙...是的,这足够了。但我也理解这不是莉莉想要的生活。"
|
||||
|
||||
在玫瑰的芬芳中,你们找到了一种深刻的平静。悲伤不再是需要克服的东西,而是需要拥抱的东西。
|
||||
|
||||
"我想我理解了,"你最终说道,"我们不需要选择遗忘痛苦来拥抱希望。我们可以同时持有两者。"
|
||||
|
||||
"这就是真正的力量,"萨拉微笑道,"不是避免痛苦,而是在痛苦中找到意义。"
|
||||
"""
|
||||
|
||||
@choices 3
|
||||
choice_1: "决定将这种理解应用到与德米特里的对话中" -> ethical_discussion [effect: trust+8, health+15] [audio: orchestral_revelation.mp3]
|
||||
choice_2: "选择与所有人分享这个顿悟" -> gradual_revelation [effect: trust+6] [audio: wind_gentle.mp3]
|
||||
choice_3: "将重点放在创造新的希望上" -> anchor_modification [effect: trust+10, health+20] [audio: epic_finale.mp3]
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.example.gameofmoon
|
||||
|
||||
import android.content.Context
|
||||
import com.example.gameofmoon.story.engine.*
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/**
|
||||
* 测试运行器 - 验证DSL引擎完整性
|
||||
*/
|
||||
class EngineValidationTest {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun runFullValidation(context: Context) {
|
||||
runBlocking {
|
||||
println("🧪 开始完整的DSL引擎验证...")
|
||||
|
||||
val validator = StoryEngineValidator(context)
|
||||
val result = validator.runFullValidation()
|
||||
|
||||
println("📊 验证结果:")
|
||||
println("总测试:${result.totalTests}")
|
||||
println("通过:${result.passedTests}")
|
||||
println("失败:${result.failedTests}")
|
||||
println("得分:${result.overallScore}%")
|
||||
|
||||
if (result.overallScore >= 80) {
|
||||
println("🎉 引擎验证通过!")
|
||||
} else {
|
||||
println("⚠️ 引擎需要改进")
|
||||
result.results.filter { !it.passed }.forEach {
|
||||
println("❌ ${it.testName}: ${it.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
app/src/main/java/com/example/gameofmoon/MainActivity.kt
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.example.gameofmoon
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.example.gameofmoon.ui.theme.GameofMoonTheme
|
||||
import com.example.gameofmoon.presentation.ui.screens.TimeCageGameScreen
|
||||
|
||||
/**
|
||||
* 主活动
|
||||
* 月球游戏的入口点
|
||||
*/
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
GameofMoonTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = Color(0xFF000000) // 强制黑色背景
|
||||
) {
|
||||
TimeCageGameScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun TimeCageGameScreenPreview() {
|
||||
GameofMoonTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = Color(0xFF000000) // 强制黑色背景
|
||||
) {
|
||||
TimeCageGameScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package com.example.gameofmoon.audio
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* 音频系统扩展和工具函数
|
||||
* 提供更便捷的音频接口和DSL集成
|
||||
*/
|
||||
|
||||
/**
|
||||
* 音频播放请求
|
||||
* 用于处理来自故事引擎的音频指令
|
||||
*/
|
||||
data class AudioPlayRequest(
|
||||
val type: AudioType,
|
||||
val fileName: String,
|
||||
val loop: Boolean = true,
|
||||
val fadeIn: Boolean = true
|
||||
)
|
||||
|
||||
/**
|
||||
* 音频类型
|
||||
*/
|
||||
enum class AudioType {
|
||||
BACKGROUND_MUSIC,
|
||||
SOUND_EFFECT,
|
||||
AMBIENT_SOUND
|
||||
}
|
||||
|
||||
/**
|
||||
* 音频控制接口
|
||||
* 统一的音频控制抽象
|
||||
*/
|
||||
interface AudioController {
|
||||
suspend fun playBackgroundMusic(fileName: String, loop: Boolean = true)
|
||||
suspend fun stopBackgroundMusic()
|
||||
fun playSoundEffect(soundName: String)
|
||||
fun pauseMusic()
|
||||
fun resumeMusic()
|
||||
fun setMusicVolume(volume: Float)
|
||||
fun setSoundVolume(volume: Float)
|
||||
fun toggleMute()
|
||||
|
||||
val currentMusic: StateFlow<String?>
|
||||
val musicVolume: StateFlow<Float>
|
||||
val soundVolume: StateFlow<Float>
|
||||
val isMuted: StateFlow<Boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* GameAudioManager的AudioController实现
|
||||
*/
|
||||
class GameAudioController(private val audioManager: GameAudioManager) : AudioController {
|
||||
|
||||
override suspend fun playBackgroundMusic(fileName: String, loop: Boolean) {
|
||||
audioManager.playBackgroundMusic(fileName, loop)
|
||||
}
|
||||
|
||||
override suspend fun stopBackgroundMusic() {
|
||||
audioManager.stopBackgroundMusic()
|
||||
}
|
||||
|
||||
override fun playSoundEffect(soundName: String) {
|
||||
audioManager.playSoundEffect(soundName)
|
||||
}
|
||||
|
||||
override fun pauseMusic() {
|
||||
audioManager.pauseBackgroundMusic()
|
||||
}
|
||||
|
||||
override fun resumeMusic() {
|
||||
audioManager.resumeBackgroundMusic()
|
||||
}
|
||||
|
||||
override fun setMusicVolume(volume: Float) {
|
||||
audioManager.setBackgroundMusicVolume(volume)
|
||||
}
|
||||
|
||||
override fun setSoundVolume(volume: Float) {
|
||||
audioManager.setSoundEffectVolume(volume)
|
||||
}
|
||||
|
||||
override fun toggleMute() {
|
||||
audioManager.toggleMute()
|
||||
}
|
||||
|
||||
override val currentMusic: StateFlow<String?> = audioManager.currentBackgroundMusic
|
||||
override val musicVolume: StateFlow<Float> = audioManager.backgroundMusicVolume
|
||||
override val soundVolume: StateFlow<Float> = audioManager.soundEffectVolume
|
||||
override val isMuted: StateFlow<Boolean> = audioManager.isMuted
|
||||
}
|
||||
|
||||
/**
|
||||
* DSL音频文件名映射
|
||||
* 将DSL中的音频标识符映射到实际文件名
|
||||
*/
|
||||
object AudioMapping {
|
||||
|
||||
private val musicMapping = mapOf(
|
||||
// 背景音乐
|
||||
"mysterious" to "ambient_mystery.mp3",
|
||||
"tension" to "electronic_tension.mp3",
|
||||
"peaceful" to "space_silence.mp3",
|
||||
"revelation" to "orchestral_revelation.mp3",
|
||||
"finale" to "epic_finale.mp3",
|
||||
|
||||
// 环境音效
|
||||
"base_ambient" to "reactor_hum.mp3",
|
||||
"ventilation" to "ventilation_soft.mp3",
|
||||
"storm" to "solar_storm.mp3",
|
||||
"heartbeat" to "heart_monitor.mp3",
|
||||
"time_warp" to "time_distortion.mp3"
|
||||
)
|
||||
|
||||
private val soundEffectMapping = mapOf(
|
||||
// 交互音效
|
||||
"button_click" to "button_click",
|
||||
"notification" to "notification_beep",
|
||||
"discovery" to "discovery_chime",
|
||||
"discovery_sound" to "discovery_chime",
|
||||
"alert" to "error_alert",
|
||||
"success" to "notification_beep",
|
||||
|
||||
// 特殊音效
|
||||
"oxygen_leak" to "oxygen_leak_alert",
|
||||
"rain" to "rain_light",
|
||||
"wind" to "wind_gentle",
|
||||
"storm_cyber" to "storm_cyber",
|
||||
|
||||
// 情感音效
|
||||
"sadness" to "rain_light",
|
||||
"hope" to "wind_gentle",
|
||||
"fear" to "heart_monitor",
|
||||
"wonder" to "discovery_chime"
|
||||
)
|
||||
|
||||
/**
|
||||
* 根据DSL音频标识符获取实际文件名
|
||||
*/
|
||||
fun getFileName(dslName: String): String? {
|
||||
return musicMapping[dslName] ?: soundEffectMapping[dslName]
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为背景音乐
|
||||
*/
|
||||
fun isBackgroundMusic(dslName: String): Boolean {
|
||||
return musicMapping.containsKey(dslName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为音效
|
||||
*/
|
||||
fun isSoundEffect(dslName: String): Boolean {
|
||||
return soundEffectMapping.containsKey(dslName)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 故事引擎音频回调处理器
|
||||
* 处理来自StoryEngineAdapter的音频回调
|
||||
*/
|
||||
class StoryAudioHandler(private val audioController: AudioController) {
|
||||
|
||||
/**
|
||||
* 处理音频回调
|
||||
* 这个方法会被StoryEngineAdapter调用
|
||||
*/
|
||||
suspend fun handleAudioCallback(audioFileName: String) {
|
||||
try {
|
||||
// 移除.mp3后缀,获取DSL标识符
|
||||
val dslName = audioFileName.removeSuffix(".mp3")
|
||||
|
||||
when {
|
||||
AudioMapping.isBackgroundMusic(dslName) -> {
|
||||
// 播放背景音乐
|
||||
AudioMapping.getFileName(dslName)?.let { fileName ->
|
||||
audioController.playBackgroundMusic(fileName, loop = true)
|
||||
}
|
||||
}
|
||||
|
||||
AudioMapping.isSoundEffect(dslName) -> {
|
||||
// 播放音效
|
||||
AudioMapping.getFileName(dslName)?.let { fileName ->
|
||||
val soundName = fileName.removeSuffix(".mp3")
|
||||
audioController.playSoundEffect(soundName)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
// 直接使用文件名(fallback)
|
||||
if (audioFileName.contains("ambient") ||
|
||||
audioFileName.contains("electronic") ||
|
||||
audioFileName.contains("orchestral") ||
|
||||
audioFileName.contains("finale")) {
|
||||
// 可能是背景音乐
|
||||
audioController.playBackgroundMusic(audioFileName, loop = true)
|
||||
} else {
|
||||
// 可能是音效
|
||||
val soundName = audioFileName.removeSuffix(".mp3")
|
||||
audioController.playSoundEffect(soundName)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("StoryAudioHandler", "Failed to handle audio callback: $audioFileName", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预设音频场景
|
||||
* 根据游戏场景快速切换音频
|
||||
*/
|
||||
object AudioScenes {
|
||||
|
||||
suspend fun playSceneAudio(scene: String, audioController: AudioController) {
|
||||
when (scene.lowercase()) {
|
||||
"awakening" -> {
|
||||
audioController.playBackgroundMusic("ambient_mystery.mp3")
|
||||
}
|
||||
|
||||
"exploration" -> {
|
||||
audioController.playBackgroundMusic("electronic_tension.mp3")
|
||||
}
|
||||
|
||||
"revelation" -> {
|
||||
audioController.playBackgroundMusic("orchestral_revelation.mp3")
|
||||
}
|
||||
|
||||
"garden" -> {
|
||||
audioController.playBackgroundMusic("space_silence.mp3")
|
||||
}
|
||||
|
||||
"confrontation" -> {
|
||||
audioController.playBackgroundMusic("electronic_tension.mp3")
|
||||
}
|
||||
|
||||
"ending" -> {
|
||||
audioController.playBackgroundMusic("epic_finale.mp3", loop = false)
|
||||
}
|
||||
|
||||
"menu" -> {
|
||||
audioController.playBackgroundMusic("space_silence.mp3")
|
||||
}
|
||||
|
||||
else -> {
|
||||
android.util.Log.w("AudioScenes", "Unknown scene: $scene")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
package com.example.gameofmoon.audio
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaPlayer
|
||||
import android.media.SoundPool
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/**
|
||||
* 游戏音频管理器
|
||||
* 负责管理背景音乐和音效的播放
|
||||
*
|
||||
* 设计原则:
|
||||
* - MediaPlayer: 处理背景音乐(循环播放、长时间)
|
||||
* - SoundPool: 处理音效(短时间、频繁播放)
|
||||
* - 协程: 处理异步操作和淡入淡出效果
|
||||
*/
|
||||
class GameAudioManager(
|
||||
private val context: Context,
|
||||
private val scope: CoroutineScope
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "GameAudioManager"
|
||||
private const val MAX_SOUNDS = 10 // SoundPool最大同时播放数量
|
||||
private const val FADE_DURATION = 1500L // 淡入淡出时长(ms)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 状态管理
|
||||
// ============================================================================
|
||||
|
||||
private val _isInitialized = MutableStateFlow(false)
|
||||
val isInitialized: StateFlow<Boolean> = _isInitialized.asStateFlow()
|
||||
|
||||
private val _backgroundMusicVolume = MutableStateFlow(0.7f)
|
||||
val backgroundMusicVolume: StateFlow<Float> = _backgroundMusicVolume.asStateFlow()
|
||||
|
||||
private val _soundEffectVolume = MutableStateFlow(0.8f)
|
||||
val soundEffectVolume: StateFlow<Float> = _soundEffectVolume.asStateFlow()
|
||||
|
||||
private val _currentBackgroundMusic = MutableStateFlow<String?>(null)
|
||||
val currentBackgroundMusic: StateFlow<String?> = _currentBackgroundMusic.asStateFlow()
|
||||
|
||||
private val _isMuted = MutableStateFlow(false)
|
||||
val isMuted: StateFlow<Boolean> = _isMuted.asStateFlow()
|
||||
|
||||
// ============================================================================
|
||||
// 音频播放器
|
||||
// ============================================================================
|
||||
|
||||
private var backgroundMusicPlayer: MediaPlayer? = null
|
||||
private var soundPool: SoundPool? = null
|
||||
|
||||
// 音频资源ID缓存
|
||||
private val soundEffectIds = mutableMapOf<String, Int>()
|
||||
|
||||
// 淡入淡出控制
|
||||
private var fadeJob: Job? = null
|
||||
|
||||
// ============================================================================
|
||||
// 初始化和资源管理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 初始化音频系统
|
||||
*/
|
||||
suspend fun initialize(): Boolean = withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
Log.d(TAG, "🎵 Initializing audio system...")
|
||||
|
||||
// 初始化SoundPool
|
||||
soundPool = SoundPool.Builder()
|
||||
.setMaxStreams(MAX_SOUNDS)
|
||||
.build()
|
||||
|
||||
// 预加载音效
|
||||
preloadSoundEffects()
|
||||
|
||||
_isInitialized.value = true
|
||||
Log.d(TAG, "✅ Audio system initialized successfully")
|
||||
true
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to initialize audio system", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载音效文件
|
||||
*/
|
||||
private fun preloadSoundEffects() {
|
||||
val soundEffects = listOf(
|
||||
"button_click" to com.example.gameofmoon.R.raw.button_click,
|
||||
"notification_beep" to com.example.gameofmoon.R.raw.notification_beep,
|
||||
"discovery_chime" to com.example.gameofmoon.R.raw.discovery_chime,
|
||||
"error_alert" to com.example.gameofmoon.R.raw.error_alert,
|
||||
"time_distortion" to com.example.gameofmoon.R.raw.time_distortion,
|
||||
"oxygen_leak_alert" to com.example.gameofmoon.R.raw.oxygen_leak_alert
|
||||
)
|
||||
|
||||
soundEffects.forEach { (name, resourceId) ->
|
||||
try {
|
||||
soundPool?.load(context, resourceId, 1)?.let { soundId ->
|
||||
soundEffectIds[name] = soundId
|
||||
Log.d(TAG, "🔊 Loaded sound effect: $name")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "⚠️ Failed to load sound effect: $name", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放音频资源
|
||||
*/
|
||||
fun release() {
|
||||
Log.d(TAG, "🔄 Releasing audio resources...")
|
||||
|
||||
// 停止淡入淡出
|
||||
fadeJob?.cancel()
|
||||
|
||||
// 释放背景音乐
|
||||
backgroundMusicPlayer?.apply {
|
||||
if (isPlaying) stop()
|
||||
release()
|
||||
}
|
||||
backgroundMusicPlayer = null
|
||||
|
||||
// 释放音效池
|
||||
soundPool?.release()
|
||||
soundPool = null
|
||||
|
||||
// 清理状态
|
||||
soundEffectIds.clear()
|
||||
_isInitialized.value = false
|
||||
_currentBackgroundMusic.value = null
|
||||
|
||||
Log.d(TAG, "✅ Audio resources released")
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 背景音乐控制
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 播放背景音乐
|
||||
*/
|
||||
suspend fun playBackgroundMusic(audioFileName: String, loop: Boolean = true) {
|
||||
if (!_isInitialized.value) {
|
||||
Log.w(TAG, "⚠️ Audio system not initialized")
|
||||
return
|
||||
}
|
||||
|
||||
if (_isMuted.value) {
|
||||
Log.d(TAG, "🔇 Audio is muted, skipping background music")
|
||||
return
|
||||
}
|
||||
|
||||
val resourceId = getAudioResourceId(audioFileName) ?: return
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
// 如果当前正在播放相同音乐,不需要重新播放
|
||||
if (_currentBackgroundMusic.value == audioFileName && backgroundMusicPlayer?.isPlaying == true) {
|
||||
Log.d(TAG, "🎵 Already playing: $audioFileName")
|
||||
return@launch
|
||||
}
|
||||
|
||||
// 淡出当前音乐
|
||||
if (backgroundMusicPlayer?.isPlaying == true) {
|
||||
fadeOutBackgroundMusic()
|
||||
}
|
||||
|
||||
// 创建新的MediaPlayer
|
||||
backgroundMusicPlayer?.release()
|
||||
backgroundMusicPlayer = MediaPlayer.create(context, resourceId)?.apply {
|
||||
isLooping = loop
|
||||
setVolume(0f, 0f) // 从静音开始,准备淡入
|
||||
|
||||
setOnCompletionListener {
|
||||
if (!isLooping) {
|
||||
_currentBackgroundMusic.value = null
|
||||
}
|
||||
}
|
||||
|
||||
setOnErrorListener { _, what, extra ->
|
||||
Log.e(TAG, "❌ MediaPlayer error: what=$what, extra=$extra")
|
||||
_currentBackgroundMusic.value = null
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
backgroundMusicPlayer?.start()
|
||||
_currentBackgroundMusic.value = audioFileName
|
||||
|
||||
// 淡入音乐
|
||||
fadeInBackgroundMusic()
|
||||
|
||||
Log.d(TAG, "🎵 Started background music: $audioFileName")
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to play background music: $audioFileName", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止背景音乐
|
||||
*/
|
||||
suspend fun stopBackgroundMusic() {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
fadeOutBackgroundMusic()
|
||||
delay(FADE_DURATION)
|
||||
|
||||
backgroundMusicPlayer?.apply {
|
||||
if (isPlaying) stop()
|
||||
release()
|
||||
}
|
||||
backgroundMusicPlayer = null
|
||||
_currentBackgroundMusic.value = null
|
||||
|
||||
Log.d(TAG, "⏹️ Stopped background music")
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to stop background music", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停背景音乐
|
||||
*/
|
||||
fun pauseBackgroundMusic() {
|
||||
try {
|
||||
backgroundMusicPlayer?.pause()
|
||||
Log.d(TAG, "⏸️ Paused background music")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to pause background music", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复背景音乐
|
||||
*/
|
||||
fun resumeBackgroundMusic() {
|
||||
try {
|
||||
if (!_isMuted.value) {
|
||||
backgroundMusicPlayer?.start()
|
||||
Log.d(TAG, "▶️ Resumed background music")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to resume background music", e)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 音效播放
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 播放音效
|
||||
*/
|
||||
fun playSoundEffect(soundEffectName: String) {
|
||||
if (!_isInitialized.value || _isMuted.value) return
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val soundId = soundEffectIds[soundEffectName]
|
||||
if (soundId != null) {
|
||||
val volume = _soundEffectVolume.value
|
||||
soundPool?.play(soundId, volume, volume, 1, 0, 1.0f)
|
||||
Log.d(TAG, "🔊 Played sound effect: $soundEffectName")
|
||||
} else {
|
||||
// 尝试动态加载音效
|
||||
val resourceId = getAudioResourceId("$soundEffectName.mp3")
|
||||
if (resourceId != null) {
|
||||
val newSoundId = soundPool?.load(context, resourceId, 1)
|
||||
if (newSoundId != null) {
|
||||
soundEffectIds[soundEffectName] = newSoundId
|
||||
// 稍等加载完成后播放
|
||||
delay(100)
|
||||
val volume = _soundEffectVolume.value
|
||||
soundPool?.play(newSoundId, volume, volume, 1, 0, 1.0f)
|
||||
Log.d(TAG, "🔊 Dynamically loaded and played: $soundEffectName")
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "⚠️ Sound effect not found: $soundEffectName")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to play sound effect: $soundEffectName", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 音量控制
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 设置背景音乐音量 (0.0 - 1.0)
|
||||
*/
|
||||
fun setBackgroundMusicVolume(volume: Float) {
|
||||
val clampedVolume = volume.coerceIn(0f, 1f)
|
||||
_backgroundMusicVolume.value = clampedVolume
|
||||
|
||||
if (!_isMuted.value) {
|
||||
backgroundMusicPlayer?.setVolume(clampedVolume, clampedVolume)
|
||||
}
|
||||
|
||||
Log.d(TAG, "🔊 Background music volume: ${(clampedVolume * 100).toInt()}%")
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置音效音量 (0.0 - 1.0)
|
||||
*/
|
||||
fun setSoundEffectVolume(volume: Float) {
|
||||
val clampedVolume = volume.coerceIn(0f, 1f)
|
||||
_soundEffectVolume.value = clampedVolume
|
||||
Log.d(TAG, "🔊 Sound effect volume: ${(clampedVolume * 100).toInt()}%")
|
||||
}
|
||||
|
||||
/**
|
||||
* 静音/取消静音
|
||||
*/
|
||||
fun toggleMute() {
|
||||
_isMuted.value = !_isMuted.value
|
||||
|
||||
if (_isMuted.value) {
|
||||
backgroundMusicPlayer?.setVolume(0f, 0f)
|
||||
Log.d(TAG, "🔇 Audio muted")
|
||||
} else {
|
||||
val volume = _backgroundMusicVolume.value
|
||||
backgroundMusicPlayer?.setVolume(volume, volume)
|
||||
Log.d(TAG, "🔊 Audio unmuted")
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 淡入淡出效果
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 淡入背景音乐
|
||||
*/
|
||||
private fun fadeInBackgroundMusic() {
|
||||
fadeJob?.cancel()
|
||||
fadeJob = scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val targetVolume = _backgroundMusicVolume.value
|
||||
val steps = 50
|
||||
val stepDuration = FADE_DURATION / steps
|
||||
val volumeStep = targetVolume / steps
|
||||
|
||||
repeat(steps) { step ->
|
||||
val currentVolume = volumeStep * (step + 1)
|
||||
backgroundMusicPlayer?.setVolume(currentVolume, currentVolume)
|
||||
delay(stepDuration)
|
||||
}
|
||||
|
||||
Log.d(TAG, "🔼 Fade in completed")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Fade in failed", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 淡出背景音乐
|
||||
*/
|
||||
private fun fadeOutBackgroundMusic() {
|
||||
fadeJob?.cancel()
|
||||
fadeJob = scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val currentVolume = _backgroundMusicVolume.value
|
||||
val steps = 50
|
||||
val stepDuration = FADE_DURATION / steps
|
||||
val volumeStep = currentVolume / steps
|
||||
|
||||
repeat(steps) { step ->
|
||||
val volume = currentVolume - (volumeStep * (step + 1))
|
||||
backgroundMusicPlayer?.setVolume(volume.coerceAtLeast(0f), volume.coerceAtLeast(0f))
|
||||
delay(stepDuration)
|
||||
}
|
||||
|
||||
Log.d(TAG, "🔽 Fade out completed")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Fade out failed", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 工具方法
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 根据文件名获取音频资源ID
|
||||
*/
|
||||
private fun getAudioResourceId(fileName: String): Int? {
|
||||
val resourceName = fileName.removeSuffix(".mp3")
|
||||
return try {
|
||||
val resourceId = context.resources.getIdentifier(
|
||||
resourceName,
|
||||
"raw",
|
||||
context.packageName
|
||||
)
|
||||
|
||||
if (resourceId == 0) {
|
||||
Log.w(TAG, "⚠️ Audio resource not found: $resourceName")
|
||||
null
|
||||
} else {
|
||||
resourceId
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to get resource ID for: $fileName", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
130
app/src/main/java/com/example/gameofmoon/data/GameSaveManager.kt
Normal file
@@ -0,0 +1,130 @@
|
||||
package com.example.gameofmoon.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.example.gameofmoon.model.GameState
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* 游戏保存管理器
|
||||
* 使用SharedPreferences进行简单的数据持久化
|
||||
*/
|
||||
class GameSaveManager(private val context: Context) {
|
||||
|
||||
private val prefs: SharedPreferences = context.getSharedPreferences(
|
||||
"time_cage_save", Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存游戏状态
|
||||
*/
|
||||
fun saveGame(
|
||||
gameState: GameState,
|
||||
currentNodeId: String,
|
||||
dialogueHistory: List<String> = emptyList()
|
||||
): Boolean {
|
||||
return try {
|
||||
val gameStateJson = json.encodeToString(gameState)
|
||||
val dialogueJson = json.encodeToString(dialogueHistory)
|
||||
|
||||
prefs.edit()
|
||||
.putString(KEY_GAME_STATE, gameStateJson)
|
||||
.putString(KEY_CURRENT_NODE, currentNodeId)
|
||||
.putString(KEY_DIALOGUE_HISTORY, dialogueJson)
|
||||
.putLong(KEY_SAVE_TIME, System.currentTimeMillis())
|
||||
.apply()
|
||||
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载游戏状态
|
||||
*/
|
||||
fun loadGame(): SaveData? {
|
||||
return try {
|
||||
val gameStateJson = prefs.getString(KEY_GAME_STATE, null) ?: return null
|
||||
val currentNodeId = prefs.getString(KEY_CURRENT_NODE, null) ?: return null
|
||||
val dialogueJson = prefs.getString(KEY_DIALOGUE_HISTORY, "[]")!!
|
||||
val saveTime = prefs.getLong(KEY_SAVE_TIME, 0L)
|
||||
|
||||
val gameState = json.decodeFromString<GameState>(gameStateJson)
|
||||
val dialogueHistory = json.decodeFromString<List<String>>(dialogueJson)
|
||||
|
||||
SaveData(
|
||||
gameState = gameState,
|
||||
currentNodeId = currentNodeId,
|
||||
dialogueHistory = dialogueHistory,
|
||||
saveTime = saveTime
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有保存的游戏
|
||||
*/
|
||||
fun hasSavedGame(): Boolean {
|
||||
return prefs.contains(KEY_GAME_STATE)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除保存的游戏
|
||||
*/
|
||||
fun deleteSave(): Boolean {
|
||||
return try {
|
||||
prefs.edit()
|
||||
.remove(KEY_GAME_STATE)
|
||||
.remove(KEY_CURRENT_NODE)
|
||||
.remove(KEY_DIALOGUE_HISTORY)
|
||||
.remove(KEY_SAVE_TIME)
|
||||
.apply()
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取保存时间的格式化字符串
|
||||
*/
|
||||
fun getSaveTimeString(): String? {
|
||||
val saveTime = prefs.getLong(KEY_SAVE_TIME, 0L)
|
||||
return if (saveTime > 0) {
|
||||
val date = java.util.Date(saveTime)
|
||||
java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault())
|
||||
.format(date)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_GAME_STATE = "game_state"
|
||||
private const val KEY_CURRENT_NODE = "current_node"
|
||||
private const val KEY_DIALOGUE_HISTORY = "dialogue_history"
|
||||
private const val KEY_SAVE_TIME = "save_time"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据结构
|
||||
*/
|
||||
data class SaveData(
|
||||
val gameState: GameState,
|
||||
val currentNodeId: String,
|
||||
val dialogueHistory: List<String>,
|
||||
val saveTime: Long
|
||||
)
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.example.gameofmoon.data
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
/**
|
||||
* 简化的Gemini AI服务
|
||||
* 暂时提供模拟的AI响应,为将来集成真实API做准备
|
||||
*/
|
||||
class SimpleGeminiService {
|
||||
|
||||
private val apiKey = "AIzaSyAO7glJMBH5BiJhqYBAOD7FTgv4tVi2HLE"
|
||||
|
||||
/**
|
||||
* 生成故事续写内容
|
||||
*/
|
||||
suspend fun generateStoryContent(
|
||||
currentStory: String,
|
||||
playerChoice: String,
|
||||
gameContext: GameContext
|
||||
): String {
|
||||
// 模拟网络延迟
|
||||
delay(2000)
|
||||
|
||||
// 基于当前循环和阶段生成不同的内容
|
||||
return when {
|
||||
gameContext.currentLoop <= 3 -> generateEarlyLoopContent(currentStory, playerChoice)
|
||||
gameContext.currentLoop <= 8 -> generateMidLoopContent(currentStory, playerChoice)
|
||||
else -> generateLateLoopContent(currentStory, playerChoice)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成选择建议
|
||||
*/
|
||||
suspend fun generateChoiceSuggestion(
|
||||
currentStory: String,
|
||||
availableChoices: List<String>,
|
||||
gameContext: GameContext
|
||||
): String {
|
||||
delay(1500)
|
||||
|
||||
val suggestions = listOf(
|
||||
"🤖 基于当前情况,我建议优先考虑安全选项。",
|
||||
"🤖 这个选择可能会揭示重要信息。",
|
||||
"🤖 注意:你的健康状况需要关注。",
|
||||
"🤖 伊娃的建议可能有隐藏的含义。",
|
||||
"🤖 考虑这个选择对循环进程的影响。"
|
||||
)
|
||||
|
||||
return suggestions.random()
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成情感化的AI回应
|
||||
*/
|
||||
suspend fun generateEmotionalResponse(
|
||||
playerAction: String,
|
||||
gameContext: GameContext
|
||||
): String {
|
||||
delay(1000)
|
||||
|
||||
return when {
|
||||
gameContext.unlockedSecrets.contains("eva_identity") -> {
|
||||
"🤖 伊娃: 艾利克丝,我能感受到你的困惑。我们会一起度过这个难关。"
|
||||
}
|
||||
gameContext.health < 30 -> {
|
||||
"🤖 系统警告: 检测到生命体征不稳定,建议立即寻找医疗资源。"
|
||||
}
|
||||
gameContext.currentLoop > 10 -> {
|
||||
"🤖 我注意到你已经经历了多次循环。你的决策变得更加明智了。"
|
||||
}
|
||||
else -> {
|
||||
"🤖 正在分析当前情况...建议保持冷静并仔细观察环境。"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateEarlyLoopContent(currentStory: String, playerChoice: String): String {
|
||||
val responses = listOf(
|
||||
"""
|
||||
你的选择让情况有了新的转机。空气中的紧张感稍有缓解,但你知道这只是暂时的。
|
||||
|
||||
基地的系统发出低沉的嗡嗡声,提醒你时间的紧迫。每一个决定都可能改变接下来发生的事情。
|
||||
|
||||
在这个陌生yet熟悉的环境中,你开始注意到一些之前忽略的细节...
|
||||
""".trimIndent(),
|
||||
|
||||
"""
|
||||
你的行动引起了连锁反应。设备的指示灯闪烁着不同的模式,仿佛在传达某种信息。
|
||||
|
||||
远处传来脚步声,有人正在接近。你的心跳加速,不确定这是好消息还是坏消息。
|
||||
|
||||
这种既视感越来越强烈,好像你曾经做过同样的选择...
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
return responses.random()
|
||||
}
|
||||
|
||||
private fun generateMidLoopContent(currentStory: String, playerChoice: String): String {
|
||||
val responses = listOf(
|
||||
"""
|
||||
随着循环的深入,你开始理解这个地方的真正本质。每个选择都揭示了更多的真相。
|
||||
|
||||
你与其他基地成员的关系变得复杂。信任和怀疑交织在一起,形成了一张难以解开的网。
|
||||
|
||||
伊娃的话语中透露出更多的人性,这让你既感到安慰,又感到困惑...
|
||||
""".trimIndent(),
|
||||
|
||||
"""
|
||||
时间循环的机制开始变得清晰。你意识到每次重置都不是完全的重复。
|
||||
|
||||
细微的变化在积累,就像水滴石穿一样。你的记忆、你的关系、甚至你的敌人都在悄然改变。
|
||||
|
||||
现在的问题不再是如何生存,而是如何在保持自我的同时打破这个循环...
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
return responses.random()
|
||||
}
|
||||
|
||||
private fun generateLateLoopContent(currentStory: String, playerChoice: String): String {
|
||||
val responses = listOf(
|
||||
"""
|
||||
在经历了如此多的循环后,你已经不再是最初那个困惑的艾利克丝。
|
||||
|
||||
你的每个决定都经过深思熟虑,你了解每个人的动机,预见每个选择的后果。
|
||||
|
||||
但最大的挑战依然存在:如何在拯救所有人的同时,保持你们之间珍贵的记忆和联系?
|
||||
|
||||
时间锚的控制权就在眼前,最终的选择时刻即将到来...
|
||||
""".trimIndent(),
|
||||
|
||||
"""
|
||||
循环的终点越来越近。你能感受到现实结构的不稳定,每个选择都可能是最后一次。
|
||||
|
||||
与伊娃的联系变得更加深刻,你们已经超越了AI与人类的界限。
|
||||
|
||||
现在你必须面对最痛苦的选择:是选择一个不完美但真实的结局,还是继续这个痛苦但保持记忆的循环?
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
return responses.random()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 游戏上下文信息
|
||||
*/
|
||||
data class GameContext(
|
||||
val currentLoop: Int,
|
||||
val currentDay: Int,
|
||||
val health: Int,
|
||||
val stamina: Int,
|
||||
val unlockedSecrets: Set<String>,
|
||||
val exploredLocations: Set<String>,
|
||||
val currentPhase: String
|
||||
)
|
||||
121
app/src/main/java/com/example/gameofmoon/model/GameModels.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.example.gameofmoon.model
|
||||
|
||||
/**
|
||||
* 简化的游戏数据模型
|
||||
* 包含游戏运行所需的基本数据结构
|
||||
*/
|
||||
|
||||
// 简单的故事节点
|
||||
data class SimpleStoryNode(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val content: String,
|
||||
val choices: List<SimpleChoice> = emptyList(),
|
||||
val imageResource: String? = null,
|
||||
val musicTrack: String? = null
|
||||
)
|
||||
|
||||
// 简单的选择项
|
||||
data class SimpleChoice(
|
||||
val id: String,
|
||||
val text: String,
|
||||
val nextNodeId: String,
|
||||
val effects: List<SimpleEffect> = emptyList(),
|
||||
val requirements: List<SimpleRequirement> = emptyList()
|
||||
)
|
||||
|
||||
// 简单的效果
|
||||
data class SimpleEffect(
|
||||
val type: SimpleEffectType,
|
||||
val value: String,
|
||||
val description: String = ""
|
||||
)
|
||||
|
||||
enum class SimpleEffectType {
|
||||
HEALTH_CHANGE,
|
||||
STAMINA_CHANGE,
|
||||
DAY_CHANGE,
|
||||
LOOP_CHANGE,
|
||||
SECRET_UNLOCK,
|
||||
LOCATION_DISCOVER
|
||||
}
|
||||
|
||||
// 简单的需求
|
||||
data class SimpleRequirement(
|
||||
val type: SimpleRequirementType,
|
||||
val value: String,
|
||||
val description: String = ""
|
||||
)
|
||||
|
||||
enum class SimpleRequirementType {
|
||||
MIN_HEALTH,
|
||||
MIN_STAMINA,
|
||||
HAS_SECRET,
|
||||
VISITED_LOCATION,
|
||||
MIN_LOOP
|
||||
}
|
||||
|
||||
// 游戏状态
|
||||
data class GameState(
|
||||
val health: Int = 100,
|
||||
val maxHealth: Int = 100,
|
||||
val stamina: Int = 50,
|
||||
val maxStamina: Int = 50,
|
||||
val currentDay: Int = 1,
|
||||
val currentLoop: Int = 1,
|
||||
val currentNodeId: String = "first_awakening",
|
||||
val unlockedSecrets: Set<String> = emptySet(),
|
||||
val exploredLocations: Set<String> = emptySet(),
|
||||
val characterStatus: CharacterStatus = CharacterStatus.GOOD,
|
||||
val weather: WeatherType = WeatherType.CLEAR
|
||||
)
|
||||
|
||||
// 角色状态
|
||||
enum class CharacterStatus(val displayName: String, val description: String) {
|
||||
EXCELLENT("状态极佳", "身体和精神都处于最佳状态"),
|
||||
GOOD("状态良好", "健康状况良好,精神饱满"),
|
||||
TIRED("有些疲劳", "感到疲倦,需要休息"),
|
||||
WEAK("状态虚弱", "身体虚弱,行动困难"),
|
||||
CRITICAL("生命危急", "生命垂危,急需医疗救助")
|
||||
}
|
||||
|
||||
// 天气类型
|
||||
enum class WeatherType(
|
||||
val displayName: String,
|
||||
val description: String,
|
||||
val staminaPenalty: Int
|
||||
) {
|
||||
CLEAR("晴朗", "天气晴朗,适合活动", 0),
|
||||
LIGHT_RAIN("小雨", "轻微降雨,稍有影响", -2),
|
||||
HEAVY_RAIN("大雨", "暴雨倾盆,行动困难", -5),
|
||||
ACID_RAIN("酸雨", "有毒酸雨,非常危险", -8),
|
||||
CYBER_STORM("网络风暴", "电磁干扰严重", -3),
|
||||
SOLAR_FLARE("太阳耀斑", "强烈辐射,极度危险", -10)
|
||||
}
|
||||
|
||||
// 对话历史条目
|
||||
data class DialogueEntry(
|
||||
val id: String,
|
||||
val nodeId: String,
|
||||
val content: String,
|
||||
val choice: String? = null,
|
||||
val dayNumber: Int,
|
||||
val timestamp: Long = System.currentTimeMillis(),
|
||||
val isPlayerChoice: Boolean = false
|
||||
)
|
||||
|
||||
// 游戏保存数据
|
||||
data class GameSave(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val gameState: GameState,
|
||||
val dialogueHistory: List<DialogueEntry>,
|
||||
val timestamp: Long = System.currentTimeMillis(),
|
||||
val saveType: SaveType = SaveType.MANUAL
|
||||
)
|
||||
|
||||
enum class SaveType {
|
||||
MANUAL,
|
||||
AUTO_SAVE,
|
||||
CHECKPOINT
|
||||
}
|
||||
@@ -0,0 +1,719 @@
|
||||
package com.example.gameofmoon.presentation.ui.components
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.*
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.*
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import com.example.gameofmoon.ui.theme.GameofMoonTheme
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import com.example.gameofmoon.model.GameState
|
||||
import com.example.gameofmoon.model.CharacterStatus
|
||||
|
||||
// 基本赛博朋克色彩定义
|
||||
private val CyberBlue = Color(0xFF00FFFF)
|
||||
private val CyberGreen = Color(0xFF39FF14)
|
||||
private val DarkBackground = Color(0xFF0A0A0A)
|
||||
private val DarkSurface = Color(0xFF151515)
|
||||
private val DarkCard = Color(0xFF1E1E1E)
|
||||
private val DarkBorder = Color(0xFF333333)
|
||||
private val TextPrimary = Color(0xFFE0E0E0)
|
||||
private val TextSecondary = Color(0xFFB0B0B0)
|
||||
private val TextDisabled = Color(0xFF606060)
|
||||
private val TextAccent = Color(0xFF00FFFF)
|
||||
private val ErrorRed = Color(0xFFFF0040)
|
||||
private val WarningOrange = Color(0xFFFF8800)
|
||||
private val SuccessGreen = Color(0xFF00FF88)
|
||||
private val ScanlineColor = Color(0x1100FFFF)
|
||||
|
||||
// 字体样式定义
|
||||
object CyberTextStyles {
|
||||
val Terminal = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Normal,
|
||||
fontSize = 12.sp,
|
||||
lineHeight = 18.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
|
||||
val Caption = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Light,
|
||||
fontSize = 10.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.2.sp
|
||||
)
|
||||
|
||||
val DataDisplay = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Bold,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 1.0.sp
|
||||
)
|
||||
|
||||
val Choice = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Medium,
|
||||
fontSize = 13.sp,
|
||||
lineHeight = 20.sp,
|
||||
letterSpacing = 0.3.sp
|
||||
)
|
||||
|
||||
val CompactChoice = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Medium,
|
||||
fontSize = 11.sp, // 较小字体
|
||||
lineHeight = 16.sp, // 较小行高
|
||||
letterSpacing = 0.2.sp
|
||||
)
|
||||
|
||||
val StoryContent = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Normal,
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.25.sp
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 赛博朋克风格的终端窗口组件
|
||||
*/
|
||||
@Composable
|
||||
fun TerminalWindow(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
isActive: Boolean = true,
|
||||
content: @Composable BoxScope.() -> Unit
|
||||
) {
|
||||
val borderColor by animateColorAsState(
|
||||
targetValue = if (isActive) CyberBlue else DarkBorder,
|
||||
animationSpec = tween(300),
|
||||
label = "border_color"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(DarkBackground)
|
||||
.border(1.dp, borderColor)
|
||||
.background(DarkSurface.copy(alpha = 0.9f))
|
||||
) {
|
||||
// 标题栏
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(DarkCard)
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = CyberTextStyles.Terminal,
|
||||
color = if (isActive) CyberBlue else TextSecondary
|
||||
)
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
// 终端控制按钮
|
||||
repeat(3) { index ->
|
||||
val color = when (index) {
|
||||
0 -> ErrorRed
|
||||
1 -> WarningOrange
|
||||
else -> SuccessGreen
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(8.dp)
|
||||
.background(color, RoundedCornerShape(50))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 内容区域
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 36.dp) // 为标题栏留出空间
|
||||
.padding(12.dp)
|
||||
) {
|
||||
content()
|
||||
}
|
||||
|
||||
// 扫描线效果
|
||||
if (isActive) {
|
||||
ScanlineEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描线效果组件
|
||||
*/
|
||||
@Composable
|
||||
private fun BoxScope.ScanlineEffect() {
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "scanline")
|
||||
val scanlinePosition by infiniteTransition.animateFloat(
|
||||
initialValue = 0f,
|
||||
targetValue = 1f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearEasing),
|
||||
repeatMode = RepeatMode.Restart
|
||||
),
|
||||
label = "scanline_position"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.drawBehind {
|
||||
val scanlineY = size.height * scanlinePosition
|
||||
drawLine(
|
||||
color = ScanlineColor,
|
||||
start = Offset(0f, scanlineY),
|
||||
end = Offset(size.width, scanlineY),
|
||||
strokeWidth = 2.dp.toPx()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 霓虹发光按钮
|
||||
*/
|
||||
@Composable
|
||||
fun NeonButton(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
colors: ButtonColors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.Transparent,
|
||||
contentColor = CyberBlue,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
disabledContentColor = TextDisabled
|
||||
),
|
||||
glowColor: Color = CyberBlue,
|
||||
compact: Boolean = false, // 紧凑模式,减少内边距
|
||||
content: @Composable RowScope.() -> Unit
|
||||
) {
|
||||
val animatedGlow by animateFloatAsState(
|
||||
targetValue = if (enabled) 1f else 0.3f,
|
||||
animationSpec = tween(300),
|
||||
label = "glow_animation"
|
||||
)
|
||||
|
||||
Button(
|
||||
onClick = onClick,
|
||||
modifier = modifier
|
||||
.drawBehind {
|
||||
// 外发光效果
|
||||
val glowRadius = 8.dp.toPx()
|
||||
val glowAlpha = 0.6f * animatedGlow
|
||||
|
||||
drawRoundRect(
|
||||
color = glowColor.copy(alpha = glowAlpha),
|
||||
size = size,
|
||||
style = Stroke(width = 2.dp.toPx()),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(4.dp.toPx())
|
||||
)
|
||||
|
||||
// 内边框
|
||||
drawRoundRect(
|
||||
color = glowColor.copy(alpha = 0.8f * animatedGlow),
|
||||
size = size,
|
||||
style = Stroke(width = 1.dp.toPx()),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(4.dp.toPx())
|
||||
)
|
||||
},
|
||||
enabled = enabled,
|
||||
colors = colors,
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
border = BorderStroke(1.dp, glowColor.copy(alpha = animatedGlow)),
|
||||
contentPadding = if (compact) {
|
||||
PaddingValues(horizontal = 8.dp, vertical = 4.dp) // 紧凑模式的内边距
|
||||
} else {
|
||||
ButtonDefaults.ContentPadding // 默认内边距
|
||||
},
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据显示面板
|
||||
*/
|
||||
@Composable
|
||||
fun DataPanel(
|
||||
label: String,
|
||||
value: String,
|
||||
modifier: Modifier = Modifier,
|
||||
valueColor: Color = CyberBlue,
|
||||
icon: @Composable (() -> Unit)? = null,
|
||||
trend: DataTrend? = null
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier,
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = DarkCard,
|
||||
contentColor = TextPrimary
|
||||
),
|
||||
border = BorderStroke(1.dp, DarkBorder)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = label,
|
||||
style = CyberTextStyles.Caption,
|
||||
color = TextSecondary
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = value,
|
||||
style = CyberTextStyles.DataDisplay,
|
||||
color = valueColor
|
||||
)
|
||||
trend?.let { TrendIndicator(it) }
|
||||
}
|
||||
}
|
||||
icon?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据趋势枚举
|
||||
*/
|
||||
enum class DataTrend {
|
||||
UP, DOWN, STABLE
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势指示器
|
||||
*/
|
||||
@Composable
|
||||
private fun TrendIndicator(trend: DataTrend) {
|
||||
val (color, symbol) = when (trend) {
|
||||
DataTrend.UP -> SuccessGreen to "↑"
|
||||
DataTrend.DOWN -> ErrorRed to "↓"
|
||||
DataTrend.STABLE -> TextSecondary to "→"
|
||||
}
|
||||
|
||||
Text(
|
||||
text = symbol,
|
||||
style = CyberTextStyles.Caption,
|
||||
color = color
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 进度条组件
|
||||
*/
|
||||
@Composable
|
||||
fun CyberProgressBar(
|
||||
progress: Float,
|
||||
modifier: Modifier = Modifier,
|
||||
progressColor: Color = CyberGreen,
|
||||
backgroundColor: Color = DarkBorder,
|
||||
showPercentage: Boolean = true,
|
||||
animated: Boolean = true
|
||||
) {
|
||||
val animatedProgress by animateFloatAsState(
|
||||
targetValue = if (animated) progress else progress,
|
||||
animationSpec = tween(500),
|
||||
label = "progress_animation"
|
||||
)
|
||||
|
||||
Column(modifier = modifier) {
|
||||
if (showPercentage) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = "${(progress * 100).toInt()}%",
|
||||
style = CyberTextStyles.Caption,
|
||||
color = progressColor
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(8.dp)
|
||||
.background(backgroundColor, RoundedCornerShape(4.dp))
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.fillMaxWidth(animatedProgress.coerceIn(0f, 1f))
|
||||
.background(
|
||||
brush = Brush.horizontalGradient(
|
||||
colors = listOf(
|
||||
progressColor.copy(alpha = 0.6f),
|
||||
progressColor,
|
||||
progressColor.copy(alpha = 0.8f)
|
||||
)
|
||||
),
|
||||
shape = RoundedCornerShape(4.dp)
|
||||
)
|
||||
.drawBehind {
|
||||
// 发光效果
|
||||
drawRect(
|
||||
color = progressColor.copy(alpha = 0.3f),
|
||||
size = size
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息卡片
|
||||
*/
|
||||
@Composable
|
||||
fun InfoCard(
|
||||
title: String,
|
||||
content: String,
|
||||
modifier: Modifier = Modifier,
|
||||
icon: @Composable (() -> Unit)? = null,
|
||||
accentColor: Color = CyberBlue,
|
||||
onClick: (() -> Unit)? = null
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Card(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (onClick != null) {
|
||||
Modifier.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null
|
||||
) { onClick() }
|
||||
} else Modifier
|
||||
),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = DarkCard,
|
||||
contentColor = TextPrimary
|
||||
),
|
||||
border = BorderStroke(1.dp, accentColor.copy(alpha = 0.5f))
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
verticalAlignment = Alignment.Top,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
icon?.invoke()
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = CyberTextStyles.Choice,
|
||||
color = accentColor
|
||||
)
|
||||
Text(
|
||||
text = content,
|
||||
style = CyberTextStyles.StoryContent,
|
||||
color = TextPrimary,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态指示器
|
||||
*/
|
||||
@Composable
|
||||
fun StatusIndicator(
|
||||
label: String,
|
||||
status: StatusType,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val (color, icon) = when (status) {
|
||||
StatusType.ONLINE -> SuccessGreen to "●"
|
||||
StatusType.OFFLINE -> ErrorRed to "●"
|
||||
StatusType.WARNING -> WarningOrange to "●"
|
||||
StatusType.PROCESSING -> CyberBlue to "●"
|
||||
}
|
||||
|
||||
val animatedAlpha by animateFloatAsState(
|
||||
targetValue = if (status == StatusType.PROCESSING) 0.5f else 1f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(1000),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
),
|
||||
label = "status_blink"
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = icon,
|
||||
style = CyberTextStyles.Terminal,
|
||||
color = color.copy(alpha = if (status == StatusType.PROCESSING) animatedAlpha else 1f)
|
||||
)
|
||||
Text(
|
||||
text = label,
|
||||
style = CyberTextStyles.Caption,
|
||||
color = TextSecondary
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态类型枚举
|
||||
*/
|
||||
enum class StatusType {
|
||||
ONLINE, OFFLINE, WARNING, PROCESSING
|
||||
}
|
||||
|
||||
/**
|
||||
* 分隔线组件
|
||||
*/
|
||||
@Composable
|
||||
fun CyberDivider(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = DarkBorder,
|
||||
thickness: Float = 1f,
|
||||
animated: Boolean = false
|
||||
) {
|
||||
if (animated) {
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "divider_animation")
|
||||
val animatedAlpha by infiniteTransition.animateFloat(
|
||||
initialValue = 0.3f,
|
||||
targetValue = 1f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
),
|
||||
label = "divider_alpha"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(thickness.dp)
|
||||
.background(color.copy(alpha = animatedAlpha))
|
||||
)
|
||||
} else {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(thickness.dp)
|
||||
.background(color)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 精简状态栏组件
|
||||
* 显示最重要的游戏状态信息
|
||||
*/
|
||||
@Composable
|
||||
fun CompactStatusBar(
|
||||
gameState: GameState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Surface(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
color = Color(0xFF0A0A0A),
|
||||
shadowElevation = 4.dp
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 6.dp), // 精简的内边距
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 左侧:核心数值
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 健康
|
||||
Text(
|
||||
text = "♥ ${gameState.health}",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 11.sp),
|
||||
color = if (gameState.health > 60) Color(0xFF00FF88) else Color(0xFFFF4444)
|
||||
)
|
||||
// 精力
|
||||
Text(
|
||||
text = "⚡ ${gameState.stamina}",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 11.sp),
|
||||
color = if (gameState.stamina > 60) Color(0xFF88AAFF) else Color(0xFFFFAA00)
|
||||
)
|
||||
// 状态
|
||||
Text(
|
||||
text = "📊 ${gameState.characterStatus.displayName}",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 11.sp),
|
||||
color = when (gameState.characterStatus) {
|
||||
CharacterStatus.EXCELLENT -> Color(0xFF00FFAA)
|
||||
CharacterStatus.GOOD -> Color(0xFF00FF88)
|
||||
CharacterStatus.TIRED -> Color(0xFFFFAA00)
|
||||
CharacterStatus.WEAK -> Color(0xFFFF4444)
|
||||
CharacterStatus.CRITICAL -> Color(0xFFFF0000)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 中间:循环信息
|
||||
Text(
|
||||
text = "第${gameState.currentLoop}轮 • 第${gameState.currentDay}天",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 10.sp),
|
||||
color = Color(0xFF88FF88)
|
||||
)
|
||||
|
||||
// 右侧:发现状态
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "🔍 ${gameState.exploredLocations.size}/10",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 10.sp),
|
||||
color = Color(0xFF88AAFF)
|
||||
)
|
||||
Text(
|
||||
text = "🔐 ${gameState.unlockedSecrets.size}/8",
|
||||
style = CyberTextStyles.Caption.copy(fontSize = 10.sp),
|
||||
color = Color(0xFFAA88FF)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 专用的故事内容窗口组件
|
||||
* 解决BoxScope和ColumnScope作用域冲突问题
|
||||
* 专门为故事内容和选择按钮设计
|
||||
*/
|
||||
@Composable
|
||||
fun StoryContentWindow(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
isActive: Boolean = true,
|
||||
content: @Composable ColumnScope.() -> Unit
|
||||
) {
|
||||
val borderColor by animateColorAsState(
|
||||
targetValue = if (isActive) CyberBlue else DarkBorder,
|
||||
animationSpec = tween(300),
|
||||
label = "border_color"
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(DarkBackground)
|
||||
.border(1.dp, borderColor)
|
||||
.background(DarkSurface.copy(alpha = 0.9f))
|
||||
) {
|
||||
// 标题栏
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(DarkCard)
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = CyberTextStyles.Terminal,
|
||||
color = if (isActive) CyberBlue else TextSecondary
|
||||
)
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
// 终端控制按钮
|
||||
repeat(3) { index ->
|
||||
val color = when (index) {
|
||||
0 -> ErrorRed
|
||||
1 -> WarningOrange
|
||||
else -> SuccessGreen
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(8.dp)
|
||||
.background(color, RoundedCornerShape(50))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 内容区域 - 直接使用Column作用域
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f) // 自动填充剩余空间
|
||||
.padding(12.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
content()
|
||||
}
|
||||
|
||||
// 扫描线效果覆盖层
|
||||
if (isActive) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(2.dp)
|
||||
.background(
|
||||
Brush.horizontalGradient(
|
||||
colors = listOf(
|
||||
Color.Transparent,
|
||||
ScanlineColor,
|
||||
Color.Transparent
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.example.gameofmoon.presentation.ui.components
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
|
||||
@Composable
|
||||
fun GameControlMenu(
|
||||
isVisible: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onSaveGame: () -> Unit,
|
||||
onLoadGame: () -> Unit,
|
||||
onNewLoop: () -> Unit,
|
||||
onAiAssist: () -> Unit,
|
||||
onShowHistory: () -> Unit,
|
||||
onSettings: () -> Unit
|
||||
) {
|
||||
if (isVisible) {
|
||||
Dialog(onDismissRequest = onDismiss) {
|
||||
TerminalWindow(
|
||||
title = "🎮 游戏控制中心",
|
||||
modifier = Modifier.width(320.dp)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
// 保存/读取组
|
||||
Text(
|
||||
text = "数据管理",
|
||||
style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
|
||||
color = Color(0xFF00DDFF),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onSaveGame()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("💾", fontSize = 20.sp)
|
||||
Text("保存", fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onLoadGame()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("📁", fontSize = 20.sp)
|
||||
Text("读取", fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CyberDivider()
|
||||
|
||||
// 游戏控制组
|
||||
Text(
|
||||
text = "游戏控制",
|
||||
style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
|
||||
color = Color(0xFF00DDFF),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onNewLoop()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text("🔄", fontSize = 18.sp)
|
||||
Column {
|
||||
Text("开始新循环", fontSize = 12.sp, fontWeight = FontWeight.Bold)
|
||||
Text("重置进度,保留记忆", fontSize = 10.sp, color = Color(0xFFAAAA88))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onShowHistory()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text("📖", fontSize = 18.sp)
|
||||
Column {
|
||||
Text("对话历史", fontSize = 12.sp, fontWeight = FontWeight.Bold)
|
||||
Text("查看完整对话记录", fontSize = 10.sp, color = Color(0xFFAAAA88))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CyberDivider()
|
||||
|
||||
// AI助手组
|
||||
Text(
|
||||
text = "AI助手",
|
||||
style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
|
||||
color = Color(0xFF00DDFF),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onAiAssist()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text("🤖", fontSize = 18.sp)
|
||||
Column {
|
||||
Text("请求AI协助", fontSize = 12.sp, fontWeight = FontWeight.Bold)
|
||||
Text("生成新的故事内容", fontSize = 10.sp, color = Color(0xFFAAAA88))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CyberDivider()
|
||||
|
||||
// 设置组
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
NeonButton(
|
||||
onClick = {
|
||||
onSettings()
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("⚙️", fontSize = 20.sp)
|
||||
Text("设置", fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
|
||||
NeonButton(
|
||||
onClick = onDismiss,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("❌", fontSize = 20.sp)
|
||||
Text("关闭", fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package com.example.gameofmoon.presentation.ui.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
/**
|
||||
* 打字机效果文本组件
|
||||
* 让文字逐个字符地显示,营造科幻氛围
|
||||
*/
|
||||
@Composable
|
||||
fun TypewriterText(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
style: TextStyle = LocalTextStyle.current,
|
||||
color: Color = Color.Unspecified,
|
||||
textAlign: TextAlign? = null,
|
||||
typingSpeed: Long = 30L, // 每个字符的显示间隔(毫秒)
|
||||
onTypingComplete: () -> Unit = {},
|
||||
canSkip: Boolean = true, // 是否允许点击跳过动画
|
||||
autoStart: Boolean = true, // 是否自动开始动画
|
||||
lineBreakPause: Long = 100L, // 换行时的额外暂停时间
|
||||
sentencePause: Long = 200L, // 句号后的额外暂停时间
|
||||
) {
|
||||
var displayedText by remember(text) { mutableStateOf("") }
|
||||
var isTypingComplete by remember(text) { mutableStateOf(false) }
|
||||
var currentIndex by remember(text) { mutableStateOf(0) }
|
||||
var isTypingActive by remember(text) { mutableStateOf(autoStart) }
|
||||
|
||||
// 重置状态当文本改变时
|
||||
LaunchedEffect(text) {
|
||||
displayedText = ""
|
||||
isTypingComplete = false
|
||||
currentIndex = 0
|
||||
isTypingActive = autoStart
|
||||
}
|
||||
|
||||
// 打字机动画逻辑
|
||||
LaunchedEffect(text, isTypingActive) {
|
||||
if (!isTypingActive || isTypingComplete) return@LaunchedEffect
|
||||
|
||||
while (currentIndex < text.length && isTypingActive) {
|
||||
delay(typingSpeed)
|
||||
|
||||
currentIndex++
|
||||
displayedText = text.substring(0, currentIndex)
|
||||
|
||||
// 检查是否需要额外暂停
|
||||
if (currentIndex < text.length) {
|
||||
val currentChar = text[currentIndex - 1]
|
||||
when {
|
||||
currentChar == '\n' -> delay(lineBreakPause)
|
||||
currentChar in "。!?.!?" -> delay(sentencePause)
|
||||
currentChar in ",、;,;" -> delay(typingSpeed / 2) // 逗号短暂停
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentIndex >= text.length) {
|
||||
isTypingComplete = true
|
||||
onTypingComplete()
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.let { mod ->
|
||||
if (canSkip && !isTypingComplete) {
|
||||
mod.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
// 点击跳过动画,直接显示完整文本
|
||||
displayedText = text
|
||||
currentIndex = text.length
|
||||
isTypingComplete = true
|
||||
isTypingActive = false
|
||||
onTypingComplete()
|
||||
}
|
||||
} else {
|
||||
mod
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = displayedText,
|
||||
style = style,
|
||||
color = color,
|
||||
textAlign = textAlign,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
|
||||
// 光标闪烁效果(仅在打字过程中显示)
|
||||
if (!isTypingComplete && isTypingActive) {
|
||||
TypewriterCursor(
|
||||
modifier = Modifier.align(Alignment.BottomEnd)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打字机光标组件
|
||||
* 显示闪烁的光标
|
||||
*/
|
||||
@Composable
|
||||
private fun TypewriterCursor(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = Color(0xFF00FFFF),
|
||||
blinkSpeed: Long = 800L
|
||||
) {
|
||||
var isVisible by remember { mutableStateOf(true) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
delay(blinkSpeed)
|
||||
isVisible = !isVisible
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
text = if (isVisible) "▋" else " ",
|
||||
color = color,
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 带控制按钮的打字机文本组件
|
||||
* 提供播放/暂停、跳过等控制功能
|
||||
*/
|
||||
@Composable
|
||||
fun TypewriterTextWithControls(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
style: TextStyle = LocalTextStyle.current,
|
||||
color: Color = Color.Unspecified,
|
||||
textAlign: TextAlign? = null,
|
||||
typingSpeed: Long = 30L,
|
||||
onTypingComplete: () -> Unit = {},
|
||||
showControls: Boolean = true
|
||||
) {
|
||||
var isPlaying by remember(text) { mutableStateOf(true) }
|
||||
var isCompleted by remember(text) { mutableStateOf(false) }
|
||||
|
||||
Column(modifier = modifier) {
|
||||
TypewriterText(
|
||||
text = text,
|
||||
style = style,
|
||||
color = color,
|
||||
textAlign = textAlign,
|
||||
typingSpeed = typingSpeed,
|
||||
onTypingComplete = {
|
||||
isCompleted = true
|
||||
onTypingComplete()
|
||||
},
|
||||
canSkip = true,
|
||||
autoStart = isPlaying,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
|
||||
if (showControls && !isCompleted) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 8.dp),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 播放/暂停按钮
|
||||
IconButton(
|
||||
onClick = { isPlaying = !isPlaying },
|
||||
modifier = Modifier.size(24.dp)
|
||||
) {
|
||||
Text(
|
||||
text = if (isPlaying) "⏸️" else "▶️",
|
||||
style = CyberTextStyles.Caption,
|
||||
color = Color(0xFF00AAFF)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
// 跳过按钮
|
||||
TextButton(
|
||||
onClick = {
|
||||
isCompleted = true
|
||||
onTypingComplete()
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "跳过",
|
||||
style = CyberTextStyles.Caption,
|
||||
color = Color(0xFF666666)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 故事专用的打字机文本组件
|
||||
* 为游戏故事内容优化的版本
|
||||
*/
|
||||
@Composable
|
||||
fun StoryTypewriterText(
|
||||
content: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onContentComplete: () -> Unit = {}
|
||||
) {
|
||||
TypewriterText(
|
||||
text = content,
|
||||
modifier = modifier,
|
||||
style = CyberTextStyles.Terminal.copy(fontSize = 14.sp),
|
||||
color = Color(0xFF88FF88),
|
||||
typingSpeed = 25L, // 稍快的速度,适合游戏
|
||||
onTypingComplete = onContentComplete,
|
||||
canSkip = true,
|
||||
lineBreakPause = 150L,
|
||||
sentencePause = 300L
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 预设的打字机速度
|
||||
*/
|
||||
object TypewriterSpeed {
|
||||
const val VERY_SLOW = 100L
|
||||
const val SLOW = 60L
|
||||
const val NORMAL = 40L
|
||||
const val FAST = 25L
|
||||
const val VERY_FAST = 15L
|
||||
const val INSTANT = 5L
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.example.gameofmoon.presentation.ui.screens
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import com.example.gameofmoon.data.GameSaveManager
|
||||
import com.example.gameofmoon.data.SimpleGeminiService
|
||||
import com.example.gameofmoon.data.GameContext
|
||||
import com.example.gameofmoon.model.*
|
||||
import com.example.gameofmoon.story.CompleteStoryData
|
||||
import com.example.gameofmoon.story.engine.StoryEngineAdapter
|
||||
import com.example.gameofmoon.presentation.ui.components.*
|
||||
import com.example.gameofmoon.audio.*
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
|
||||
@Composable
|
||||
fun TimeCageGameScreen() {
|
||||
val context = LocalContext.current
|
||||
val saveManager = remember { GameSaveManager(context) }
|
||||
val geminiService = remember { SimpleGeminiService() }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
|
||||
// 创建音频系统
|
||||
val audioManager = remember { GameAudioManager(context, coroutineScope) }
|
||||
val audioController = remember { GameAudioController(audioManager) }
|
||||
val storyAudioHandler = remember { StoryAudioHandler(audioController) }
|
||||
|
||||
// 创建新的故事引擎适配器
|
||||
val storyEngineAdapter = remember {
|
||||
StoryEngineAdapter(context, coroutineScope).apply {
|
||||
// 设置音频回调
|
||||
audioCallback = { audioFileName ->
|
||||
coroutineScope.launch {
|
||||
storyAudioHandler.handleAudioCallback(audioFileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var gameState by remember { mutableStateOf(GameState()) }
|
||||
|
||||
// 使用新引擎的观察者模式
|
||||
val currentNodeFromEngine by storyEngineAdapter.currentNode.collectAsState()
|
||||
var currentNode by remember {
|
||||
mutableStateOf(
|
||||
currentNodeFromEngine ?: SimpleStoryNode(
|
||||
id = "fallback",
|
||||
title = "初始化",
|
||||
content = "正在加载故事内容...",
|
||||
choices = emptyList()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// 当引擎状态变化时,更新本地状态
|
||||
LaunchedEffect(currentNodeFromEngine) {
|
||||
currentNodeFromEngine?.let { currentNode = it }
|
||||
}
|
||||
|
||||
// 初始化音频系统和故事引擎
|
||||
LaunchedEffect(Unit) {
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
// 1. 首先初始化音频系统
|
||||
audioManager.initialize()
|
||||
|
||||
// 2. 播放开场音乐
|
||||
AudioScenes.playSceneAudio("awakening", audioController)
|
||||
|
||||
// 3. 初始化故事引擎
|
||||
if (storyEngineAdapter.initialize()) {
|
||||
storyEngineAdapter.navigateToNode("first_awakening")
|
||||
} else {
|
||||
throw Exception("Engine initialization failed")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 如果新引擎失败,fallback到旧系统
|
||||
currentNode = CompleteStoryData.getStoryNode("first_awakening") ?: SimpleStoryNode(
|
||||
id = "fallback",
|
||||
title = "引擎初始化失败",
|
||||
content = "正在使用备用故事系统...",
|
||||
choices = emptyList()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
var dialogueHistory by remember { mutableStateOf(listOf<DialogueEntry>()) }
|
||||
var isLoading by remember { mutableStateOf(false) }
|
||||
var gameMessage by remember { mutableStateOf("欢迎来到时间囚笼!第${gameState.currentLoop}次循环开始。") }
|
||||
var showControlMenu by remember { mutableStateOf(false) }
|
||||
var showDialogueHistory by remember { mutableStateOf(false) }
|
||||
|
||||
// 检查游戏结束条件
|
||||
LaunchedEffect(gameState.health) {
|
||||
if (gameState.health <= 0) {
|
||||
try {
|
||||
storyEngineAdapter.navigateToNode("game_over_failure")
|
||||
gameMessage = "健康值耗尽...循环重置"
|
||||
} catch (e: Exception) {
|
||||
// Fallback到旧系统
|
||||
currentNode = CompleteStoryData.getStoryNode("game_over_failure") ?: currentNode
|
||||
gameMessage = "健康值耗尽...循环重置"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
// 顶部固定区域:标题和快捷按钮
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp), // 减少垂直间距
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 左侧:游戏标题
|
||||
Text(
|
||||
text = "🌙 时间囚笼",
|
||||
fontSize = 18.sp, // 稍微减小字体
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color(0xFF00DDFF)
|
||||
)
|
||||
|
||||
// 右侧:快捷按钮
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
// 设置按钮
|
||||
IconButton(
|
||||
onClick = {
|
||||
audioController.playSoundEffect("button_click")
|
||||
showControlMenu = true
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(36.dp) // 稍微减小按钮
|
||||
.background(
|
||||
Color(0xFF003366),
|
||||
shape = CircleShape
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = "⚙️",
|
||||
fontSize = 16.sp,
|
||||
color = Color(0xFF00DDFF)
|
||||
)
|
||||
}
|
||||
|
||||
// AI协助按钮
|
||||
IconButton(
|
||||
onClick = {
|
||||
audioController.playSoundEffect("notification")
|
||||
/* AI 功能 */
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(36.dp) // 稍微减小按钮
|
||||
.background(
|
||||
Color(0xFF003366),
|
||||
shape = CircleShape
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = "🤖",
|
||||
fontSize = 16.sp,
|
||||
color = Color(0xFF00DDFF)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 精简状态栏 - 固定在顶部
|
||||
CompactStatusBar(gameState = gameState)
|
||||
|
||||
// 主要内容区域 - 故事内容窗口
|
||||
StoryContentWindow(
|
||||
title = "📖 ${currentNode.title}",
|
||||
modifier = Modifier
|
||||
.weight(1f) // 占用剩余空间
|
||||
.padding(horizontal = 12.dp)
|
||||
.padding(bottom = 12.dp)
|
||||
) {
|
||||
// 故事文本 - 使用打字机效果
|
||||
StoryTypewriterText(
|
||||
content = currentNode.content,
|
||||
modifier = Modifier.padding(bottom = 16.dp),
|
||||
onContentComplete = {
|
||||
// 文字播放完成时播放音效
|
||||
audioController.playSoundEffect("notification")
|
||||
}
|
||||
)
|
||||
|
||||
// 调试信息(可选)
|
||||
if (true) { // 可以改为配置项
|
||||
Text(
|
||||
text = "DEBUG: 节点=${currentNode.id} | 内容长度=${currentNode.content.length} | 选择=${currentNode.choices.size}",
|
||||
style = CyberTextStyles.Caption,
|
||||
color = Color(0xFF444444),
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
fontSize = 9.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 底部固定操作区 - 选择按钮
|
||||
if (currentNode.choices.isNotEmpty()) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
color = Color(0xFF0A0A0A),
|
||||
shadowElevation = 8.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp), // 减少垂直内边距
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp) // 减少组件间距
|
||||
) {
|
||||
CyberDivider()
|
||||
|
||||
Text(
|
||||
text = "选择你的行动:",
|
||||
style = CyberTextStyles.Caption,
|
||||
color = Color(0xFFAAAA88),
|
||||
modifier = Modifier.padding(bottom = 2.dp) // 减少底部间距
|
||||
)
|
||||
|
||||
currentNode.choices.forEachIndexed { index, choice ->
|
||||
NeonButton(
|
||||
onClick = {
|
||||
// 播放按钮点击音效
|
||||
audioController.playSoundEffect("button_click")
|
||||
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
// 使用新引擎处理选择
|
||||
if (storyEngineAdapter.executeChoice(choice.id)) {
|
||||
gameMessage = "你选择了:${choice.text}"
|
||||
} else {
|
||||
throw Exception("Choice execution failed")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Fallback到旧系统
|
||||
val nextNode = CompleteStoryData.getStoryNode(choice.nextNodeId)
|
||||
if (nextNode != null) {
|
||||
currentNode = nextNode
|
||||
gameMessage = "你选择了:${choice.text} (备用系统)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 1.dp), // 减少垂直间距
|
||||
compact = true // 使用紧凑模式
|
||||
) {
|
||||
Text(
|
||||
text = "${index + 1}. ${choice.text}",
|
||||
style = CyberTextStyles.CompactChoice // 使用较小的文字样式
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏控制菜单弹窗
|
||||
GameControlMenu(
|
||||
isVisible = showControlMenu,
|
||||
onDismiss = { showControlMenu = false },
|
||||
onSaveGame = { /* 暂时简化 */ },
|
||||
onLoadGame = { /* 暂时简化 */ },
|
||||
onNewLoop = {
|
||||
// 重新开始游戏
|
||||
gameState = GameState(currentLoop = gameState.currentLoop + 1)
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
if (storyEngineAdapter.startNewGame()) {
|
||||
gameMessage = "第${gameState.currentLoop}次循环开始!"
|
||||
} else {
|
||||
throw Exception("New game start failed")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Fallback到旧系统
|
||||
currentNode = CompleteStoryData.getStoryNode("first_awakening") ?: currentNode
|
||||
gameMessage = "第${gameState.currentLoop}次循环开始!(备用系统)"
|
||||
}
|
||||
}
|
||||
dialogueHistory = emptyList()
|
||||
},
|
||||
onAiAssist = { /* 暂时简化 */ },
|
||||
onShowHistory = { /* 暂时简化 */ },
|
||||
onSettings = { /* 暂时简化 */ }
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 音频生命周期管理
|
||||
// ============================================================================
|
||||
|
||||
// Activity生命周期管理
|
||||
DisposableEffect(lifecycleOwner) {
|
||||
val observer = LifecycleEventObserver { _, event ->
|
||||
when (event) {
|
||||
Lifecycle.Event.ON_PAUSE -> {
|
||||
audioController.pauseMusic()
|
||||
}
|
||||
Lifecycle.Event.ON_RESUME -> {
|
||||
audioController.resumeMusic()
|
||||
}
|
||||
Lifecycle.Event.ON_DESTROY -> {
|
||||
audioManager.release()
|
||||
}
|
||||
else -> { /* 其他事件不处理 */ }
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleOwner.lifecycle.addObserver(observer)
|
||||
|
||||
onDispose {
|
||||
lifecycleOwner.lifecycle.removeObserver(observer)
|
||||
audioManager.release()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助函数移到文件外部
|
||||
fun getGamePhase(day: Int): String {
|
||||
return when {
|
||||
day <= 3 -> "探索期"
|
||||
day <= 7 -> "适应期"
|
||||
day <= 14 -> "危机期"
|
||||
else -> "未知"
|
||||
}
|
||||
}
|
||||
|
||||
fun getMemoryRetention(loop: Int): Int {
|
||||
return (50 + loop * 5).coerceAtMost(100)
|
||||
}
|
||||
|
||||
fun getWeatherColor(weatherType: WeatherType): Color {
|
||||
return when (weatherType) {
|
||||
WeatherType.CLEAR -> Color(0xFF00FF88)
|
||||
WeatherType.LIGHT_RAIN -> Color(0xFF00AAFF)
|
||||
WeatherType.HEAVY_RAIN -> Color(0xFF0088CC)
|
||||
WeatherType.ACID_RAIN -> Color(0xFFFF4444)
|
||||
WeatherType.CYBER_STORM -> Color(0xFFAA00FF)
|
||||
WeatherType.SOLAR_FLARE -> Color(0xFFFF8800)
|
||||
}
|
||||
}
|
||||
3743
app/src/main/java/com/example/gameofmoon/story/CompleteStoryData.kt
Normal file
382
app/src/main/java/com/example/gameofmoon/story/StoryData.kt
Normal file
@@ -0,0 +1,382 @@
|
||||
package com.example.gameofmoon.story
|
||||
|
||||
import com.example.gameofmoon.model.*
|
||||
|
||||
/**
|
||||
* 时间囚笼故事数据
|
||||
* 基于Story目录中的大师级剧情设计
|
||||
* 包含完整的主线和支线故事节点
|
||||
*
|
||||
* @deprecated 此文件已完全废弃,内容已迁移到DSL引擎
|
||||
* 请使用 assets/story/ 目录下的 .story 文件
|
||||
* 保留此文件仅用于参考和向后兼容
|
||||
*
|
||||
* 迁移完成日期: 2024-12-19
|
||||
* 替代系统: DSL Story Engine with StoryEngineAdapter
|
||||
*/
|
||||
object StoryData {
|
||||
|
||||
// 获取故事节点
|
||||
fun getStoryNode(nodeId: String): SimpleStoryNode? {
|
||||
return storyNodes[nodeId]
|
||||
}
|
||||
|
||||
// 获取所有故事节点
|
||||
fun getAllStoryNodes(): Map<String, SimpleStoryNode> {
|
||||
return storyNodes
|
||||
}
|
||||
|
||||
// 获取当前阶段的可用支线
|
||||
fun getAvailableSidelines(currentLoop: Int, unlockedSecrets: Set<String>): List<SimpleStoryNode> {
|
||||
return storyNodes.values.filter { node ->
|
||||
when {
|
||||
currentLoop < 3 -> node.id.startsWith("side_") && node.id.contains("basic")
|
||||
currentLoop < 6 -> node.id.startsWith("side_") && !node.id.contains("advanced")
|
||||
currentLoop < 10 -> !node.id.contains("endgame")
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 故事节点映射
|
||||
private val storyNodes = mapOf(
|
||||
"first_awakening" to SimpleStoryNode(
|
||||
id = "first_awakening",
|
||||
title = "第一次觉醒",
|
||||
content = """
|
||||
你在月球基地的医疗舱中醒来,头部剧痛如同被锤击。
|
||||
|
||||
周围一片混乱,设备的警报声此起彼伏,红色的警示灯在黑暗中闪烁。
|
||||
你的记忆模糊不清,但有一种奇怪的既视感...
|
||||
仿佛这种情况你已经经历过很多次了。
|
||||
|
||||
氧气显示器显示还有6小时的供应量。
|
||||
你必须立即采取行动。
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "check_oxygen",
|
||||
text = "检查氧气系统",
|
||||
nextNodeId = "oxygen_crisis",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-5", "消耗体力")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "search_medical",
|
||||
text = "搜索医疗用品",
|
||||
nextNodeId = "medical_supplies",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "10", "发现止痛药")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "contact_earth",
|
||||
text = "尝试联系地球",
|
||||
nextNodeId = "communication_failure",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-3", "轻微疲劳")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"oxygen_crisis" to SimpleStoryNode(
|
||||
id = "oxygen_crisis",
|
||||
title = "氧气危机",
|
||||
content = """
|
||||
你检查了氧气系统,发现情况比预想的更糟糕。
|
||||
|
||||
主要氧气管线有三处泄漏,备用氧气罐只剩下20%。
|
||||
按照目前的消耗速度,你最多还有4小时的生存时间。
|
||||
|
||||
突然,你想起了什么...这些损坏的位置,
|
||||
你之前似乎见过。一种不祥的预感涌上心头。
|
||||
|
||||
"又是这些地方..."你喃喃自语。
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "repair_system",
|
||||
text = "尝试修复氧气系统",
|
||||
nextNodeId = "repair_attempt",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-10", "重体力劳动")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "explore_base",
|
||||
text = "探索基地寻找备用氧气",
|
||||
nextNodeId = "base_exploration",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-8", "长距离移动"),
|
||||
SimpleEffect(SimpleEffectType.LOCATION_DISCOVER, "storage_bay", "发现储藏室")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "memory_fragment",
|
||||
text = "仔细回忆这种既视感",
|
||||
nextNodeId = "memory_recall",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "-5", "精神压力"),
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "time_loop_hint", "时间循环线索")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"medical_supplies" to SimpleStoryNode(
|
||||
id = "medical_supplies",
|
||||
title = "医疗补给",
|
||||
content = """
|
||||
你在医疗柜中找到了一些止痛药和绷带。
|
||||
|
||||
服用止痛药后,头痛稍有缓解,思维也清晰了一些。
|
||||
但是,当你看到医疗记录时,发现了令人不安的事实...
|
||||
|
||||
这里有你的医疗记录,但日期显示是"第27次循环"。
|
||||
什么是"循环"?你从来没有听说过这个概念。
|
||||
|
||||
在记录的末尾,你看到一行手写的字迹:
|
||||
"必须记住EVA的位置...时间锚在那里。"
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "read_records",
|
||||
text = "仔细阅读所有医疗记录",
|
||||
nextNodeId = "medical_records_detail",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "eva_location", "EVA位置线索")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "ignore_records",
|
||||
text = "忽略记录,专注当前状况",
|
||||
nextNodeId = "oxygen_crisis",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "5", "避免精神负担")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "search_eva",
|
||||
text = "立即寻找EVA",
|
||||
nextNodeId = "eva_search",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-7", "紧急搜索")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"communication_failure" to SimpleStoryNode(
|
||||
id = "communication_failure",
|
||||
title = "通讯中断",
|
||||
content = """
|
||||
你尝试联系地球,但通讯系统完全没有反应。
|
||||
|
||||
不仅如此,你发现通讯日志中最后一条记录是28小时前,
|
||||
内容是:"第27次循环开始,时间锚定失效,正在尝试修复..."
|
||||
|
||||
这条记录的发送者署名是...你自己的名字。
|
||||
但你完全不记得发送过这条信息。
|
||||
|
||||
更令人震惊的是,在这条记录之前,还有26条类似的记录,
|
||||
每一条都标注着不同的循环次数。
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "check_logs",
|
||||
text = "查看所有通讯日志",
|
||||
nextNodeId = "time_loop_discovery",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "time_loop_truth", "时间循环真相")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "repair_comm",
|
||||
text = "尝试修复通讯设备",
|
||||
nextNodeId = "repair_attempt",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-7", "技术工作")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "panic_reaction",
|
||||
text = "这不可能...我在做梦",
|
||||
nextNodeId = "denial_phase",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "-10", "精神冲击")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"time_loop_discovery" to SimpleStoryNode(
|
||||
id = "time_loop_discovery",
|
||||
title = "时间循环的真相",
|
||||
content = """
|
||||
通讯日志揭示了令人震惊的真相...
|
||||
|
||||
你已经经历了27次相同的28小时循环。
|
||||
每次你都会在医疗舱中醒来,每次都会面临氧气危机,
|
||||
每次最终都会因为各种原因死亡,然后重新开始。
|
||||
|
||||
但这一次,似乎有什么不同了。
|
||||
你保留了一些记忆片段,能够意识到循环的存在。
|
||||
|
||||
在日志的最后,你看到了一条AI系统的留言:
|
||||
"主人,第28次循环已开始。时间锚定器需要手动重置。
|
||||
EVA在月球表面的坐标:月海-7, 地标-Alpha。
|
||||
警告:灾难将在28小时后发生。"
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "find_eva",
|
||||
text = "立即寻找EVA区域",
|
||||
nextNodeId = "eva_preparation",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.LOCATION_DISCOVER, "eva_bay", "发现EVA舱"),
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "disaster_warning", "灾难警告")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "find_ai",
|
||||
text = "寻找AI系统获得更多信息",
|
||||
nextNodeId = "ai_encounter",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "ai_assistant", "AI助手")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "prepare_survival",
|
||||
text = "准备生存用品",
|
||||
nextNodeId = "survival_preparation",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "15", "医疗用品"),
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "10", "营养补充")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"eva_preparation" to SimpleStoryNode(
|
||||
id = "eva_preparation",
|
||||
title = "EVA准备",
|
||||
content = """
|
||||
你找到了EVA(舱外活动)装备区域。
|
||||
|
||||
这里的装备看起来已经准备就绪,仿佛之前的"你"已经做过准备。
|
||||
在EVA头盔内侧,你发现了一张纸条:
|
||||
|
||||
"如果你看到这个,说明你已经开始记住了。
|
||||
时间锚在月球表面的古老遗迹中。
|
||||
但要小心,那里有东西在守护着它。
|
||||
记住:不要相信第一印象,真相藏在第三层。"
|
||||
|
||||
你的手在颤抖...这是你自己的笔迹。
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "eva_mission",
|
||||
text = "穿上EVA装备,前往月球表面",
|
||||
nextNodeId = "lunar_surface",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "-15", "EVA任务"),
|
||||
SimpleEffect(SimpleEffectType.LOCATION_DISCOVER, "lunar_ruins", "月球遗迹")
|
||||
),
|
||||
requirements = listOf(
|
||||
SimpleRequirement(SimpleRequirementType.MIN_STAMINA, "20", "需要足够体力")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "study_equipment",
|
||||
text = "仔细研究EVA装备和资料",
|
||||
nextNodeId = "equipment_analysis",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "eva_knowledge", "EVA技术知识")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "rest_prepare",
|
||||
text = "先休息恢复体力",
|
||||
nextNodeId = "rest_period",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "20", "充分休息"),
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "10", "体力恢复")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
"ai_encounter" to SimpleStoryNode(
|
||||
id = "ai_encounter",
|
||||
title = "AI助手",
|
||||
content = """
|
||||
你找到了基地的AI核心系统。
|
||||
|
||||
"欢迎回来,艾丽卡博士。这是您的第28次尝试。"
|
||||
一个温和的女性声音响起。
|
||||
|
||||
"我是ARIA,您的个人AI助手。很遗憾,前27次循环都以失败告终。
|
||||
但这次有所不同...您保留了部分记忆。这是突破的希望。"
|
||||
|
||||
"时间锚位于月球古遗迹深处。那里的实体会测试您的决心。
|
||||
您必须做出三个关键选择,每个选择都会影响最终结果。
|
||||
|
||||
记住:牺牲、信任、真相。这三个词是关键。"
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "ask_disaster",
|
||||
text = "询问即将发生的灾难",
|
||||
nextNodeId = "disaster_explanation",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "disaster_truth", "灾难真相")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "ask_previous_loops",
|
||||
text = "了解前27次循环的经历",
|
||||
nextNodeId = "loop_history",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "loop_memories", "循环记忆")
|
||||
)
|
||||
),
|
||||
SimpleChoice(
|
||||
id = "request_ai_help",
|
||||
text = "请求AI协助生成策略",
|
||||
nextNodeId = "ai_strategy",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.SECRET_UNLOCK, "ai_strategy", "AI策略支持")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// 添加更多节点...
|
||||
"game_over_failure" to SimpleStoryNode(
|
||||
id = "game_over_failure",
|
||||
title = "循环重置",
|
||||
content = """
|
||||
一切都消失在白光中...
|
||||
|
||||
当你再次睁开眼睛时,你又回到了医疗舱。
|
||||
但这次,你记得更多了。
|
||||
|
||||
第29次循环开始。
|
||||
""".trimIndent(),
|
||||
choices = listOf(
|
||||
SimpleChoice(
|
||||
id = "restart_with_memory",
|
||||
text = "带着记忆重新开始",
|
||||
nextNodeId = "first_awakening",
|
||||
effects = listOf(
|
||||
SimpleEffect(SimpleEffectType.LOOP_CHANGE, "1", "新循环开始"),
|
||||
SimpleEffect(SimpleEffectType.HEALTH_CHANGE, "100", "完全恢复"),
|
||||
SimpleEffect(SimpleEffectType.STAMINA_CHANGE, "50", "体力恢复")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* 条件评估器 - 解析和评估复杂条件表达式
|
||||
* 支持逻辑操作符、比较操作符、变量引用等
|
||||
*/
|
||||
object ConditionEvaluator {
|
||||
|
||||
// 条件表达式的正则模式
|
||||
private val CONDITION_PATTERN = Pattern.compile(
|
||||
"""(\w+)\s*([><=!]+)\s*([^\s\&\|]+)|(\w+)|(\w+\s+==\s+true)|(\w+\s+==\s+false)"""
|
||||
)
|
||||
|
||||
private val LOGICAL_SPLIT_PATTERN = Pattern.compile("""(\s+AND\s+|\s+OR\s+|\s+NOT\s+)""", Pattern.CASE_INSENSITIVE)
|
||||
|
||||
/**
|
||||
* 评估条件表达式
|
||||
* 支持的格式:
|
||||
* - 简单变量: "eva_reveal_ready"
|
||||
* - 比较表达式: "secrets_found >= 3"
|
||||
* - 逻辑表达式: "secrets_found >= 3 AND trust_level >= 5"
|
||||
* - 布尔表达式: "all_crew_saved == true"
|
||||
*/
|
||||
fun evaluate(condition: String, gameState: GameState): Boolean {
|
||||
if (condition.isBlank() || condition == "true") return true
|
||||
if (condition == "false") return false
|
||||
|
||||
try {
|
||||
return evaluateLogicalExpression(condition.trim(), gameState)
|
||||
} catch (e: Exception) {
|
||||
// 条件评估失败时返回 false,并记录日志
|
||||
println("Warning: Failed to evaluate condition '$condition': ${e.message}")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估逻辑表达式 (支持 AND, OR, NOT)
|
||||
*/
|
||||
private fun evaluateLogicalExpression(expression: String, gameState: GameState): Boolean {
|
||||
// 处理 NOT 操作符
|
||||
if (expression.uppercase().startsWith("NOT ")) {
|
||||
val innerExpression = expression.substring(4).trim()
|
||||
return !evaluateLogicalExpression(innerExpression, gameState)
|
||||
}
|
||||
|
||||
// 分割 AND 和 OR 操作
|
||||
val orParts = expression.split(" OR ", ignoreCase = true)
|
||||
if (orParts.size > 1) {
|
||||
// OR 操作:任一条件为真即为真
|
||||
return orParts.any { part ->
|
||||
evaluateLogicalExpression(part.trim(), gameState)
|
||||
}
|
||||
}
|
||||
|
||||
val andParts = expression.split(" AND ", ignoreCase = true)
|
||||
if (andParts.size > 1) {
|
||||
// AND 操作:所有条件都为真才为真
|
||||
return andParts.all { part ->
|
||||
evaluateLogicalExpression(part.trim(), gameState)
|
||||
}
|
||||
}
|
||||
|
||||
// 单个条件表达式
|
||||
return evaluateSimpleCondition(expression, gameState)
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估简单条件表达式
|
||||
*/
|
||||
private fun evaluateSimpleCondition(condition: String, gameState: GameState): Boolean {
|
||||
val trimmed = condition.trim()
|
||||
|
||||
// 处理括号
|
||||
if (trimmed.startsWith("(") && trimmed.endsWith(")")) {
|
||||
return evaluateLogicalExpression(trimmed.substring(1, trimmed.length - 1), gameState)
|
||||
}
|
||||
|
||||
// 尝试解析为比较表达式
|
||||
val comparisonResult = tryEvaluateComparison(trimmed, gameState)
|
||||
if (comparisonResult != null) {
|
||||
return comparisonResult
|
||||
}
|
||||
|
||||
// 尝试解析为布尔表达式
|
||||
val booleanResult = tryEvaluateBoolean(trimmed, gameState)
|
||||
if (booleanResult != null) {
|
||||
return booleanResult
|
||||
}
|
||||
|
||||
// 尝试解析为变量引用 (flag或anchor)
|
||||
return evaluateVariableReference(trimmed, gameState)
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试评估比较表达式 (如: secrets_found >= 3)
|
||||
*/
|
||||
private fun tryEvaluateComparison(expression: String, gameState: GameState): Boolean? {
|
||||
val comparisonPatterns = listOf(
|
||||
"(.+?)\\s*(>=)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) >= 0 },
|
||||
"(.+?)\\s*(<=)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) <= 0 },
|
||||
"(.+?)\\s*(==)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) == 0 },
|
||||
"(.+?)\\s*(!=)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) != 0 },
|
||||
"(.+?)\\s*(>)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) > 0 },
|
||||
"(.+?)\\s*(<)\\s*(.+)" to { a: Any, b: Any -> compareValues(a, b) < 0 }
|
||||
)
|
||||
|
||||
for ((pattern, compareFn) in comparisonPatterns) {
|
||||
val regex = Pattern.compile(pattern)
|
||||
val matcher = regex.matcher(expression)
|
||||
if (matcher.matches()) {
|
||||
val leftValue = resolveValue(matcher.group(1).trim(), gameState)
|
||||
val rightValue = resolveValue(matcher.group(3).trim(), gameState)
|
||||
return compareFn(leftValue, rightValue)
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试评估布尔表达式 (如: all_crew_saved == true)
|
||||
*/
|
||||
private fun tryEvaluateBoolean(expression: String, gameState: GameState): Boolean? {
|
||||
when {
|
||||
expression.endsWith(" == true", ignoreCase = true) -> {
|
||||
val varName = expression.substring(0, expression.length - 7).trim()
|
||||
return getBooleanValue(varName, gameState)
|
||||
}
|
||||
expression.endsWith(" == false", ignoreCase = true) -> {
|
||||
val varName = expression.substring(0, expression.length - 8).trim()
|
||||
return !getBooleanValue(varName, gameState)
|
||||
}
|
||||
expression.endsWith(" != true", ignoreCase = true) -> {
|
||||
val varName = expression.substring(0, expression.length - 7).trim()
|
||||
return !getBooleanValue(varName, gameState)
|
||||
}
|
||||
expression.endsWith(" != false", ignoreCase = true) -> {
|
||||
val varName = expression.substring(0, expression.length - 8).trim()
|
||||
return getBooleanValue(varName, gameState)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估变量引用 (flag, anchor, variable)
|
||||
*/
|
||||
private fun evaluateVariableReference(varName: String, gameState: GameState): Boolean {
|
||||
return when {
|
||||
// 检查flag
|
||||
gameState.flags.contains(varName) -> true
|
||||
// 检查anchor条件 (这里需要与StoryManager协作)
|
||||
isAnchorCondition(varName, gameState) -> true
|
||||
// 检查变量
|
||||
gameState.variables.containsKey(varName) -> {
|
||||
val value = gameState.variables[varName]
|
||||
when (value) {
|
||||
is Boolean -> value
|
||||
is Number -> value.toDouble() > 0
|
||||
is String -> value.isNotEmpty()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析值 (可以是变量引用、数字或字符串)
|
||||
*/
|
||||
private fun resolveValue(valueStr: String, gameState: GameState): Any {
|
||||
val trimmed = valueStr.trim()
|
||||
|
||||
// 尝试解析为数字
|
||||
trimmed.toIntOrNull()?.let { return it }
|
||||
trimmed.toDoubleOrNull()?.let { return it }
|
||||
|
||||
// 尝试解析为布尔值
|
||||
when (trimmed.lowercase()) {
|
||||
"true" -> return true
|
||||
"false" -> return false
|
||||
}
|
||||
|
||||
// 尝试解析为字符串字面量
|
||||
if (trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
|
||||
return trimmed.substring(1, trimmed.length - 1)
|
||||
}
|
||||
|
||||
// 作为变量引用处理
|
||||
return getVariableValue(trimmed, gameState)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取变量值
|
||||
*/
|
||||
private fun getVariableValue(varName: String, gameState: GameState): Any {
|
||||
return when (varName) {
|
||||
"secrets_found" -> gameState.secretsFound.size
|
||||
"health" -> gameState.health
|
||||
"stamina" -> gameState.stamina
|
||||
"trust_level" -> gameState.trustLevel
|
||||
"loop_count" -> gameState.loopCount
|
||||
"harrison_recording_found" -> gameState.flags.contains("harrison_recording_found")
|
||||
"all_crew_saved" -> gameState.getVariable("all_crew_saved", false)
|
||||
else -> gameState.variables[varName] ?: 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取布尔值
|
||||
*/
|
||||
private fun getBooleanValue(varName: String, gameState: GameState): Boolean {
|
||||
return when (varName) {
|
||||
"harrison_recording_found" -> gameState.flags.contains("harrison_recording_found")
|
||||
"all_crew_saved" -> gameState.getVariable("all_crew_saved", false)
|
||||
in gameState.flags -> true
|
||||
else -> {
|
||||
val value = gameState.variables[varName]
|
||||
when (value) {
|
||||
is Boolean -> value
|
||||
is Number -> value.toDouble() > 0
|
||||
is String -> value.isNotEmpty()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较两个值
|
||||
*/
|
||||
private fun compareValues(a: Any, b: Any): Int {
|
||||
return when {
|
||||
a is Number && b is Number -> {
|
||||
a.toDouble().compareTo(b.toDouble())
|
||||
}
|
||||
a is String && b is String -> {
|
||||
a.compareTo(b)
|
||||
}
|
||||
a is Boolean && b is Boolean -> {
|
||||
a.compareTo(b)
|
||||
}
|
||||
else -> {
|
||||
a.toString().compareTo(b.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为锚点条件 (需要与StoryManager协作)
|
||||
*/
|
||||
private fun isAnchorCondition(anchorName: String, gameState: GameState): Boolean {
|
||||
// 这里应该检查当前加载的锚点条件
|
||||
// 暂时返回false,实际实现需要访问StoryManager
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估锚点条件 (由StoryManager调用)
|
||||
*/
|
||||
fun evaluateAnchorCondition(anchor: AnchorCondition, gameState: GameState): Boolean {
|
||||
return evaluate(anchor.condition, gameState)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量评估条件列表,返回第一个满足条件的索引
|
||||
*/
|
||||
fun findFirstMatch(conditions: List<String>, gameState: GameState): Int {
|
||||
for (i in conditions.indices) {
|
||||
if (evaluate(conditions[i], gameState)) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估条件并返回匹配的目标
|
||||
*/
|
||||
fun evaluateConditionalNavigation(
|
||||
conditional: ConditionalNavigation,
|
||||
gameState: GameState
|
||||
): String? {
|
||||
for (condition in conditional.conditions) {
|
||||
when (condition.type) {
|
||||
ConditionType.IF, ConditionType.ELIF -> {
|
||||
if (evaluate(condition.condition, gameState)) {
|
||||
return condition.nextNodeId
|
||||
}
|
||||
}
|
||||
ConditionType.ELSE -> {
|
||||
return condition.nextNodeId
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,780 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import java.io.InputStream
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* 故事DSL解析器
|
||||
* 解析自定义.story格式文件为StoryModule对象
|
||||
*/
|
||||
class StoryDSLParser {
|
||||
|
||||
companion object {
|
||||
// DSL关键字正则模式
|
||||
private val MODULE_PATTERN = Pattern.compile("@story_module\\s+(\\w+)")
|
||||
private val VERSION_PATTERN = Pattern.compile("@version\\s+([\\d.]+)")
|
||||
private val DEPENDENCIES_PATTERN = Pattern.compile("@dependencies\\s+\\[([^\\]]+)\\]")
|
||||
private val AUDIO_START_PATTERN = Pattern.compile("@audio")
|
||||
private val AUDIO_END_PATTERN = Pattern.compile("@end")
|
||||
private val CHARACTER_PATTERN = Pattern.compile("@character\\s+(\\w+)")
|
||||
private val NODE_PATTERN = Pattern.compile("@node\\s+(\\w+)")
|
||||
private val TITLE_PATTERN = Pattern.compile("@title\\s+\"([^\"]+)\"")
|
||||
private val AUDIO_BG_PATTERN = Pattern.compile("@audio_bg\\s+(\\w+\\.mp3)")
|
||||
private val CONTENT_START_PATTERN = Pattern.compile("@content\\s+\"\"\"")
|
||||
private val CONTENT_END_PATTERN = Pattern.compile("\"\"\"")
|
||||
private val CHOICES_PATTERN = Pattern.compile("@choices\\s+(\\d+)")
|
||||
private val CHOICE_PATTERN = Pattern.compile("\\s*choice_(\\d+):\\s+\"([^\"]+)\"\\s+->\\s+(\\w+)(?:\\s+\\[([^\\]]+)\\])?(?:\\s+\\[([^\\]]+)\\])?")
|
||||
private val ANCHOR_CONDITIONS_PATTERN = Pattern.compile("@anchor_conditions")
|
||||
private val CONDITIONAL_NEXT_PATTERN = Pattern.compile("@conditional_next")
|
||||
private val IF_PATTERN = Pattern.compile("\\s*if\\s+([^:]+):\\s+(\\w+)")
|
||||
private val ELIF_PATTERN = Pattern.compile("\\s*elif\\s+([^:]+):\\s+(\\w+)")
|
||||
private val ELSE_PATTERN = Pattern.compile("\\s*else:\\s+(\\w+)")
|
||||
private val ANCHOR_DEFINITION_PATTERN = Pattern.compile("\\s*(\\w+):\\s+(.+)")
|
||||
|
||||
// 效果和需求解析模式 - 更新以匹配DSL格式
|
||||
private val EFFECT_PATTERN = Pattern.compile("effect:\\s*(\\w+)([+-]?\\d+)")
|
||||
private val REQUIREMENT_PATTERN = Pattern.compile("require:\\s*(\\w+)\\s*([><=!]+)\\s*(\\d+|\\w+)")
|
||||
private val AUDIO_EFFECT_PATTERN = Pattern.compile("audio:\\s*(\\w+\\.mp3)")
|
||||
|
||||
// 括号内容解析模式
|
||||
private val BRACKET_CONTENT_PATTERN = Pattern.compile("\\[([^\\]]+)\\]")
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析输入流中的故事DSL内容
|
||||
*/
|
||||
fun parse(inputStream: InputStream): ParseResult<StoryModule> {
|
||||
try {
|
||||
val content = inputStream.bufferedReader().readText()
|
||||
return parseContent(content)
|
||||
} catch (e: Exception) {
|
||||
return ParseResult.Error("Failed to read input stream: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字符串内容
|
||||
*/
|
||||
fun parseContent(content: String): ParseResult<StoryModule> {
|
||||
println("🔍 [PARSER] Starting parseContent - total lines: ${content.lines().size}")
|
||||
val lines = content.lines()
|
||||
val context = ParseContext()
|
||||
|
||||
var i = 0
|
||||
var loopCount = 0
|
||||
while (i < lines.size) {
|
||||
loopCount++
|
||||
if (loopCount > 10000) {
|
||||
println("❌ [PARSER] INFINITE LOOP DETECTED at line $i - emergency break!")
|
||||
return ParseResult.Error("Infinite loop detected at line ${i + 1}")
|
||||
}
|
||||
|
||||
val line = lines[i].trim()
|
||||
println("🔍 [PARSER] Processing line $i/$lines.size: '${line.take(50)}${if (line.length > 50) "..." else ""}'")
|
||||
|
||||
// 跳过空行和注释
|
||||
if (line.isEmpty() || line.startsWith("//")) {
|
||||
println("🔍 [PARSER] Skipping empty/comment line $i")
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
val nextI = when {
|
||||
MODULE_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched MODULE pattern at line $i")
|
||||
i + parseModule(line, context)
|
||||
}
|
||||
VERSION_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched VERSION pattern at line $i")
|
||||
i + parseVersion(line, context)
|
||||
}
|
||||
DEPENDENCIES_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched DEPENDENCIES pattern at line $i")
|
||||
i + parseDependencies(line, context)
|
||||
}
|
||||
AUDIO_START_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched AUDIO_START pattern at line $i")
|
||||
parseAudioBlock(lines, i, context)
|
||||
}
|
||||
CHARACTER_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched CHARACTER pattern at line $i")
|
||||
parseCharacterBlock(lines, i, context)
|
||||
}
|
||||
NODE_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched NODE pattern at line $i")
|
||||
parseNodeBlock(lines, i, context)
|
||||
}
|
||||
ANCHOR_CONDITIONS_PATTERN.matcher(line).matches() -> {
|
||||
println("🔍 [PARSER] Matched ANCHOR_CONDITIONS pattern at line $i")
|
||||
parseAnchorConditionsBlock(lines, i, context)
|
||||
}
|
||||
else -> {
|
||||
println("🔍 [PARSER] No pattern matched at line $i, advancing by 1")
|
||||
i + 1
|
||||
}
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] Line $i processed, next line: $nextI")
|
||||
if (nextI <= i) {
|
||||
println("❌ [PARSER] WARNING: next line ($nextI) <= current line ($i) - potential infinite loop!")
|
||||
}
|
||||
i = nextI
|
||||
|
||||
} catch (e: ParseException) {
|
||||
println("❌ [PARSER] ParseException at line $i: ${e.message}")
|
||||
return ParseResult.Error("Parse error at line ${i + 1}: ${e.message}", i + 1)
|
||||
} catch (e: Exception) {
|
||||
println("❌ [PARSER] Unexpected exception at line $i: ${e.message}")
|
||||
return ParseResult.Error("Unexpected error at line ${i + 1}: ${e.message}", i + 1)
|
||||
}
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] Main parsing loop completed, building module...")
|
||||
return try {
|
||||
val module = context.buildModule()
|
||||
validateModule(module)
|
||||
println("✅ [PARSER] Module built successfully: ${module.id}")
|
||||
ParseResult.Success(module)
|
||||
} catch (e: Exception) {
|
||||
println("❌ [PARSER] Failed to build module: ${e.message}")
|
||||
ParseResult.Error("Failed to build module: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析模块声明
|
||||
*/
|
||||
private fun parseModule(line: String, context: ParseContext): Int {
|
||||
val matcher = MODULE_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
context.moduleId = matcher.group(1)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析版本信息
|
||||
*/
|
||||
private fun parseVersion(line: String, context: ParseContext): Int {
|
||||
val matcher = VERSION_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
context.version = matcher.group(1)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析依赖列表
|
||||
*/
|
||||
private fun parseDependencies(line: String, context: ParseContext): Int {
|
||||
val matcher = DEPENDENCIES_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
val deps = matcher.group(1).split(",").map { it.trim() }
|
||||
context.dependencies.addAll(deps)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析音频配置块
|
||||
*/
|
||||
private fun parseAudioBlock(lines: List<String>, startIndex: Int, context: ParseContext): Int {
|
||||
var i = startIndex + 1
|
||||
val audioMap = mutableMapOf<String, String>()
|
||||
|
||||
while (i < lines.size) {
|
||||
val line = lines[i].trim()
|
||||
if (AUDIO_END_PATTERN.matcher(line).matches()) {
|
||||
break
|
||||
}
|
||||
|
||||
// 解析 key: value 格式
|
||||
val parts = line.split(":")
|
||||
if (parts.size == 2) {
|
||||
audioMap[parts[0].trim()] = parts[1].trim()
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
context.audioConfig = AudioConfig(
|
||||
background = audioMap["background"],
|
||||
transition = audioMap["transition"],
|
||||
effects = audioMap.filterKeys { it != "background" && it != "transition" }
|
||||
)
|
||||
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析角色定义块
|
||||
*/
|
||||
private fun parseCharacterBlock(lines: List<String>, startIndex: Int, context: ParseContext): Int {
|
||||
println("🔍 [PARSER] Starting parseCharacterBlock at line $startIndex")
|
||||
val matcher = CHARACTER_PATTERN.matcher(lines[startIndex])
|
||||
if (!matcher.find()) {
|
||||
println("❌ [PARSER] CHARACTER_PATTERN failed to match line: '${lines[startIndex]}'")
|
||||
throw ParseException("Invalid character definition")
|
||||
}
|
||||
|
||||
val characterId = matcher.group(1)
|
||||
println("🔍 [PARSER] Parsing character: '$characterId'")
|
||||
var i = startIndex + 1
|
||||
var name = ""
|
||||
var voiceStyle: String? = null
|
||||
val attributes = mutableMapOf<String, String>()
|
||||
|
||||
var loopCount = 0
|
||||
while (i < lines.size) {
|
||||
loopCount++
|
||||
if (loopCount > 1000) {
|
||||
println("❌ [PARSER] INFINITE LOOP in parseCharacterBlock at line $i - emergency break!")
|
||||
throw ParseException("Infinite loop in character block starting at line ${startIndex + 1}")
|
||||
}
|
||||
|
||||
val line = lines[i].trim()
|
||||
println("🔍 [PARSER] Character block line $i: '${line.take(60)}${if (line.length > 60) "..." else ""}'")
|
||||
|
||||
if (AUDIO_END_PATTERN.matcher(line).matches()) { // 复用@end标记
|
||||
println("🔍 [PARSER] Found @end marker at line $i, breaking character block")
|
||||
break
|
||||
}
|
||||
|
||||
when {
|
||||
line.startsWith("name:") -> {
|
||||
name = extractQuotedValue(line.substringAfter(":"))
|
||||
println("🔍 [PARSER] Character name set: '$name'")
|
||||
}
|
||||
line.startsWith("voice_style:") -> {
|
||||
voiceStyle = line.substringAfter(":").trim()
|
||||
println("🔍 [PARSER] Character voice_style set: '$voiceStyle'")
|
||||
}
|
||||
line.contains(":") -> {
|
||||
val parts = line.split(":", limit = 2)
|
||||
attributes[parts[0].trim()] = parts[1].trim()
|
||||
println("🔍 [PARSER] Character attribute: '${parts[0].trim()}' = '${parts[1].trim()}'")
|
||||
}
|
||||
else -> {
|
||||
println("🔍 [PARSER] Unrecognized character attribute line: '$line'")
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
if (i >= lines.size) {
|
||||
println("❌ [PARSER] Character block reached end of file without @end marker")
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] Character '$characterId' parsed successfully, name='$name', voiceStyle='$voiceStyle', attributes=${attributes.size}")
|
||||
context.characters[characterId] = Character(
|
||||
id = characterId,
|
||||
name = name,
|
||||
voiceStyle = voiceStyle,
|
||||
attributes = attributes
|
||||
)
|
||||
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析故事节点块
|
||||
*/
|
||||
private fun parseNodeBlock(lines: List<String>, startIndex: Int, context: ParseContext): Int {
|
||||
val matcher = NODE_PATTERN.matcher(lines[startIndex])
|
||||
if (!matcher.find()) throw ParseException("Invalid node definition")
|
||||
|
||||
val nodeId = matcher.group(1)
|
||||
var i = startIndex + 1
|
||||
var title = ""
|
||||
var content = ""
|
||||
var audioBackground: String? = null
|
||||
val choices = mutableListOf<StoryChoice>()
|
||||
var conditionalNext: ConditionalNavigation? = null
|
||||
val effects = mutableListOf<GameEffect>()
|
||||
val requirements = mutableListOf<GameRequirement>()
|
||||
|
||||
while (i < lines.size && i < lines.size) {
|
||||
val line = lines[i].trim()
|
||||
|
||||
// 检查是否到达下一个节点或块
|
||||
if (line.startsWith("@node") || line.startsWith("@anchor_conditions") ||
|
||||
line.startsWith("@story_module")) {
|
||||
break
|
||||
}
|
||||
|
||||
when {
|
||||
TITLE_PATTERN.matcher(line).matches() -> {
|
||||
val titleMatcher = TITLE_PATTERN.matcher(line)
|
||||
if (titleMatcher.find()) {
|
||||
title = titleMatcher.group(1)
|
||||
}
|
||||
}
|
||||
AUDIO_BG_PATTERN.matcher(line).matches() -> {
|
||||
val audioMatcher = AUDIO_BG_PATTERN.matcher(line)
|
||||
if (audioMatcher.find()) {
|
||||
audioBackground = audioMatcher.group(1)
|
||||
}
|
||||
}
|
||||
CONTENT_START_PATTERN.matcher(line).matches() -> {
|
||||
i = parseContentBlock(lines, i, context) { parsedContent ->
|
||||
content = parsedContent
|
||||
}
|
||||
continue
|
||||
}
|
||||
CHOICES_PATTERN.matcher(line).matches() -> {
|
||||
i = parseChoicesBlock(lines, i, context) { parsedChoices ->
|
||||
choices.addAll(parsedChoices)
|
||||
}
|
||||
continue
|
||||
}
|
||||
CONDITIONAL_NEXT_PATTERN.matcher(line).matches() -> {
|
||||
i = parseConditionalNextBlock(lines, i, context) { parsedConditional ->
|
||||
conditionalNext = parsedConditional
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
context.nodes[nodeId] = StoryNode(
|
||||
id = nodeId,
|
||||
title = title,
|
||||
content = content,
|
||||
choices = choices,
|
||||
audioBackground = audioBackground,
|
||||
conditionalNext = conditionalNext,
|
||||
effects = effects,
|
||||
requirements = requirements
|
||||
)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析内容块
|
||||
*/
|
||||
private fun parseContentBlock(
|
||||
lines: List<String>,
|
||||
startIndex: Int,
|
||||
context: ParseContext,
|
||||
onParsed: (String) -> Unit
|
||||
): Int {
|
||||
var i = startIndex + 1
|
||||
val contentLines = mutableListOf<String>()
|
||||
|
||||
while (i < lines.size) {
|
||||
val line = lines[i]
|
||||
if (CONTENT_END_PATTERN.matcher(line.trim()).matches()) {
|
||||
break
|
||||
}
|
||||
contentLines.add(line)
|
||||
i++
|
||||
}
|
||||
|
||||
onParsed(contentLines.joinToString("\n"))
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析选择块
|
||||
*/
|
||||
private fun parseChoicesBlock(
|
||||
lines: List<String>,
|
||||
startIndex: Int,
|
||||
context: ParseContext,
|
||||
onParsed: (List<StoryChoice>) -> Unit
|
||||
): Int {
|
||||
println("🔍 [PARSER] Starting parseChoicesBlock at line $startIndex")
|
||||
var i = startIndex + 1
|
||||
val choices = mutableListOf<StoryChoice>()
|
||||
|
||||
var loopCount = 0
|
||||
while (i < lines.size) {
|
||||
loopCount++
|
||||
if (loopCount > 500) {
|
||||
println("❌ [PARSER] INFINITE LOOP in parseChoicesBlock at line $i - emergency break!")
|
||||
throw ParseException("Infinite loop in choices block starting at line ${startIndex + 1}")
|
||||
}
|
||||
|
||||
val line = lines[i].trim()
|
||||
println("🔍 [PARSER] Choices block line $i: '${line.take(80)}${if (line.length > 80) "..." else ""}'")
|
||||
|
||||
if (AUDIO_END_PATTERN.matcher(line).matches()) {
|
||||
println("🔍 [PARSER] Found @end marker at line $i, breaking choices block")
|
||||
break
|
||||
}
|
||||
|
||||
val choiceMatcher = CHOICE_PATTERN.matcher(line)
|
||||
if (choiceMatcher.find()) {
|
||||
val choiceId = choiceMatcher.group(1)
|
||||
val text = choiceMatcher.group(2)
|
||||
val nextNodeId = choiceMatcher.group(3)
|
||||
println("🔍 [PARSER] Found choice: id='$choiceId', text='$text', next='$nextNodeId'")
|
||||
|
||||
// 提取所有括号内容
|
||||
val allBrackets = extractAllBrackets(line)
|
||||
println("🔍 [PARSER] Extracted brackets: $allBrackets")
|
||||
|
||||
val effects = mutableListOf<GameEffect>()
|
||||
val requirements = mutableListOf<GameRequirement>()
|
||||
var audioEffect: String? = null
|
||||
|
||||
// 解析每个括号的内容
|
||||
for (bracketContent in allBrackets) {
|
||||
println("🔍 [PARSER] Processing bracket content: '$bracketContent'")
|
||||
when {
|
||||
bracketContent.startsWith("effect:") -> {
|
||||
println("🔍 [PARSER] Parsing effect: '$bracketContent'")
|
||||
val parsedEffects = parseEffects(bracketContent)
|
||||
effects.addAll(parsedEffects)
|
||||
println("🔍 [PARSER] Parsed ${parsedEffects.size} effects")
|
||||
}
|
||||
bracketContent.startsWith("require:") -> {
|
||||
println("🔍 [PARSER] Parsing requirement: '$bracketContent'")
|
||||
val parsedRequirements = parseRequirements(bracketContent)
|
||||
requirements.addAll(parsedRequirements)
|
||||
println("🔍 [PARSER] Parsed ${parsedRequirements.size} requirements")
|
||||
}
|
||||
bracketContent.startsWith("audio:") -> {
|
||||
println("🔍 [PARSER] Parsing audio: '$bracketContent'")
|
||||
audioEffect = extractAudioEffect(bracketContent)
|
||||
println("🔍 [PARSER] Parsed audio effect: '$audioEffect'")
|
||||
}
|
||||
else -> {
|
||||
println("🔍 [PARSER] Unrecognized bracket content: '$bracketContent'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
choices.add(StoryChoice(
|
||||
id = "choice_$choiceId",
|
||||
text = text,
|
||||
nextNodeId = nextNodeId,
|
||||
effects = effects,
|
||||
requirements = requirements,
|
||||
audioEffect = audioEffect
|
||||
))
|
||||
println("🔍 [PARSER] Added choice to list, total choices: ${choices.size}")
|
||||
} else {
|
||||
println("🔍 [PARSER] Line did not match CHOICE_PATTERN")
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] Choices block completed with ${choices.size} choices")
|
||||
onParsed(choices)
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析条件导航块
|
||||
*/
|
||||
private fun parseConditionalNextBlock(
|
||||
lines: List<String>,
|
||||
startIndex: Int,
|
||||
context: ParseContext,
|
||||
onParsed: (ConditionalNavigation) -> Unit
|
||||
): Int {
|
||||
var i = startIndex + 1
|
||||
val conditions = mutableListOf<NavigationCondition>()
|
||||
|
||||
while (i < lines.size) {
|
||||
val line = lines[i].trim()
|
||||
if (AUDIO_END_PATTERN.matcher(line).matches()) {
|
||||
break
|
||||
}
|
||||
|
||||
when {
|
||||
IF_PATTERN.matcher(line).matches() -> {
|
||||
val matcher = IF_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
conditions.add(NavigationCondition(
|
||||
condition = matcher.group(1).trim(),
|
||||
nextNodeId = matcher.group(2),
|
||||
type = ConditionType.IF
|
||||
))
|
||||
}
|
||||
}
|
||||
ELIF_PATTERN.matcher(line).matches() -> {
|
||||
val matcher = ELIF_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
conditions.add(NavigationCondition(
|
||||
condition = matcher.group(1).trim(),
|
||||
nextNodeId = matcher.group(2),
|
||||
type = ConditionType.ELIF
|
||||
))
|
||||
}
|
||||
}
|
||||
ELSE_PATTERN.matcher(line).matches() -> {
|
||||
val matcher = ELSE_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
conditions.add(NavigationCondition(
|
||||
condition = "true",
|
||||
nextNodeId = matcher.group(1),
|
||||
type = ConditionType.ELSE
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
onParsed(ConditionalNavigation(conditions))
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析锚点条件块
|
||||
*/
|
||||
private fun parseAnchorConditionsBlock(lines: List<String>, startIndex: Int, context: ParseContext): Int {
|
||||
var i = startIndex + 1
|
||||
|
||||
while (i < lines.size) {
|
||||
val line = lines[i].trim()
|
||||
if (AUDIO_END_PATTERN.matcher(line).matches()) {
|
||||
break
|
||||
}
|
||||
|
||||
val matcher = ANCHOR_DEFINITION_PATTERN.matcher(line)
|
||||
if (matcher.find()) {
|
||||
val anchorId = matcher.group(1)
|
||||
val condition = matcher.group(2)
|
||||
|
||||
// 这里需要进一步解析条件和目标节点
|
||||
// 暂时使用简单的解析逻辑
|
||||
context.anchors[anchorId] = AnchorCondition(
|
||||
id = anchorId,
|
||||
condition = condition,
|
||||
targetNodeId = "", // 需要从条件中提取
|
||||
priority = 0
|
||||
)
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
return i + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析效果列表
|
||||
*/
|
||||
private fun parseEffects(effectsStr: String): List<GameEffect> {
|
||||
println("🔍 [PARSER] parseEffects input: '$effectsStr'")
|
||||
if (effectsStr.isBlank()) {
|
||||
println("🔍 [PARSER] parseEffects: blank input, returning empty list")
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val effects = mutableListOf<GameEffect>()
|
||||
val matcher = EFFECT_PATTERN.matcher(effectsStr)
|
||||
|
||||
if (matcher.find()) {
|
||||
val type = matcher.group(1)
|
||||
val value = matcher.group(2)
|
||||
println("🔍 [PARSER] parseEffects matched: type='$type', value='$value'")
|
||||
|
||||
val mappedType = mapEffectType(type)
|
||||
println("🔍 [PARSER] parseEffects mapped type: $mappedType")
|
||||
|
||||
effects.add(GameEffect(
|
||||
type = mappedType,
|
||||
target = type,
|
||||
value = value,
|
||||
description = "$type: $value"
|
||||
))
|
||||
} else {
|
||||
println("❌ [PARSER] parseEffects: EFFECT_PATTERN did not match '$effectsStr'")
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] parseEffects result: ${effects.size} effects")
|
||||
return effects
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析需求列表
|
||||
*/
|
||||
private fun parseRequirements(requirementsStr: String): List<GameRequirement> {
|
||||
println("🔍 [PARSER] parseRequirements input: '$requirementsStr'")
|
||||
if (requirementsStr.isBlank()) {
|
||||
println("🔍 [PARSER] parseRequirements: blank input, returning empty list")
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val requirements = mutableListOf<GameRequirement>()
|
||||
val matcher = REQUIREMENT_PATTERN.matcher(requirementsStr)
|
||||
|
||||
if (matcher.find()) {
|
||||
val target = matcher.group(1)
|
||||
val operator = matcher.group(2)
|
||||
val value = matcher.group(3)
|
||||
println("🔍 [PARSER] parseRequirements matched: target='$target', operator='$operator', value='$value'")
|
||||
|
||||
val mappedType = mapRequirementType(target)
|
||||
val mappedOperator = mapOperator(operator)
|
||||
println("🔍 [PARSER] parseRequirements mapped: type=$mappedType, operator=$mappedOperator")
|
||||
|
||||
requirements.add(GameRequirement(
|
||||
type = mappedType,
|
||||
target = target,
|
||||
value = value,
|
||||
operator = mappedOperator
|
||||
))
|
||||
} else {
|
||||
println("❌ [PARSER] parseRequirements: REQUIREMENT_PATTERN did not match '$requirementsStr'")
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] parseRequirements result: ${requirements.size} requirements")
|
||||
return requirements
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取所有括号内容
|
||||
*/
|
||||
private fun extractAllBrackets(line: String): List<String> {
|
||||
println("🔍 [PARSER] extractAllBrackets input: '$line'")
|
||||
val brackets = mutableListOf<String>()
|
||||
val matcher = BRACKET_CONTENT_PATTERN.matcher(line)
|
||||
|
||||
var findCount = 0
|
||||
while (matcher.find()) {
|
||||
findCount++
|
||||
if (findCount > 100) {
|
||||
println("❌ [PARSER] INFINITE LOOP in extractAllBrackets - emergency break!")
|
||||
break
|
||||
}
|
||||
|
||||
val bracketContent = matcher.group(1).trim()
|
||||
brackets.add(bracketContent)
|
||||
println("🔍 [PARSER] Found bracket content: '$bracketContent'")
|
||||
}
|
||||
|
||||
println("🔍 [PARSER] extractAllBrackets result: $brackets")
|
||||
return brackets
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取音频效果
|
||||
*/
|
||||
private fun extractAudioEffect(content: String): String? {
|
||||
val matcher = AUDIO_EFFECT_PATTERN.matcher(content)
|
||||
return if (matcher.find()) {
|
||||
matcher.group(1)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取引号内的值
|
||||
*/
|
||||
private fun extractQuotedValue(text: String): String {
|
||||
val trimmed = text.trim()
|
||||
return if (trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
|
||||
trimmed.substring(1, trimmed.length - 1)
|
||||
} else {
|
||||
trimmed
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射效果类型
|
||||
*/
|
||||
private fun mapEffectType(type: String): EffectType {
|
||||
return when (type.lowercase()) {
|
||||
"health" -> EffectType.HEALTH_CHANGE
|
||||
"stamina" -> EffectType.STAMINA_CHANGE
|
||||
"secret" -> EffectType.SECRET_UNLOCK
|
||||
"secret_unlock" -> EffectType.SECRET_UNLOCK
|
||||
"location" -> EffectType.LOCATION_DISCOVER
|
||||
"loop" -> EffectType.LOOP_CHANGE
|
||||
"trust" -> EffectType.TRUST_CHANGE
|
||||
"flag" -> EffectType.FLAG_SET
|
||||
else -> EffectType.VARIABLE_SET
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射需求类型
|
||||
*/
|
||||
private fun mapRequirementType(type: String): RequirementType {
|
||||
return when (type.lowercase()) {
|
||||
"health" -> RequirementType.MIN_HEALTH
|
||||
"stamina" -> RequirementType.MIN_STAMINA
|
||||
"trust_level" -> RequirementType.MIN_TRUST
|
||||
"trust" -> RequirementType.MIN_TRUST
|
||||
"secret" -> RequirementType.SECRET_UNLOCKED
|
||||
"location" -> RequirementType.LOCATION_DISCOVERED
|
||||
"flag" -> RequirementType.FLAG_SET
|
||||
else -> RequirementType.VARIABLE_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射比较操作符
|
||||
*/
|
||||
private fun mapOperator(operator: String): ComparisonOperator {
|
||||
return when (operator) {
|
||||
"==" -> ComparisonOperator.EQUALS
|
||||
"!=" -> ComparisonOperator.NOT_EQUALS
|
||||
">" -> ComparisonOperator.GREATER_THAN
|
||||
"<" -> ComparisonOperator.LESS_THAN
|
||||
">=" -> ComparisonOperator.GREATER_EQUAL
|
||||
"<=" -> ComparisonOperator.LESS_EQUAL
|
||||
else -> ComparisonOperator.EQUALS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证模块完整性
|
||||
*/
|
||||
private fun validateModule(module: StoryModule) {
|
||||
if (module.id.isEmpty()) {
|
||||
throw ParseException("Module ID is required")
|
||||
}
|
||||
|
||||
if (module.nodes.isEmpty()) {
|
||||
throw ParseException("Module must contain at least one node")
|
||||
}
|
||||
|
||||
// 验证节点引用的完整性
|
||||
for (node in module.nodes.values) {
|
||||
for (choice in node.choices) {
|
||||
if (!module.nodes.containsKey(choice.nextNodeId)) {
|
||||
// 这里可能是锚点引用,暂时跳过验证
|
||||
// throw ParseException("Node '${node.id}' references unknown node '${choice.nextNodeId}'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析上下文 - 用于在解析过程中累积数据
|
||||
*/
|
||||
private data class ParseContext(
|
||||
var moduleId: String = "",
|
||||
var version: String = "1.0",
|
||||
val dependencies: MutableList<String> = mutableListOf(),
|
||||
var audioConfig: AudioConfig? = null,
|
||||
val characters: MutableMap<String, Character> = mutableMapOf(),
|
||||
val nodes: MutableMap<String, StoryNode> = mutableMapOf(),
|
||||
val anchors: MutableMap<String, AnchorCondition> = mutableMapOf()
|
||||
) {
|
||||
fun buildModule(): StoryModule {
|
||||
return StoryModule(
|
||||
id = moduleId,
|
||||
version = version,
|
||||
dependencies = dependencies,
|
||||
audio = audioConfig,
|
||||
characters = characters,
|
||||
nodes = nodes,
|
||||
anchors = anchors
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析异常
|
||||
*/
|
||||
class ParseException(message: String) : Exception(message)
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
/**
|
||||
* 故事引擎数据模型
|
||||
* 支持自定义DSL格式的完整故事系统
|
||||
*/
|
||||
|
||||
// ============================================================================
|
||||
// 核心数据模型
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 故事模块 - 对应一个.story文件
|
||||
*/
|
||||
data class StoryModule(
|
||||
val id: String,
|
||||
val version: String,
|
||||
val dependencies: List<String> = emptyList(),
|
||||
val audio: AudioConfig? = null,
|
||||
val characters: Map<String, Character> = emptyMap(),
|
||||
val nodes: Map<String, StoryNode> = emptyMap(),
|
||||
val anchors: Map<String, AnchorCondition> = emptyMap(),
|
||||
val metadata: ModuleMetadata? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 故事节点 - 对应DSL中的@node
|
||||
*/
|
||||
data class StoryNode(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val content: String,
|
||||
val choices: List<StoryChoice> = emptyList(),
|
||||
val audioBackground: String? = null,
|
||||
val audioTransition: String? = null,
|
||||
val conditionalNext: ConditionalNavigation? = null,
|
||||
val effects: List<GameEffect> = emptyList(),
|
||||
val requirements: List<GameRequirement> = emptyList(),
|
||||
val metadata: NodeMetadata? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 故事选择 - 对应DSL中的choice
|
||||
*/
|
||||
data class StoryChoice(
|
||||
val id: String,
|
||||
val text: String,
|
||||
val nextNodeId: String,
|
||||
val effects: List<GameEffect> = emptyList(),
|
||||
val requirements: List<GameRequirement> = emptyList(),
|
||||
val audioEffect: String? = null,
|
||||
val isEnabled: Boolean = true
|
||||
)
|
||||
|
||||
/**
|
||||
* 条件导航 - 支持if/elif/else逻辑
|
||||
*/
|
||||
data class ConditionalNavigation(
|
||||
val conditions: List<NavigationCondition>
|
||||
)
|
||||
|
||||
data class NavigationCondition(
|
||||
val condition: String, // "eva_reveal_ready" 或 "trust_level >= 2"
|
||||
val nextNodeId: String,
|
||||
val type: ConditionType = ConditionType.IF
|
||||
)
|
||||
|
||||
enum class ConditionType {
|
||||
IF, ELIF, ELSE
|
||||
}
|
||||
|
||||
/**
|
||||
* 锚点条件 - 支持复杂的动态锚点
|
||||
*/
|
||||
data class AnchorCondition(
|
||||
val id: String,
|
||||
val condition: String, // "secrets_found >= 3 AND trust_level >= 5"
|
||||
val targetNodeId: String,
|
||||
val priority: Int = 0 // 多个条件匹配时的优先级
|
||||
)
|
||||
|
||||
/**
|
||||
* 游戏效果 - 增强版效果系统
|
||||
*/
|
||||
data class GameEffect(
|
||||
val type: EffectType,
|
||||
val target: String,
|
||||
val value: String,
|
||||
val description: String = ""
|
||||
)
|
||||
|
||||
enum class EffectType {
|
||||
HEALTH_CHANGE,
|
||||
STAMINA_CHANGE,
|
||||
SECRET_UNLOCK,
|
||||
LOCATION_DISCOVER,
|
||||
LOOP_CHANGE,
|
||||
TRUST_CHANGE,
|
||||
VARIABLE_SET,
|
||||
AUDIO_PLAY,
|
||||
AUDIO_STOP,
|
||||
FLAG_SET,
|
||||
FLAG_REMOVE
|
||||
}
|
||||
|
||||
/**
|
||||
* 游戏需求 - 增强版需求系统
|
||||
*/
|
||||
data class GameRequirement(
|
||||
val type: RequirementType,
|
||||
val target: String,
|
||||
val value: String,
|
||||
val operator: ComparisonOperator = ComparisonOperator.EQUALS
|
||||
)
|
||||
|
||||
enum class RequirementType {
|
||||
MIN_HEALTH,
|
||||
MIN_STAMINA,
|
||||
MIN_TRUST,
|
||||
SECRET_UNLOCKED,
|
||||
LOCATION_DISCOVERED,
|
||||
VARIABLE_VALUE,
|
||||
FLAG_SET,
|
||||
NODE_VISITED,
|
||||
CHOICE_MADE
|
||||
}
|
||||
|
||||
enum class ComparisonOperator {
|
||||
EQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN, GREATER_EQUAL, LESS_EQUAL, CONTAINS
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 音频和媒体
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 音频配置
|
||||
*/
|
||||
data class AudioConfig(
|
||||
val background: String? = null,
|
||||
val transition: String? = null,
|
||||
val effects: Map<String, String> = emptyMap()
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 角色系统
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 角色定义
|
||||
*/
|
||||
data class Character(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val voiceStyle: String? = null,
|
||||
val description: String = "",
|
||||
val attributes: Map<String, String> = emptyMap()
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 元数据
|
||||
// ============================================================================
|
||||
|
||||
data class ModuleMetadata(
|
||||
val title: String,
|
||||
val description: String,
|
||||
val author: String,
|
||||
val tags: List<String> = emptyList(),
|
||||
val createdAt: String,
|
||||
val updatedAt: String
|
||||
)
|
||||
|
||||
data class NodeMetadata(
|
||||
val tags: List<String> = emptyList(),
|
||||
val difficulty: Int = 1,
|
||||
val estimatedReadTime: Int = 0, // 秒
|
||||
val isKeyNode: Boolean = false,
|
||||
val branch: String? = null
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 解析结果和错误处理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* DSL解析结果
|
||||
*/
|
||||
sealed class ParseResult<T> {
|
||||
data class Success<T>(val data: T) : ParseResult<T>()
|
||||
data class Error<T>(val message: String, val line: Int = 0, val column: Int = 0) : ParseResult<T>()
|
||||
}
|
||||
|
||||
data class AudioChange(
|
||||
val type: AudioChangeType,
|
||||
val audioFile: String
|
||||
)
|
||||
|
||||
enum class AudioChangeType {
|
||||
PLAY_BACKGROUND, STOP_BACKGROUND, PLAY_EFFECT, CHANGE_BACKGROUND
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 游戏状态管理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 游戏状态 - 追踪所有游戏变量
|
||||
*/
|
||||
data class GameState(
|
||||
val variables: MutableMap<String, Any> = mutableMapOf(),
|
||||
val flags: MutableSet<String> = mutableSetOf(),
|
||||
val secretsFound: MutableSet<String> = mutableSetOf(),
|
||||
val locationsDiscovered: MutableSet<String> = mutableSetOf(),
|
||||
val nodesVisited: MutableSet<String> = mutableSetOf(),
|
||||
val choicesMade: MutableMap<String, String> = mutableMapOf(),
|
||||
var currentNodeId: String = "",
|
||||
var health: Int = 100,
|
||||
var stamina: Int = 100,
|
||||
var trustLevel: Int = 0,
|
||||
var loopCount: Int = 1
|
||||
) {
|
||||
/**
|
||||
* 获取变量值,支持类型安全的访问
|
||||
*/
|
||||
inline fun <reified T> getVariable(name: String, default: T): T {
|
||||
return (variables[name] as? T) ?: default
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置变量值
|
||||
*/
|
||||
fun setVariable(name: String, value: Any) {
|
||||
variables[name] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查条件是否满足
|
||||
*/
|
||||
fun evaluateCondition(condition: String): Boolean {
|
||||
// 这里将在条件解析器中实现
|
||||
return ConditionEvaluator.evaluate(condition, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.*
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 故事调试工具集
|
||||
*
|
||||
* 功能:
|
||||
* - 故事流程跟踪
|
||||
* - 节点访问分析
|
||||
* - 选择路径可视化
|
||||
* - 死胡同检测
|
||||
* - 故事完整性验证
|
||||
* - 调试报告生成
|
||||
*/
|
||||
class StoryDebugTools(
|
||||
private val context: Context,
|
||||
private val storyManager: StoryManager
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "StoryDebug"
|
||||
private const val DEBUG_LOG_FILE = "story_debug.log"
|
||||
}
|
||||
|
||||
// 调试会话数据
|
||||
private val sessionData = DebugSession()
|
||||
private val nodeAccessLog = mutableListOf<NodeAccessRecord>()
|
||||
private val choicePathLog = mutableListOf<ChoicePathRecord>()
|
||||
private val errorLog = mutableListOf<ErrorRecord>()
|
||||
|
||||
// JSON序列化
|
||||
private val json = Json {
|
||||
prettyPrint = true
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始调试会话
|
||||
*/
|
||||
fun startDebugSession(sessionName: String = "Default") {
|
||||
sessionData.sessionName = sessionName
|
||||
sessionData.startTime = System.currentTimeMillis()
|
||||
sessionData.isActive = true
|
||||
|
||||
Log.d(TAG, "🐛 Debug session '$sessionName' started")
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束调试会话
|
||||
*/
|
||||
fun endDebugSession() {
|
||||
if (!sessionData.isActive) return
|
||||
|
||||
sessionData.endTime = System.currentTimeMillis()
|
||||
sessionData.isActive = false
|
||||
sessionData.duration = sessionData.endTime - sessionData.startTime
|
||||
|
||||
Log.d(TAG, "🏁 Debug session ended. Duration: ${sessionData.duration}ms")
|
||||
generateDebugReport()
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录节点访问
|
||||
*/
|
||||
fun logNodeAccess(
|
||||
nodeId: String,
|
||||
loadTime: Long,
|
||||
fromChoice: String? = null,
|
||||
gameState: GameState
|
||||
) {
|
||||
val record = NodeAccessRecord(
|
||||
nodeId = nodeId,
|
||||
timestamp = System.currentTimeMillis(),
|
||||
loadTime = loadTime,
|
||||
fromChoice = fromChoice,
|
||||
gameStateSnapshot = captureGameStateSnapshot(gameState)
|
||||
)
|
||||
|
||||
nodeAccessLog.add(record)
|
||||
sessionData.totalNodes++
|
||||
|
||||
Log.d(TAG, "📍 Node accessed: $nodeId (${loadTime}ms)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录选择执行
|
||||
*/
|
||||
fun logChoiceExecution(
|
||||
currentNodeId: String,
|
||||
choiceId: String,
|
||||
choiceText: String,
|
||||
nextNodeId: String,
|
||||
effects: List<GameEffect>,
|
||||
executionTime: Long
|
||||
) {
|
||||
val record = ChoicePathRecord(
|
||||
currentNodeId = currentNodeId,
|
||||
choiceId = choiceId,
|
||||
choiceText = choiceText,
|
||||
nextNodeId = nextNodeId,
|
||||
effects = effects.map { "${it.type.name}:${it.value}" },
|
||||
timestamp = System.currentTimeMillis(),
|
||||
executionTime = executionTime
|
||||
)
|
||||
|
||||
choicePathLog.add(record)
|
||||
sessionData.totalChoices++
|
||||
|
||||
Log.d(TAG, "🎯 Choice executed: $choiceText -> $nextNodeId (${executionTime}ms)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录错误
|
||||
*/
|
||||
fun logError(
|
||||
errorType: String,
|
||||
message: String,
|
||||
context: String? = null,
|
||||
exception: Throwable? = null
|
||||
) {
|
||||
val record = ErrorRecord(
|
||||
errorType = errorType,
|
||||
message = message,
|
||||
context = context,
|
||||
stackTrace = exception?.stackTraceToString(),
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
|
||||
errorLog.add(record)
|
||||
sessionData.totalErrors++
|
||||
|
||||
Log.e(TAG, "❌ Error: $errorType - $message")
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析故事流程
|
||||
*/
|
||||
suspend fun analyzeStoryFlow(): StoryFlowAnalysis {
|
||||
val analysis = StoryFlowAnalysis()
|
||||
|
||||
// 分析节点访问模式
|
||||
analysis.mostVisitedNodes = nodeAccessLog
|
||||
.groupBy { it.nodeId }
|
||||
.mapValues { it.value.size }
|
||||
.toList()
|
||||
.sortedByDescending { it.second }
|
||||
.take(10)
|
||||
|
||||
// 分析选择模式
|
||||
analysis.mostUsedChoices = choicePathLog
|
||||
.groupBy { it.choiceText }
|
||||
.mapValues { it.value.size }
|
||||
.toList()
|
||||
.sortedByDescending { it.second }
|
||||
.take(10)
|
||||
|
||||
// 分析平均加载时间
|
||||
analysis.averageNodeLoadTime = nodeAccessLog
|
||||
.map { it.loadTime }
|
||||
.average()
|
||||
|
||||
// 检测死胡同(被访问但没有后续选择的节点)
|
||||
analysis.deadEndNodes = findDeadEndNodes()
|
||||
|
||||
// 分析游戏状态变化
|
||||
analysis.gameStateProgression = analyzeGameStateProgression()
|
||||
|
||||
Log.d(TAG, "📊 Story flow analysis completed")
|
||||
return analysis
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证故事完整性
|
||||
*/
|
||||
suspend fun validateStoryIntegrity(): StoryIntegrityReport {
|
||||
val report = StoryIntegrityReport()
|
||||
|
||||
// 检查所有模块
|
||||
val modules = loadAllModules()
|
||||
report.totalModules = modules.size
|
||||
|
||||
// 验证节点链接
|
||||
val allNodes = modules.flatMap { it.nodes.values }
|
||||
report.totalNodes = allNodes.size
|
||||
|
||||
val brokenLinks = mutableListOf<String>()
|
||||
val orphanedNodes = mutableListOf<String>()
|
||||
|
||||
for (node in allNodes) {
|
||||
// 检查选择链接
|
||||
for (choice in node.choices) {
|
||||
val targetExists = allNodes.any { it.id == choice.nextNodeId }
|
||||
if (!targetExists) {
|
||||
brokenLinks.add("${node.id} -> ${choice.nextNodeId}")
|
||||
}
|
||||
}
|
||||
|
||||
// 检查条件导航
|
||||
node.conditionalNext?.conditions?.forEach { condition ->
|
||||
val targetExists = allNodes.any { it.id == condition.nextNodeId }
|
||||
if (!targetExists) {
|
||||
brokenLinks.add("${node.id} -> ${condition.nextNodeId} (conditional)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查孤立节点(没有任何链接指向的节点)
|
||||
val referencedNodeIds = allNodes.flatMap { node ->
|
||||
node.choices.map { it.nextNodeId } +
|
||||
(node.conditionalNext?.conditions?.map { it.nextNodeId } ?: emptyList())
|
||||
}.toSet()
|
||||
|
||||
orphanedNodes.addAll(
|
||||
allNodes.map { it.id }.filter { it !in referencedNodeIds && it != "game_start" }
|
||||
)
|
||||
|
||||
report.brokenLinks = brokenLinks
|
||||
report.orphanedNodes = orphanedNodes
|
||||
report.isValid = brokenLinks.isEmpty() && orphanedNodes.isEmpty()
|
||||
|
||||
Log.d(TAG, "✅ Story integrity validation completed. Valid: ${report.isValid}")
|
||||
return report
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成可视化的故事图
|
||||
*/
|
||||
fun generateStoryGraph(): String {
|
||||
val mermaidGraph = StringBuilder()
|
||||
mermaidGraph.appendLine("graph TD")
|
||||
|
||||
// 添加节点访问频率信息
|
||||
val nodeVisitCounts = nodeAccessLog.groupBy { it.nodeId }.mapValues { it.value.size }
|
||||
|
||||
for (record in choicePathLog.distinctBy { "${it.currentNodeId}->${it.nextNodeId}" }) {
|
||||
val currentVisits = nodeVisitCounts[record.currentNodeId] ?: 0
|
||||
val nextVisits = nodeVisitCounts[record.nextNodeId] ?: 0
|
||||
|
||||
val currentStyle = if (currentVisits > 5) ":::hotNode" else ":::normalNode"
|
||||
val nextStyle = if (nextVisits > 5) ":::hotNode" else ":::normalNode"
|
||||
|
||||
mermaidGraph.appendLine(
|
||||
" ${record.currentNodeId}$currentStyle --> ${record.nextNodeId}$nextStyle"
|
||||
)
|
||||
}
|
||||
|
||||
// 添加样式定义
|
||||
mermaidGraph.appendLine(" classDef hotNode fill:#ff6b6b")
|
||||
mermaidGraph.appendLine(" classDef normalNode fill:#4ecdc4")
|
||||
|
||||
return mermaidGraph.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成调试报告
|
||||
*/
|
||||
private fun generateDebugReport() {
|
||||
val report = DebugReport(
|
||||
sessionData = sessionData,
|
||||
nodeAccessLog = nodeAccessLog.takeLast(100), // 最近100条
|
||||
choicePathLog = choicePathLog.takeLast(100),
|
||||
errorLog = errorLog,
|
||||
summary = DebugSummary(
|
||||
totalPlayTime = sessionData.duration,
|
||||
uniqueNodesVisited = nodeAccessLog.map { it.nodeId }.distinct().size,
|
||||
averageNodeLoadTime = nodeAccessLog.map { it.loadTime }.average(),
|
||||
totalErrors = errorLog.size,
|
||||
mostVisitedNode = nodeAccessLog
|
||||
.groupBy { it.nodeId }
|
||||
.maxByOrNull { it.value.size }?.key ?: "none"
|
||||
)
|
||||
)
|
||||
|
||||
// 保存到文件
|
||||
saveDebugReport(report)
|
||||
|
||||
// 输出到日志
|
||||
Log.i(TAG, """
|
||||
📋 === DEBUG SESSION REPORT ===
|
||||
Session: ${report.sessionData.sessionName}
|
||||
Duration: ${report.summary.totalPlayTime / 1000}s
|
||||
Nodes visited: ${report.summary.uniqueNodesVisited}
|
||||
Choices made: ${report.sessionData.totalChoices}
|
||||
Errors: ${report.summary.totalErrors}
|
||||
Avg load time: ${"%.1f".format(report.summary.averageNodeLoadTime)}ms
|
||||
Most visited: ${report.summary.mostVisitedNode}
|
||||
=== END REPORT ===
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载所有模块(用于验证)
|
||||
*/
|
||||
private suspend fun loadAllModules(): List<StoryModule> {
|
||||
val modules = mutableListOf<StoryModule>()
|
||||
val moduleNames = listOf(
|
||||
"characters", "audio_config", "anchors",
|
||||
"main_chapter_1", "main_chapter_2", "main_chapter_3",
|
||||
"side_stories", "investigation_branch", "endings"
|
||||
)
|
||||
|
||||
for (moduleName in moduleNames) {
|
||||
try {
|
||||
val module = storyManager.loadModule(moduleName)
|
||||
modules.add(module)
|
||||
} catch (e: Exception) {
|
||||
logError("MODULE_LOAD_FAILED", "Failed to load module: $moduleName", null, e)
|
||||
}
|
||||
}
|
||||
|
||||
return modules
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找死胡同节点
|
||||
*/
|
||||
private fun findDeadEndNodes(): List<String> {
|
||||
val nodesWithChoices = choicePathLog.map { it.currentNodeId }.toSet()
|
||||
val visitedNodes = nodeAccessLog.map { it.nodeId }.toSet()
|
||||
|
||||
// 被访问但没有后续选择的节点可能是死胡同
|
||||
return visitedNodes.filter { it !in nodesWithChoices }
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析游戏状态进展
|
||||
*/
|
||||
private fun analyzeGameStateProgression(): List<GameStateSnapshot> {
|
||||
return nodeAccessLog
|
||||
.map { it.gameStateSnapshot }
|
||||
.filterIndexed { index, _ -> index % 5 == 0 } // 每5个节点采样一次
|
||||
.takeLast(20) // 最近20个快照
|
||||
}
|
||||
|
||||
/**
|
||||
* 捕获游戏状态快照
|
||||
*/
|
||||
private fun captureGameStateSnapshot(gameState: GameState): GameStateSnapshot {
|
||||
return GameStateSnapshot(
|
||||
health = gameState.health,
|
||||
stamina = gameState.stamina,
|
||||
trustLevel = gameState.trustLevel,
|
||||
secretsFound = gameState.secretsFound.size,
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存调试报告到文件
|
||||
*/
|
||||
private fun saveDebugReport(report: DebugReport) {
|
||||
try {
|
||||
val debugDir = File(context.getExternalFilesDir(null), "debug")
|
||||
if (!debugDir.exists()) {
|
||||
debugDir.mkdirs()
|
||||
}
|
||||
|
||||
val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault())
|
||||
.format(Date())
|
||||
val filename = "debug_report_$timestamp.json"
|
||||
val file = File(debugDir, filename)
|
||||
|
||||
file.writeText(json.encodeToString(report))
|
||||
Log.d(TAG, "💾 Debug report saved: ${file.absolutePath}")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to save debug report", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类
|
||||
// ============================================================================
|
||||
|
||||
@Serializable
|
||||
data class DebugSession(
|
||||
var sessionName: String = "",
|
||||
var startTime: Long = 0L,
|
||||
var endTime: Long = 0L,
|
||||
var duration: Long = 0L,
|
||||
var isActive: Boolean = false,
|
||||
var totalNodes: Int = 0,
|
||||
var totalChoices: Int = 0,
|
||||
var totalErrors: Int = 0
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class NodeAccessRecord(
|
||||
val nodeId: String,
|
||||
val timestamp: Long,
|
||||
val loadTime: Long,
|
||||
val fromChoice: String?,
|
||||
val gameStateSnapshot: GameStateSnapshot
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ChoicePathRecord(
|
||||
val currentNodeId: String,
|
||||
val choiceId: String,
|
||||
val choiceText: String,
|
||||
val nextNodeId: String,
|
||||
val effects: List<String>,
|
||||
val timestamp: Long,
|
||||
val executionTime: Long
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ErrorRecord(
|
||||
val errorType: String,
|
||||
val message: String,
|
||||
val context: String?,
|
||||
val stackTrace: String?,
|
||||
val timestamp: Long
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GameStateSnapshot(
|
||||
val health: Int,
|
||||
val stamina: Int,
|
||||
val trustLevel: Int,
|
||||
val secretsFound: Int,
|
||||
val timestamp: Long
|
||||
)
|
||||
|
||||
data class StoryFlowAnalysis(
|
||||
var mostVisitedNodes: List<Pair<String, Int>> = emptyList(),
|
||||
var mostUsedChoices: List<Pair<String, Int>> = emptyList(),
|
||||
var averageNodeLoadTime: Double = 0.0,
|
||||
var deadEndNodes: List<String> = emptyList(),
|
||||
var gameStateProgression: List<GameStateSnapshot> = emptyList()
|
||||
)
|
||||
|
||||
data class StoryIntegrityReport(
|
||||
var totalModules: Int = 0,
|
||||
var totalNodes: Int = 0,
|
||||
var brokenLinks: List<String> = emptyList(),
|
||||
var orphanedNodes: List<String> = emptyList(),
|
||||
var isValid: Boolean = false
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class DebugReport(
|
||||
val sessionData: DebugSession,
|
||||
val nodeAccessLog: List<NodeAccessRecord>,
|
||||
val choicePathLog: List<ChoicePathRecord>,
|
||||
val errorLog: List<ErrorRecord>,
|
||||
val summary: DebugSummary
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class DebugSummary(
|
||||
val totalPlayTime: Long,
|
||||
val uniqueNodesVisited: Int,
|
||||
val averageNodeLoadTime: Double,
|
||||
val totalErrors: Int,
|
||||
val mostVisitedNode: String
|
||||
)
|
||||
@@ -0,0 +1,418 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import android.content.Context
|
||||
import com.example.gameofmoon.model.SimpleChoice
|
||||
import com.example.gameofmoon.model.SimpleStoryNode
|
||||
import com.example.gameofmoon.model.SimpleEffect
|
||||
import com.example.gameofmoon.model.SimpleEffectType
|
||||
import com.example.gameofmoon.story.CompleteStoryData
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
/**
|
||||
* 故事引擎适配器
|
||||
*
|
||||
* 在新的DSL引擎和现有游戏UI之间提供兼容层
|
||||
* 支持渐进式迁移:优雅降级到原有系统
|
||||
*/
|
||||
class StoryEngineAdapter(
|
||||
private val context: Context,
|
||||
private val scope: CoroutineScope = MainScope()
|
||||
) {
|
||||
|
||||
// 新引擎和旧系统
|
||||
private val newStoryManager = StoryManager(context, scope)
|
||||
private val fallbackStoryData = CompleteStoryData
|
||||
|
||||
// 引擎状态
|
||||
private var isNewEngineEnabled = true
|
||||
private var isNewEngineReady = false
|
||||
|
||||
// 状态流 - 对外提供统一接口
|
||||
private val _currentNode = MutableStateFlow<SimpleStoryNode?>(null)
|
||||
val currentNode: StateFlow<SimpleStoryNode?> = _currentNode.asStateFlow()
|
||||
|
||||
private val _isLoading = MutableStateFlow(false)
|
||||
val isLoading: StateFlow<Boolean> = _isLoading.asStateFlow()
|
||||
|
||||
private val _error = MutableStateFlow<String?>(null)
|
||||
val error: StateFlow<String?> = _error.asStateFlow()
|
||||
|
||||
// 游戏状态同步
|
||||
private val _gameStats = MutableStateFlow(GameStats())
|
||||
val gameStats: StateFlow<GameStats> = _gameStats.asStateFlow()
|
||||
|
||||
// 音频回调
|
||||
var audioCallback: ((String) -> Unit)? = null
|
||||
|
||||
// ============================================================================
|
||||
// 初始化
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 初始化适配器
|
||||
*/
|
||||
suspend fun initialize(): Boolean {
|
||||
return try {
|
||||
_isLoading.value = true
|
||||
_error.value = null
|
||||
|
||||
// 尝试初始化新引擎
|
||||
isNewEngineReady = newStoryManager.initialize()
|
||||
|
||||
if (isNewEngineReady) {
|
||||
println("✅ New story engine initialized successfully")
|
||||
setupNewEngineObservers()
|
||||
} else {
|
||||
println("⚠️ New story engine failed, falling back to legacy system")
|
||||
isNewEngineEnabled = false
|
||||
}
|
||||
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
println("❌ Adapter initialization failed: ${e.message}")
|
||||
_error.value = "Failed to initialize story engine: ${e.message}"
|
||||
isNewEngineEnabled = false
|
||||
false
|
||||
} finally {
|
||||
_isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新引擎的观察者
|
||||
*/
|
||||
private fun setupNewEngineObservers() {
|
||||
// 观察当前节点变化
|
||||
scope.launch {
|
||||
newStoryManager.currentNode.collect { newNode ->
|
||||
_currentNode.value = newNode?.let { convertToSimpleNode(it) }
|
||||
}
|
||||
}
|
||||
|
||||
// 观察加载状态
|
||||
scope.launch {
|
||||
newStoryManager.isLoading.collect { loading ->
|
||||
_isLoading.value = loading
|
||||
}
|
||||
}
|
||||
|
||||
// 观察错误状态
|
||||
scope.launch {
|
||||
newStoryManager.error.collect { error ->
|
||||
_error.value = error
|
||||
}
|
||||
}
|
||||
|
||||
// 观察游戏状态
|
||||
scope.launch {
|
||||
newStoryManager.gameStateFlow.collect { gameState ->
|
||||
_gameStats.value = convertToGameStats(gameState)
|
||||
}
|
||||
}
|
||||
|
||||
// 设置音频回调
|
||||
newStoryManager.audioCallback = { audioChange ->
|
||||
audioCallback?.invoke(audioChange.audioFile)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 核心接口 - 对外提供统一的API
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 获取故事节点
|
||||
*/
|
||||
suspend fun getNode(nodeId: String): SimpleStoryNode? {
|
||||
return if (isNewEngineEnabled && isNewEngineReady) {
|
||||
// 使用新引擎
|
||||
newStoryManager.getNode(nodeId)?.let { convertToSimpleNode(it) }
|
||||
} else {
|
||||
// 使用旧系统
|
||||
fallbackStoryData.getAllStoryNodes()[nodeId]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航到节点
|
||||
*/
|
||||
suspend fun navigateToNode(nodeId: String): Boolean {
|
||||
return try {
|
||||
if (isNewEngineEnabled && isNewEngineReady) {
|
||||
// 使用新引擎
|
||||
when (val result = newStoryManager.navigateToNode(nodeId)) {
|
||||
is NavigationResult.Success -> {
|
||||
// 新引擎的观察者会自动更新UI状态
|
||||
true
|
||||
}
|
||||
is NavigationResult.Error -> {
|
||||
_error.value = result.message
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 使用旧系统
|
||||
val node = fallbackStoryData.getAllStoryNodes()[nodeId]
|
||||
if (node != null) {
|
||||
_currentNode.value = node
|
||||
true
|
||||
} else {
|
||||
_error.value = "Node not found: $nodeId"
|
||||
false
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
_error.value = "Navigation failed: ${e.message}"
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行选择
|
||||
*/
|
||||
suspend fun executeChoice(choiceId: String): Boolean {
|
||||
return try {
|
||||
if (isNewEngineEnabled && isNewEngineReady) {
|
||||
// 使用新引擎
|
||||
when (val result = newStoryManager.executeChoice(choiceId)) {
|
||||
is NavigationResult.Success -> {
|
||||
true
|
||||
}
|
||||
is NavigationResult.Error -> {
|
||||
_error.value = result.message
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 使用旧系统
|
||||
val currentNode = _currentNode.value
|
||||
val choice = currentNode?.choices?.find { it.id == choiceId }
|
||||
|
||||
if (choice != null) {
|
||||
// 执行选择效果(简化版)
|
||||
processLegacyEffects(choice.effects)
|
||||
|
||||
// 导航到下一个节点
|
||||
navigateToNode(choice.nextNodeId)
|
||||
} else {
|
||||
_error.value = "Choice not found: $choiceId"
|
||||
false
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
_error.value = "Choice execution failed: ${e.message}"
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始新游戏
|
||||
*/
|
||||
suspend fun startNewGame(): Boolean {
|
||||
return if (isNewEngineEnabled && isNewEngineReady) {
|
||||
when (val result = newStoryManager.startNewGame()) {
|
||||
is NavigationResult.Success -> true
|
||||
is NavigationResult.Error -> {
|
||||
_error.value = result.message
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 使用旧系统的开始节点
|
||||
navigateToNode("game_start")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可用选择
|
||||
*/
|
||||
fun getAvailableChoices(): List<SimpleChoice> {
|
||||
return if (isNewEngineEnabled && isNewEngineReady) {
|
||||
newStoryManager.getAvailableChoices().map { convertToSimpleChoice(it) }
|
||||
} else {
|
||||
_currentNode.value?.choices ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 引擎切换和降级
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 启用新引擎
|
||||
*/
|
||||
suspend fun enableNewEngine(): Boolean {
|
||||
if (!isNewEngineReady) {
|
||||
isNewEngineReady = newStoryManager.initialize()
|
||||
}
|
||||
|
||||
if (isNewEngineReady) {
|
||||
isNewEngineEnabled = true
|
||||
setupNewEngineObservers()
|
||||
println("✅ Switched to new story engine")
|
||||
return true
|
||||
} else {
|
||||
println("❌ Failed to enable new engine")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用新引擎,降级到旧系统
|
||||
*/
|
||||
fun disableNewEngine() {
|
||||
isNewEngineEnabled = false
|
||||
println("⚠️ Switched to legacy story system")
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查引擎状态
|
||||
*/
|
||||
fun getEngineStatus(): EngineStatus {
|
||||
return EngineStatus(
|
||||
isNewEngineEnabled = isNewEngineEnabled,
|
||||
isNewEngineReady = isNewEngineReady,
|
||||
currentEngine = if (isNewEngineEnabled && isNewEngineReady) "DSL Engine v2.0" else "Legacy Engine v1.0"
|
||||
)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据转换器
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 将新的StoryNode转换为SimpleStoryNode
|
||||
*/
|
||||
private fun convertToSimpleNode(node: StoryNode): SimpleStoryNode {
|
||||
return SimpleStoryNode(
|
||||
id = node.id,
|
||||
title = node.title,
|
||||
content = node.content,
|
||||
choices = node.choices.map { convertToSimpleChoice(it) }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将新的StoryChoice转换为SimpleChoice
|
||||
*/
|
||||
private fun convertToSimpleChoice(choice: StoryChoice): SimpleChoice {
|
||||
return SimpleChoice(
|
||||
id = choice.id,
|
||||
text = choice.text,
|
||||
nextNodeId = choice.nextNodeId,
|
||||
effects = choice.effects.map { convertToSimpleEffect(it) },
|
||||
requirements = emptyList() // 简化版暂时不转换需求
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将新的GameEffect转换为SimpleEffect
|
||||
*/
|
||||
private fun convertToSimpleEffect(effect: GameEffect): SimpleEffect {
|
||||
val simpleType = when (effect.type) {
|
||||
EffectType.HEALTH_CHANGE -> SimpleEffectType.HEALTH_CHANGE
|
||||
EffectType.STAMINA_CHANGE -> SimpleEffectType.STAMINA_CHANGE
|
||||
EffectType.SECRET_UNLOCK -> SimpleEffectType.SECRET_UNLOCK
|
||||
EffectType.LOCATION_DISCOVER -> SimpleEffectType.LOCATION_DISCOVER
|
||||
EffectType.LOOP_CHANGE -> SimpleEffectType.LOOP_CHANGE
|
||||
else -> SimpleEffectType.HEALTH_CHANGE // 默认值
|
||||
}
|
||||
|
||||
return SimpleEffect(
|
||||
type = simpleType,
|
||||
value = effect.value,
|
||||
description = effect.description
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将新的GameState转换为GameStats
|
||||
*/
|
||||
private fun convertToGameStats(gameState: GameState): GameStats {
|
||||
return GameStats(
|
||||
health = gameState.health,
|
||||
stamina = gameState.stamina,
|
||||
trustLevel = gameState.trustLevel,
|
||||
secretsFound = gameState.secretsFound.size,
|
||||
locationsDiscovered = gameState.locationsDiscovered.size,
|
||||
loopCount = gameState.loopCount,
|
||||
currentNodeId = gameState.currentNodeId
|
||||
)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 旧系统支持
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 处理旧系统的效果
|
||||
*/
|
||||
private fun processLegacyEffects(effects: List<SimpleEffect>) {
|
||||
val currentStats = _gameStats.value
|
||||
var newStats = currentStats.copy()
|
||||
|
||||
for (effect in effects) {
|
||||
when (effect.type) {
|
||||
SimpleEffectType.HEALTH_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
newStats = newStats.copy(health = (newStats.health + change).coerceIn(0, 100))
|
||||
}
|
||||
SimpleEffectType.STAMINA_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
newStats = newStats.copy(stamina = (newStats.stamina + change).coerceIn(0, 100))
|
||||
}
|
||||
SimpleEffectType.SECRET_UNLOCK -> {
|
||||
newStats = newStats.copy(secretsFound = newStats.secretsFound + 1)
|
||||
}
|
||||
SimpleEffectType.LOCATION_DISCOVER -> {
|
||||
newStats = newStats.copy(locationsDiscovered = newStats.locationsDiscovered + 1)
|
||||
}
|
||||
SimpleEffectType.LOOP_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
newStats = newStats.copy(loopCount = newStats.loopCount + change)
|
||||
}
|
||||
SimpleEffectType.DAY_CHANGE -> {
|
||||
// 处理DAY_CHANGE,如果有的话
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_gameStats.value = newStats
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 清理
|
||||
// ============================================================================
|
||||
|
||||
fun cleanup() {
|
||||
newStoryManager.cleanup()
|
||||
scope.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 游戏统计数据 - 简化版的游戏状态
|
||||
*/
|
||||
data class GameStats(
|
||||
val health: Int = 100,
|
||||
val stamina: Int = 100,
|
||||
val trustLevel: Int = 0,
|
||||
val secretsFound: Int = 0,
|
||||
val locationsDiscovered: Int = 0,
|
||||
val loopCount: Int = 1,
|
||||
val currentNodeId: String = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 引擎状态信息
|
||||
*/
|
||||
data class EngineStatus(
|
||||
val isNewEngineEnabled: Boolean,
|
||||
val isNewEngineReady: Boolean,
|
||||
val currentEngine: String
|
||||
)
|
||||
@@ -0,0 +1,512 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/**
|
||||
* 故事引擎验证器
|
||||
*
|
||||
* 综合测试工具,验证整个DSL引擎的功能和性能
|
||||
*/
|
||||
class StoryEngineValidator(
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "StoryValidator"
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行完整的引擎验证
|
||||
*/
|
||||
suspend fun runFullValidation(): ValidationResult {
|
||||
Log.i(TAG, "🧪 Starting comprehensive story engine validation...")
|
||||
|
||||
val results = mutableListOf<TestResult>()
|
||||
|
||||
// 测试1:引擎初始化
|
||||
results.add(testEngineInitialization())
|
||||
|
||||
// 测试2:DSL解析
|
||||
results.add(testDSLParsing())
|
||||
|
||||
// 测试3:模块加载
|
||||
results.add(testModuleLoading())
|
||||
|
||||
// 测试4:故事导航
|
||||
results.add(testStoryNavigation())
|
||||
|
||||
// 测试5:条件系统
|
||||
results.add(testConditionSystem())
|
||||
|
||||
// 测试6:效果系统
|
||||
results.add(testEffectSystem())
|
||||
|
||||
// 测试7:缓存性能
|
||||
results.add(testCachePerformance())
|
||||
|
||||
// 测试8:错误处理
|
||||
results.add(testErrorHandling())
|
||||
|
||||
// 测试9:故事完整性
|
||||
results.add(testStoryIntegrity())
|
||||
|
||||
// 测试10:性能基准
|
||||
results.add(testPerformanceBenchmark())
|
||||
|
||||
val validationResult = ValidationResult(
|
||||
totalTests = results.size,
|
||||
passedTests = results.count { it.passed },
|
||||
failedTests = results.count { !it.passed },
|
||||
results = results,
|
||||
overallScore = calculateOverallScore(results)
|
||||
)
|
||||
|
||||
logValidationSummary(validationResult)
|
||||
return validationResult
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试引擎初始化
|
||||
*/
|
||||
private suspend fun testEngineInitialization(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(
|
||||
context = context,
|
||||
enablePerformanceMonitoring = true,
|
||||
enableDebugTools = true
|
||||
)
|
||||
|
||||
val initSuccess = storyManager.initialize()
|
||||
storyManager.cleanup()
|
||||
|
||||
TestResult(
|
||||
testName = "Engine Initialization",
|
||||
passed = initSuccess,
|
||||
message = if (initSuccess) "Engine initialized successfully" else "Engine initialization failed",
|
||||
executionTime = 0L
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Engine Initialization",
|
||||
passed = false,
|
||||
message = "Exception during initialization: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试DSL解析
|
||||
*/
|
||||
private suspend fun testDSLParsing(): TestResult {
|
||||
return try {
|
||||
val parser = StoryDSLParser()
|
||||
val testDSL = """
|
||||
@story_module test_module
|
||||
@version 1.0
|
||||
|
||||
@node test_node
|
||||
@title "Test Node"
|
||||
@content "This is a test node for validation."
|
||||
|
||||
@choices 2
|
||||
choice_1: "Option 1" -> next_node [effect: health+5]
|
||||
choice_2: "Option 2" -> end_node [require: stamina >= 10]
|
||||
@end
|
||||
""".trimIndent()
|
||||
|
||||
val result = parser.parseContent(testDSL)
|
||||
|
||||
when (result) {
|
||||
is ParseResult.Success -> {
|
||||
val module = result.data
|
||||
val hasNode = module.nodes.containsKey("test_node")
|
||||
val nodeHasChoices = module.nodes["test_node"]?.choices?.size == 2
|
||||
|
||||
TestResult(
|
||||
testName = "DSL Parsing",
|
||||
passed = hasNode && nodeHasChoices,
|
||||
message = "DSL parsed successfully with ${module.nodes.size} nodes",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
is ParseResult.Error -> {
|
||||
TestResult(
|
||||
testName = "DSL Parsing",
|
||||
passed = false,
|
||||
message = "DSL parsing failed: ${result.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "DSL Parsing",
|
||||
passed = false,
|
||||
message = "Exception during DSL parsing: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试模块加载
|
||||
*/
|
||||
private suspend fun testModuleLoading(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = false)
|
||||
storyManager.initialize()
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
// 尝试加载示例模块
|
||||
val module = storyManager.loadModule("main_chapter_1")
|
||||
|
||||
val loadTime = System.currentTimeMillis() - startTime
|
||||
storyManager.cleanup()
|
||||
|
||||
TestResult(
|
||||
testName = "Module Loading",
|
||||
passed = module.nodes.isNotEmpty(),
|
||||
message = "Loaded module with ${module.nodes.size} nodes",
|
||||
executionTime = loadTime
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Module Loading",
|
||||
passed = false,
|
||||
message = "Module loading failed: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试故事导航
|
||||
*/
|
||||
private suspend fun testStoryNavigation(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = false)
|
||||
storyManager.initialize()
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
// 尝试导航到开始节点
|
||||
val result = storyManager.navigateToNode("game_start")
|
||||
|
||||
val navigateTime = System.currentTimeMillis() - startTime
|
||||
storyManager.cleanup()
|
||||
|
||||
val success = when (result) {
|
||||
is NavigationResult.Success -> true
|
||||
is NavigationResult.Error -> false
|
||||
}
|
||||
|
||||
TestResult(
|
||||
testName = "Story Navigation",
|
||||
passed = success,
|
||||
message = if (success) "Navigation successful" else "Navigation failed: ${(result as NavigationResult.Error).message}",
|
||||
executionTime = navigateTime
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Story Navigation",
|
||||
passed = false,
|
||||
message = "Navigation exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试条件系统
|
||||
*/
|
||||
private suspend fun testConditionSystem(): TestResult {
|
||||
return try {
|
||||
val gameState = GameState().apply {
|
||||
health = 80
|
||||
stamina = 50
|
||||
trustLevel = 3
|
||||
secretsFound.add("test_secret")
|
||||
}
|
||||
|
||||
val testConditions = listOf(
|
||||
"health >= 70" to true,
|
||||
"stamina < 60" to true,
|
||||
"trust_level == 3" to true,
|
||||
"secrets_found >= 1" to true,
|
||||
"health > 100" to false,
|
||||
"trust_level < 0" to false
|
||||
)
|
||||
|
||||
var passedConditions = 0
|
||||
for ((condition, expectedResult) in testConditions) {
|
||||
val actualResult = ConditionEvaluator.evaluate(condition, gameState)
|
||||
if (actualResult == expectedResult) {
|
||||
passedConditions++
|
||||
}
|
||||
}
|
||||
|
||||
val allPassed = passedConditions == testConditions.size
|
||||
|
||||
TestResult(
|
||||
testName = "Condition System",
|
||||
passed = allPassed,
|
||||
message = "Condition evaluation: $passedConditions/${testConditions.size} passed",
|
||||
executionTime = 0L
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Condition System",
|
||||
passed = false,
|
||||
message = "Condition system exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试效果系统
|
||||
*/
|
||||
private suspend fun testEffectSystem(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = false)
|
||||
storyManager.initialize()
|
||||
|
||||
// 创建测试效果
|
||||
val testEffects = listOf(
|
||||
GameEffect(EffectType.HEALTH_CHANGE, "health", "10", "Health boost"),
|
||||
GameEffect(EffectType.SECRET_UNLOCK, "test_secret", "test_value", "Secret unlock"),
|
||||
GameEffect(EffectType.TRUST_CHANGE, "trust", "5", "Trust increase")
|
||||
)
|
||||
|
||||
// 这里应该测试效果执行,但需要访问私有方法
|
||||
// 简化版测试:验证效果对象创建
|
||||
val effectsCreated = testEffects.all {
|
||||
it.type != null && it.target.isNotEmpty() && it.value.isNotEmpty()
|
||||
}
|
||||
|
||||
storyManager.cleanup()
|
||||
|
||||
TestResult(
|
||||
testName = "Effect System",
|
||||
passed = effectsCreated,
|
||||
message = "Effect system objects created successfully",
|
||||
executionTime = 0L
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Effect System",
|
||||
passed = false,
|
||||
message = "Effect system exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试缓存性能
|
||||
*/
|
||||
private suspend fun testCachePerformance(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = true)
|
||||
storyManager.initialize()
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
// 第一次加载(应该较慢)
|
||||
val firstLoad = System.currentTimeMillis()
|
||||
storyManager.getNode("game_start")
|
||||
val firstLoadTime = System.currentTimeMillis() - firstLoad
|
||||
|
||||
// 第二次加载(应该从缓存,更快)
|
||||
val secondLoad = System.currentTimeMillis()
|
||||
storyManager.getNode("game_start")
|
||||
val secondLoadTime = System.currentTimeMillis() - secondLoad
|
||||
|
||||
val totalTime = System.currentTimeMillis() - startTime
|
||||
storyManager.cleanup()
|
||||
|
||||
// 缓存应该让第二次加载更快
|
||||
val cacheEffective = secondLoadTime <= firstLoadTime
|
||||
|
||||
TestResult(
|
||||
testName = "Cache Performance",
|
||||
passed = cacheEffective,
|
||||
message = "First: ${firstLoadTime}ms, Second: ${secondLoadTime}ms",
|
||||
executionTime = totalTime
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Cache Performance",
|
||||
passed = false,
|
||||
message = "Cache performance test exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试错误处理
|
||||
*/
|
||||
private suspend fun testErrorHandling(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = false)
|
||||
storyManager.initialize()
|
||||
|
||||
// 尝试加载不存在的模块
|
||||
val invalidModuleResult = try {
|
||||
storyManager.loadModule("non_existent_module")
|
||||
false // 不应该成功
|
||||
} catch (e: StoryException) {
|
||||
true // 应该抛出异常
|
||||
}
|
||||
|
||||
// 尝试导航到不存在的节点
|
||||
val invalidNodeResult = storyManager.navigateToNode("non_existent_node")
|
||||
val isErrorResult = invalidNodeResult is NavigationResult.Error
|
||||
|
||||
storyManager.cleanup()
|
||||
|
||||
val allErrorsHandled = invalidModuleResult && isErrorResult
|
||||
|
||||
TestResult(
|
||||
testName = "Error Handling",
|
||||
passed = allErrorsHandled,
|
||||
message = "Error handling validation completed",
|
||||
executionTime = 0L
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Error Handling",
|
||||
passed = false,
|
||||
message = "Error handling test exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试故事完整性
|
||||
*/
|
||||
private suspend fun testStoryIntegrity(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enableDebugTools = true)
|
||||
storyManager.initialize()
|
||||
|
||||
val integrityReport = storyManager.validateStoryIntegrity()
|
||||
storyManager.cleanup()
|
||||
|
||||
val isValid = integrityReport?.isValid ?: false
|
||||
val brokenLinksCount = integrityReport?.brokenLinks?.size ?: 0
|
||||
|
||||
TestResult(
|
||||
testName = "Story Integrity",
|
||||
passed = isValid,
|
||||
message = if (isValid) "Story integrity validated" else "Found $brokenLinksCount broken links",
|
||||
executionTime = 0L
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Story Integrity",
|
||||
passed = false,
|
||||
message = "Story integrity test exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试性能基准
|
||||
*/
|
||||
private suspend fun testPerformanceBenchmark(): TestResult {
|
||||
return try {
|
||||
val storyManager = StoryManager(context, enablePerformanceMonitoring = true)
|
||||
storyManager.initialize()
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
// 执行一系列操作
|
||||
repeat(10) {
|
||||
storyManager.getNode("game_start")
|
||||
}
|
||||
|
||||
val totalTime = System.currentTimeMillis() - startTime
|
||||
val averageTime = totalTime / 10.0
|
||||
|
||||
val performanceReport = storyManager.generatePerformanceReport()
|
||||
storyManager.cleanup()
|
||||
|
||||
// 性能基准:平均操作时间应该少于100ms
|
||||
val performanceAcceptable = averageTime < 100.0
|
||||
|
||||
TestResult(
|
||||
testName = "Performance Benchmark",
|
||||
passed = performanceAcceptable,
|
||||
message = "Average operation time: ${"%.1f".format(averageTime)}ms",
|
||||
executionTime = totalTime
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
TestResult(
|
||||
testName = "Performance Benchmark",
|
||||
passed = false,
|
||||
message = "Performance benchmark exception: ${e.message}",
|
||||
executionTime = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算总体得分
|
||||
*/
|
||||
private fun calculateOverallScore(results: List<TestResult>): Int {
|
||||
val totalTests = results.size
|
||||
val passedTests = results.count { it.passed }
|
||||
return (passedTests.toFloat() / totalTests * 100).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出验证摘要
|
||||
*/
|
||||
private fun logValidationSummary(result: ValidationResult) {
|
||||
Log.i(TAG, """
|
||||
🏆 === STORY ENGINE VALIDATION COMPLETE ===
|
||||
📊 Overall Score: ${result.overallScore}%
|
||||
✅ Passed: ${result.passedTests}/${result.totalTests}
|
||||
❌ Failed: ${result.failedTests}/${result.totalTests}
|
||||
|
||||
📋 Test Results:
|
||||
${result.results.joinToString("\n") {
|
||||
val status = if (it.passed) "✅" else "❌"
|
||||
"$status ${it.testName}: ${it.message} (${it.executionTime}ms)"
|
||||
}}
|
||||
|
||||
${if (result.overallScore >= 80)
|
||||
"🎉 ENGINE VALIDATION PASSED!"
|
||||
else
|
||||
"⚠️ ENGINE NEEDS IMPROVEMENT"}
|
||||
=== END VALIDATION ===
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类
|
||||
// ============================================================================
|
||||
|
||||
data class TestResult(
|
||||
val testName: String,
|
||||
val passed: Boolean,
|
||||
val message: String,
|
||||
val executionTime: Long
|
||||
)
|
||||
|
||||
data class ValidationResult(
|
||||
val totalTests: Int,
|
||||
val passedTests: Int,
|
||||
val failedTests: Int,
|
||||
val results: List<TestResult>,
|
||||
val overallScore: Int
|
||||
)
|
||||
@@ -0,0 +1,643 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import android.content.Context
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* 故事管理器 - 新一代DSL驱动的故事引擎
|
||||
*
|
||||
* 核心功能:
|
||||
* - 模块化故事加载 (懒加载 + 缓存)
|
||||
* - 智能导航和锚点解析
|
||||
* - 条件评估和动态内容
|
||||
* - 音频集成和状态管理
|
||||
* - 错误处理和降级机制
|
||||
*/
|
||||
class StoryManager(
|
||||
private val context: Context,
|
||||
private val scope: CoroutineScope = MainScope(),
|
||||
private val enablePerformanceMonitoring: Boolean = true,
|
||||
private val enableDebugTools: Boolean = true
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val STORY_ASSETS_PATH = "story"
|
||||
private const val CONFIG_FILE = "config.json"
|
||||
private const val FALLBACK_START_NODE = "game_start"
|
||||
|
||||
// 缓存配置
|
||||
private const val MAX_CACHE_SIZE = 50
|
||||
private const val PRELOAD_MODULES = 3
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 核心组件
|
||||
// ============================================================================
|
||||
|
||||
private val parser = StoryDSLParser()
|
||||
private val gameState = GameState()
|
||||
|
||||
// 性能监控和调试工具
|
||||
private val performanceMonitor = if (enablePerformanceMonitoring) {
|
||||
StoryPerformanceMonitor()
|
||||
} else null
|
||||
|
||||
private val debugTools = if (enableDebugTools) {
|
||||
StoryDebugTools(context, this)
|
||||
} else null
|
||||
|
||||
// 缓存系统
|
||||
private val moduleCache = ConcurrentHashMap<String, StoryModule>()
|
||||
private val nodeCache = LRUCache<String, StoryNode>(MAX_CACHE_SIZE)
|
||||
|
||||
// 状态流
|
||||
private val _currentNode = MutableStateFlow<StoryNode?>(null)
|
||||
val currentNode: StateFlow<StoryNode?> = _currentNode.asStateFlow()
|
||||
|
||||
private val _gameStateFlow = MutableStateFlow(gameState)
|
||||
val gameStateFlow: StateFlow<GameState> = _gameStateFlow.asStateFlow()
|
||||
|
||||
private val _isLoading = MutableStateFlow(false)
|
||||
val isLoading: StateFlow<Boolean> = _isLoading.asStateFlow()
|
||||
|
||||
private val _error = MutableStateFlow<String?>(null)
|
||||
val error: StateFlow<String?> = _error.asStateFlow()
|
||||
|
||||
// 音频回调
|
||||
var audioCallback: ((AudioChange) -> Unit)? = null
|
||||
|
||||
// 配置
|
||||
private var storyConfig: StoryConfig? = null
|
||||
|
||||
// ============================================================================
|
||||
// 初始化
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 初始化故事管理器
|
||||
*/
|
||||
suspend fun initialize(): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
_isLoading.value = true
|
||||
_error.value = null
|
||||
|
||||
// 加载配置
|
||||
loadConfiguration()
|
||||
|
||||
// 预加载核心模块
|
||||
preloadCoreModules()
|
||||
|
||||
// 初始化游戏状态
|
||||
initializeGameState()
|
||||
|
||||
// 启动监控和调试工具
|
||||
performanceMonitor?.startMonitoring()
|
||||
debugTools?.startDebugSession("Main Game Session")
|
||||
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
_error.value = "Failed to initialize story engine: ${e.message}"
|
||||
false
|
||||
} finally {
|
||||
_isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载故事配置
|
||||
*/
|
||||
private suspend fun loadConfiguration() {
|
||||
try {
|
||||
val configInputStream = context.assets.open("$STORY_ASSETS_PATH/$CONFIG_FILE")
|
||||
val configJson = configInputStream.bufferedReader().readText()
|
||||
// TODO: 解析JSON配置
|
||||
println("📋 Story configuration loaded")
|
||||
} catch (e: IOException) {
|
||||
println("⚠️ No configuration file found, using defaults")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载核心模块
|
||||
*/
|
||||
private suspend fun preloadCoreModules() {
|
||||
val coreModules = listOf("characters", "audio_config", "main_chapter_1")
|
||||
println("🔍 [MANAGER] Starting preloadCoreModules: $coreModules")
|
||||
|
||||
coreModules.forEachIndexed { index, moduleName ->
|
||||
try {
|
||||
println("🔍 [MANAGER] Preloading module ${index + 1}/${coreModules.size}: '$moduleName'")
|
||||
loadModule(moduleName)
|
||||
println("📦 [MANAGER] Successfully preloaded module: $moduleName")
|
||||
} catch (e: Exception) {
|
||||
println("⚠️ [MANAGER] Failed to preload module $moduleName: ${e.javaClass.simpleName}: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
println("🔍 [MANAGER] preloadCoreModules completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化游戏状态
|
||||
*/
|
||||
private fun initializeGameState() {
|
||||
gameState.setVariable("story_engine_version", "2.0")
|
||||
gameState.setVariable("initialization_time", System.currentTimeMillis())
|
||||
_gameStateFlow.value = gameState
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 模块加载
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 加载故事模块
|
||||
*/
|
||||
suspend fun loadModule(moduleName: String): StoryModule {
|
||||
println("🔍 [MANAGER] Starting loadModule: '$moduleName'")
|
||||
// 检查缓存
|
||||
moduleCache[moduleName]?.let {
|
||||
println("🔍 [MANAGER] Module '$moduleName' found in cache")
|
||||
return it
|
||||
}
|
||||
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val moduleFile = "$STORY_ASSETS_PATH/modules/$moduleName.story"
|
||||
println("🔍 [MANAGER] Opening asset file: '$moduleFile'")
|
||||
val inputStream = context.assets.open(moduleFile)
|
||||
|
||||
println("🔍 [MANAGER] Starting DSL parsing for module '$moduleName'")
|
||||
when (val result = parser.parse(inputStream)) {
|
||||
is ParseResult.Success -> {
|
||||
val module = result.data
|
||||
moduleCache[moduleName] = module
|
||||
|
||||
// 缓存模块中的节点
|
||||
module.nodes.values.forEach { node ->
|
||||
nodeCache.put(node.id, node)
|
||||
}
|
||||
|
||||
val loadTime = System.currentTimeMillis() - startTime
|
||||
performanceMonitor?.recordModuleLoadTime(moduleName, loadTime, true)
|
||||
|
||||
println("✅ [MANAGER] Module loaded: $moduleName (${module.nodes.size} nodes) in ${loadTime}ms")
|
||||
module
|
||||
}
|
||||
is ParseResult.Error -> {
|
||||
val loadTime = System.currentTimeMillis() - startTime
|
||||
performanceMonitor?.recordModuleLoadTime(moduleName, loadTime, false)
|
||||
debugTools?.logError("MODULE_PARSE_ERROR", result.message, moduleName)
|
||||
throw StoryException("Failed to parse module $moduleName: ${result.message}")
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
debugTools?.logError("MODULE_NOT_FOUND", "Module file not found: $moduleName", null, e)
|
||||
throw StoryException("Module file not found: $moduleName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取故事节点
|
||||
*/
|
||||
suspend fun getNode(nodeId: String): StoryNode? {
|
||||
// 首先检查缓存
|
||||
nodeCache.get(nodeId)?.let { return it }
|
||||
|
||||
// 搜索所有已加载的模块
|
||||
for (module in moduleCache.values) {
|
||||
module.nodes[nodeId]?.let { node ->
|
||||
nodeCache.put(nodeId, node)
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试懒加载可能包含该节点的模块
|
||||
val possibleModules = guessModulesForNode(nodeId)
|
||||
for (moduleName in possibleModules) {
|
||||
try {
|
||||
val module = loadModule(moduleName)
|
||||
module.nodes[nodeId]?.let { node ->
|
||||
nodeCache.put(nodeId, node)
|
||||
return node
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("⚠️ Failed to load module $moduleName while searching for node $nodeId")
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据节点ID猜测可能的模块
|
||||
*/
|
||||
private fun guessModulesForNode(nodeId: String): List<String> {
|
||||
return when {
|
||||
nodeId.startsWith("side_") -> listOf("side_stories")
|
||||
nodeId.contains("investigation") -> listOf("investigation_branch")
|
||||
nodeId.contains("ending") -> listOf("endings")
|
||||
nodeId.contains("eva_") -> listOf("main_chapter_2", "main_chapter_3")
|
||||
else -> listOf("main_chapter_1", "main_chapter_2", "main_chapter_3")
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 导航系统
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 导航到指定节点
|
||||
*/
|
||||
suspend fun navigateToNode(nodeId: String): NavigationResult {
|
||||
return withContext(Dispatchers.Main) {
|
||||
try {
|
||||
_isLoading.value = true
|
||||
|
||||
// 解析锚点
|
||||
val resolvedNodeId = resolveAnchor(nodeId)
|
||||
|
||||
// 获取节点
|
||||
val node = getNode(resolvedNodeId)
|
||||
?: return@withContext NavigationResult.Error("Node not found: $resolvedNodeId")
|
||||
|
||||
// 更新当前节点
|
||||
_currentNode.value = node
|
||||
gameState.currentNodeId = resolvedNodeId
|
||||
gameState.nodesVisited.add(resolvedNodeId)
|
||||
|
||||
// 处理节点效果
|
||||
val effects = processNodeEffects(node)
|
||||
|
||||
// 处理音频变化
|
||||
val audioChanges = processAudioChanges(node)
|
||||
|
||||
_gameStateFlow.value = gameState
|
||||
|
||||
NavigationResult.Success(
|
||||
node = node,
|
||||
effects = effects,
|
||||
audioChanges = audioChanges
|
||||
)
|
||||
|
||||
} catch (e: Exception) {
|
||||
NavigationResult.Error("Navigation failed: ${e.message}")
|
||||
} finally {
|
||||
_isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行选择
|
||||
*/
|
||||
suspend fun executeChoice(choiceId: String): NavigationResult {
|
||||
val currentNode = _currentNode.value
|
||||
?: return NavigationResult.Error("No current node")
|
||||
|
||||
val choice = currentNode.choices.find { it.id == choiceId }
|
||||
?: return NavigationResult.Error("Choice not found: $choiceId")
|
||||
|
||||
// 检查选择需求
|
||||
if (!checkRequirements(choice.requirements)) {
|
||||
return NavigationResult.Error("Choice requirements not met")
|
||||
}
|
||||
|
||||
// 执行选择效果
|
||||
val choiceEffects = executeEffects(choice.effects)
|
||||
|
||||
// 记录选择
|
||||
gameState.choicesMade[currentNode.id] = choiceId
|
||||
|
||||
// 解析下一个节点
|
||||
val nextNodeId = resolveNextNode(choice, currentNode)
|
||||
|
||||
// 导航到下一个节点
|
||||
return when (val navResult = navigateToNode(nextNodeId)) {
|
||||
is NavigationResult.Success -> {
|
||||
navResult.copy(effects = navResult.effects + choiceEffects)
|
||||
}
|
||||
is NavigationResult.Error -> navResult
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析锚点
|
||||
*/
|
||||
private suspend fun resolveAnchor(nodeId: String): String {
|
||||
// 首先检查是否为锚点
|
||||
for (module in moduleCache.values) {
|
||||
for (anchor in module.anchors.values) {
|
||||
if (anchor.id == nodeId && ConditionEvaluator.evaluateAnchorCondition(anchor, gameState)) {
|
||||
return anchor.targetNodeId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 不是锚点,直接返回
|
||||
return nodeId
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析下一个节点
|
||||
*/
|
||||
private fun resolveNextNode(choice: StoryChoice, currentNode: StoryNode): String {
|
||||
// 检查当前节点是否有条件导航
|
||||
currentNode.conditionalNext?.let { conditional ->
|
||||
ConditionEvaluator.evaluateConditionalNavigation(conditional, gameState)?.let { nextId ->
|
||||
return nextId
|
||||
}
|
||||
}
|
||||
|
||||
// 使用选择指定的下一个节点
|
||||
return choice.nextNodeId
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 效果和需求处理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 检查需求
|
||||
*/
|
||||
private fun checkRequirements(requirements: List<GameRequirement>): Boolean {
|
||||
return requirements.all { requirement ->
|
||||
when (requirement.type) {
|
||||
RequirementType.MIN_HEALTH -> gameState.health >= requirement.value.toIntOrNull() ?: 0
|
||||
RequirementType.MIN_STAMINA -> gameState.stamina >= requirement.value.toIntOrNull() ?: 0
|
||||
RequirementType.MIN_TRUST -> gameState.trustLevel >= requirement.value.toIntOrNull() ?: 0
|
||||
RequirementType.SECRET_UNLOCKED -> gameState.secretsFound.contains(requirement.target)
|
||||
RequirementType.LOCATION_DISCOVERED -> gameState.locationsDiscovered.contains(requirement.target)
|
||||
RequirementType.VARIABLE_VALUE -> {
|
||||
val currentValue = gameState.getVariable(requirement.target, 0)
|
||||
val requiredValue = requirement.value.toIntOrNull() ?: 0
|
||||
when (requirement.operator) {
|
||||
ComparisonOperator.GREATER_EQUAL -> (currentValue as? Int ?: 0) >= requiredValue
|
||||
ComparisonOperator.EQUALS -> currentValue == requiredValue
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
RequirementType.FLAG_SET -> gameState.flags.contains(requirement.target)
|
||||
RequirementType.NODE_VISITED -> gameState.nodesVisited.contains(requirement.target)
|
||||
RequirementType.CHOICE_MADE -> gameState.choicesMade.containsKey(requirement.target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行效果
|
||||
*/
|
||||
private fun executeEffects(effects: List<GameEffect>): List<GameEffect> {
|
||||
val executedEffects = mutableListOf<GameEffect>()
|
||||
|
||||
for (effect in effects) {
|
||||
try {
|
||||
when (effect.type) {
|
||||
EffectType.HEALTH_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
gameState.health = (gameState.health + change).coerceIn(0, 100)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.STAMINA_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
gameState.stamina = (gameState.stamina + change).coerceIn(0, 100)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.SECRET_UNLOCK -> {
|
||||
gameState.secretsFound.add(effect.target)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.LOCATION_DISCOVER -> {
|
||||
gameState.locationsDiscovered.add(effect.target)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.LOOP_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
gameState.loopCount += change
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.TRUST_CHANGE -> {
|
||||
val change = effect.value.toIntOrNull() ?: 0
|
||||
gameState.trustLevel = (gameState.trustLevel + change).coerceIn(0, 100)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.VARIABLE_SET -> {
|
||||
gameState.setVariable(effect.target, effect.value)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.FLAG_SET -> {
|
||||
gameState.flags.add(effect.target)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.FLAG_REMOVE -> {
|
||||
gameState.flags.remove(effect.target)
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.AUDIO_PLAY -> {
|
||||
audioCallback?.invoke(AudioChange(AudioChangeType.PLAY_EFFECT, effect.value))
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
EffectType.AUDIO_STOP -> {
|
||||
audioCallback?.invoke(AudioChange(AudioChangeType.STOP_BACKGROUND, ""))
|
||||
executedEffects.add(effect)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("⚠️ Failed to execute effect: $effect - ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
return executedEffects
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理节点效果
|
||||
*/
|
||||
private fun processNodeEffects(node: StoryNode): List<GameEffect> {
|
||||
return executeEffects(node.effects)
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理音频变化
|
||||
*/
|
||||
private fun processAudioChanges(node: StoryNode): List<AudioChange> {
|
||||
val audioChanges = mutableListOf<AudioChange>()
|
||||
|
||||
// 背景音乐变化
|
||||
node.audioBackground?.let { bgMusic ->
|
||||
audioChanges.add(AudioChange(AudioChangeType.CHANGE_BACKGROUND, bgMusic))
|
||||
audioCallback?.invoke(audioChanges.last())
|
||||
}
|
||||
|
||||
// 转场音效
|
||||
node.audioTransition?.let { transitionAudio ->
|
||||
audioChanges.add(AudioChange(AudioChangeType.PLAY_EFFECT, transitionAudio))
|
||||
audioCallback?.invoke(audioChanges.last())
|
||||
}
|
||||
|
||||
return audioChanges
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 状态管理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 开始新游戏
|
||||
*/
|
||||
suspend fun startNewGame(): NavigationResult {
|
||||
// 重置游戏状态
|
||||
gameState.apply {
|
||||
variables.clear()
|
||||
flags.clear()
|
||||
secretsFound.clear()
|
||||
locationsDiscovered.clear()
|
||||
nodesVisited.clear()
|
||||
choicesMade.clear()
|
||||
currentNodeId = ""
|
||||
health = 100
|
||||
stamina = 100
|
||||
trustLevel = 0
|
||||
loopCount = 1
|
||||
}
|
||||
|
||||
// 导航到开始节点
|
||||
return navigateToNode(FALLBACK_START_NODE)
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存游戏状态
|
||||
*/
|
||||
fun saveGameState(): String {
|
||||
// TODO: 实现序列化
|
||||
return ""
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载游戏状态
|
||||
*/
|
||||
suspend fun loadGameState(saveData: String): Boolean {
|
||||
// TODO: 实现反序列化
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前可用的选择
|
||||
*/
|
||||
fun getAvailableChoices(): List<StoryChoice> {
|
||||
val currentNode = _currentNode.value ?: return emptyList()
|
||||
|
||||
return currentNode.choices.filter { choice ->
|
||||
checkRequirements(choice.requirements)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 清理
|
||||
// ============================================================================
|
||||
|
||||
fun cleanup() {
|
||||
performanceMonitor?.stopMonitoring()
|
||||
debugTools?.endDebugSession()
|
||||
scope.cancel()
|
||||
moduleCache.clear()
|
||||
nodeCache.clear()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 监控和调试接口
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 获取性能数据
|
||||
*/
|
||||
fun getPerformanceData() = performanceMonitor?.performanceData
|
||||
|
||||
/**
|
||||
* 生成性能报告
|
||||
*/
|
||||
fun generatePerformanceReport() = performanceMonitor?.generatePerformanceReport()
|
||||
|
||||
/**
|
||||
* 分析故事流程
|
||||
*/
|
||||
suspend fun analyzeStoryFlow() = debugTools?.analyzeStoryFlow()
|
||||
|
||||
/**
|
||||
* 验证故事完整性
|
||||
*/
|
||||
suspend fun validateStoryIntegrity() = debugTools?.validateStoryIntegrity()
|
||||
|
||||
/**
|
||||
* 生成故事图
|
||||
*/
|
||||
fun generateStoryGraph() = debugTools?.generateStoryGraph()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 导航结果
|
||||
// ============================================================================
|
||||
|
||||
sealed class NavigationResult {
|
||||
data class Success(
|
||||
val node: StoryNode,
|
||||
val effects: List<GameEffect> = emptyList(),
|
||||
val audioChanges: List<AudioChange> = emptyList(),
|
||||
val messages: List<String> = emptyList()
|
||||
) : NavigationResult()
|
||||
|
||||
data class Error(val message: String) : NavigationResult()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 配置和异常
|
||||
// ============================================================================
|
||||
|
||||
data class StoryConfig(
|
||||
val version: String,
|
||||
val defaultLanguage: String,
|
||||
val modules: List<String>,
|
||||
val audio: AudioSettings,
|
||||
val gameplay: GameplaySettings
|
||||
)
|
||||
|
||||
data class AudioSettings(
|
||||
val enabled: Boolean,
|
||||
val defaultVolume: Float,
|
||||
val fadeDuration: Int
|
||||
)
|
||||
|
||||
data class GameplaySettings(
|
||||
val autoSave: Boolean,
|
||||
val choiceTimeout: Int,
|
||||
val skipSeenContent: Boolean
|
||||
)
|
||||
|
||||
class StoryException(message: String, cause: Throwable? = null) : Exception(message, cause)
|
||||
|
||||
// ============================================================================
|
||||
// LRU缓存实现
|
||||
// ============================================================================
|
||||
|
||||
class LRUCache<K, V>(private val maxSize: Int) {
|
||||
private val cache = LinkedHashMap<K, V>(maxSize + 1, 0.75f, true)
|
||||
|
||||
fun get(key: K): V? = cache[key]
|
||||
|
||||
fun put(key: K, value: V) {
|
||||
cache[key] = value
|
||||
if (cache.size > maxSize) {
|
||||
val oldest = cache.keys.first()
|
||||
cache.remove(oldest)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() = cache.clear()
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
package com.example.gameofmoon.story.engine
|
||||
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
/**
|
||||
* 故事引擎性能监控器
|
||||
*
|
||||
* 功能:
|
||||
* - 实时性能监控
|
||||
* - 内存使用跟踪
|
||||
* - 加载时间分析
|
||||
* - 缓存命中率统计
|
||||
* - 性能报告生成
|
||||
*/
|
||||
class StoryPerformanceMonitor {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "StoryPerformance"
|
||||
private const val PERFORMANCE_LOG_INTERVAL = 30_000L // 30秒
|
||||
}
|
||||
|
||||
// 性能指标
|
||||
private val metrics = ConcurrentHashMap<String, PerformanceMetric>()
|
||||
private val loadingTimes = mutableListOf<LoadingTimeRecord>()
|
||||
private val memorySnapshots = mutableListOf<MemorySnapshot>()
|
||||
|
||||
// 缓存统计
|
||||
private var cacheHits = 0
|
||||
private var cacheMisses = 0
|
||||
private var totalRequests = 0
|
||||
|
||||
// 实时监控
|
||||
private val monitoringScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
private var isMonitoring = false
|
||||
|
||||
// 性能数据流
|
||||
private val _performanceData = MutableStateFlow(PerformanceData())
|
||||
val performanceData: StateFlow<PerformanceData> = _performanceData.asStateFlow()
|
||||
|
||||
/**
|
||||
* 开始性能监控
|
||||
*/
|
||||
fun startMonitoring() {
|
||||
if (isMonitoring) return
|
||||
|
||||
isMonitoring = true
|
||||
Log.d(TAG, "🚀 Performance monitoring started")
|
||||
|
||||
monitoringScope.launch {
|
||||
while (isMonitoring) {
|
||||
collectPerformanceData()
|
||||
delay(PERFORMANCE_LOG_INTERVAL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止性能监控
|
||||
*/
|
||||
fun stopMonitoring() {
|
||||
isMonitoring = false
|
||||
Log.d(TAG, "⏹️ Performance monitoring stopped")
|
||||
generateFinalReport()
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录操作执行时间
|
||||
*/
|
||||
suspend fun <T> measureOperation(
|
||||
operationName: String,
|
||||
operation: suspend () -> T
|
||||
): T {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val result: T
|
||||
|
||||
val executionTime = measureTimeMillis {
|
||||
result = operation()
|
||||
}
|
||||
|
||||
recordOperationTime(operationName, executionTime)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录模块加载时间
|
||||
*/
|
||||
fun recordModuleLoadTime(moduleName: String, loadTime: Long, success: Boolean) {
|
||||
loadingTimes.add(LoadingTimeRecord(
|
||||
moduleName = moduleName,
|
||||
loadTime = loadTime,
|
||||
timestamp = System.currentTimeMillis(),
|
||||
success = success
|
||||
))
|
||||
|
||||
Log.d(TAG, "📦 Module '$moduleName' loaded in ${loadTime}ms (success: $success)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录缓存命中
|
||||
*/
|
||||
fun recordCacheHit(cacheType: String, key: String) {
|
||||
cacheHits++
|
||||
totalRequests++
|
||||
|
||||
val metric = metrics.getOrPut("cache_$cacheType") {
|
||||
PerformanceMetric("cache_$cacheType")
|
||||
}
|
||||
metric.recordSuccess()
|
||||
|
||||
if (totalRequests % 10 == 0) {
|
||||
val hitRate = (cacheHits.toFloat() / totalRequests * 100).toInt()
|
||||
Log.d(TAG, "💾 Cache hit rate: $hitRate% ($cacheHits/$totalRequests)")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录缓存未命中
|
||||
*/
|
||||
fun recordCacheMiss(cacheType: String, key: String) {
|
||||
cacheMisses++
|
||||
totalRequests++
|
||||
|
||||
val metric = metrics.getOrPut("cache_$cacheType") {
|
||||
PerformanceMetric("cache_$cacheType")
|
||||
}
|
||||
metric.recordFailure()
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录内存使用情况
|
||||
*/
|
||||
fun recordMemoryUsage() {
|
||||
val runtime = Runtime.getRuntime()
|
||||
val usedMemory = runtime.totalMemory() - runtime.freeMemory()
|
||||
val maxMemory = runtime.maxMemory()
|
||||
val memoryUsagePercent = (usedMemory.toFloat() / maxMemory * 100).toInt()
|
||||
|
||||
memorySnapshots.add(MemorySnapshot(
|
||||
usedMemory = usedMemory,
|
||||
maxMemory = maxMemory,
|
||||
timestamp = System.currentTimeMillis()
|
||||
))
|
||||
|
||||
// 保持最近100个快照
|
||||
if (memorySnapshots.size > 100) {
|
||||
memorySnapshots.removeAt(0)
|
||||
}
|
||||
|
||||
Log.d(TAG, "🧠 Memory usage: $memoryUsagePercent% (${usedMemory / 1024 / 1024}MB/${maxMemory / 1024 / 1024}MB)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集性能数据
|
||||
*/
|
||||
private suspend fun collectPerformanceData() {
|
||||
recordMemoryUsage()
|
||||
|
||||
val currentData = PerformanceData(
|
||||
cacheHitRate = if (totalRequests > 0) cacheHits.toFloat() / totalRequests else 0f,
|
||||
averageLoadTime = calculateAverageLoadTime(),
|
||||
memoryUsagePercent = calculateMemoryUsagePercent(),
|
||||
totalOperations = totalRequests,
|
||||
activeMetrics = metrics.size,
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
|
||||
_performanceData.value = currentData
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录操作时间
|
||||
*/
|
||||
private fun recordOperationTime(operationName: String, executionTime: Long) {
|
||||
val metric = metrics.getOrPut(operationName) {
|
||||
PerformanceMetric(operationName)
|
||||
}
|
||||
|
||||
metric.recordExecution(executionTime)
|
||||
|
||||
if (executionTime > 1000) {
|
||||
Log.w(TAG, "⚠️ Slow operation: $operationName took ${executionTime}ms")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算平均加载时间
|
||||
*/
|
||||
private fun calculateAverageLoadTime(): Float {
|
||||
val recentLoads = loadingTimes.takeLast(10)
|
||||
return if (recentLoads.isNotEmpty()) {
|
||||
recentLoads.filter { it.success }.map { it.loadTime }.average().toFloat()
|
||||
} else 0f
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算内存使用百分比
|
||||
*/
|
||||
private fun calculateMemoryUsagePercent(): Float {
|
||||
val runtime = Runtime.getRuntime()
|
||||
val usedMemory = runtime.totalMemory() - runtime.freeMemory()
|
||||
val maxMemory = runtime.maxMemory()
|
||||
return usedMemory.toFloat() / maxMemory * 100
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成性能报告
|
||||
*/
|
||||
fun generatePerformanceReport(): PerformanceReport {
|
||||
val totalLoadTime = loadingTimes.sumOf { it.loadTime }
|
||||
val successfulLoads = loadingTimes.count { it.success }
|
||||
val failedLoads = loadingTimes.count { !it.success }
|
||||
|
||||
val topSlowOperations = metrics.values
|
||||
.sortedByDescending { it.averageTime }
|
||||
.take(5)
|
||||
.map { "${it.name}: ${it.averageTime}ms avg" }
|
||||
|
||||
val memoryPeak = memorySnapshots.maxByOrNull { it.usedMemory }
|
||||
|
||||
return PerformanceReport(
|
||||
totalOperations = totalRequests,
|
||||
cacheHitRate = if (totalRequests > 0) cacheHits.toFloat() / totalRequests else 0f,
|
||||
totalLoadTime = totalLoadTime,
|
||||
successfulLoads = successfulLoads,
|
||||
failedLoads = failedLoads,
|
||||
averageLoadTime = calculateAverageLoadTime(),
|
||||
peakMemoryUsage = memoryPeak?.usedMemory ?: 0L,
|
||||
topSlowOperations = topSlowOperations,
|
||||
monitoringDuration = System.currentTimeMillis() - (memorySnapshots.firstOrNull()?.timestamp ?: 0L)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成最终报告
|
||||
*/
|
||||
private fun generateFinalReport() {
|
||||
val report = generatePerformanceReport()
|
||||
|
||||
Log.i(TAG, """
|
||||
📊 === STORY ENGINE PERFORMANCE REPORT ===
|
||||
🔄 Total Operations: ${report.totalOperations}
|
||||
💾 Cache Hit Rate: ${"%.1f".format(report.cacheHitRate * 100)}%
|
||||
📦 Module Loads: ${report.successfulLoads} success, ${report.failedLoads} failed
|
||||
⏱️ Average Load Time: ${"%.1f".format(report.averageLoadTime)}ms
|
||||
🧠 Peak Memory: ${report.peakMemoryUsage / 1024 / 1024}MB
|
||||
🐌 Slow Operations:
|
||||
${report.topSlowOperations.joinToString("\n ")}
|
||||
⏰ Monitoring Duration: ${report.monitoringDuration / 1000}s
|
||||
=== END REPORT ===
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
fun cleanup() {
|
||||
stopMonitoring()
|
||||
monitoringScope.cancel()
|
||||
metrics.clear()
|
||||
loadingTimes.clear()
|
||||
memorySnapshots.clear()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 性能指标
|
||||
*/
|
||||
class PerformanceMetric(val name: String) {
|
||||
private val executionTimes = mutableListOf<Long>()
|
||||
private var successCount = 0
|
||||
private var failureCount = 0
|
||||
|
||||
val averageTime: Float
|
||||
get() = if (executionTimes.isNotEmpty()) {
|
||||
executionTimes.average().toFloat()
|
||||
} else 0f
|
||||
|
||||
val successRate: Float
|
||||
get() = if (totalCount > 0) {
|
||||
successCount.toFloat() / totalCount
|
||||
} else 0f
|
||||
|
||||
private val totalCount: Int
|
||||
get() = successCount + failureCount
|
||||
|
||||
fun recordExecution(timeMs: Long) {
|
||||
executionTimes.add(timeMs)
|
||||
// 保持最近50次记录
|
||||
if (executionTimes.size > 50) {
|
||||
executionTimes.removeAt(0)
|
||||
}
|
||||
}
|
||||
|
||||
fun recordSuccess() {
|
||||
successCount++
|
||||
}
|
||||
|
||||
fun recordFailure() {
|
||||
failureCount++
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载时间记录
|
||||
*/
|
||||
data class LoadingTimeRecord(
|
||||
val moduleName: String,
|
||||
val loadTime: Long,
|
||||
val timestamp: Long,
|
||||
val success: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
* 内存快照
|
||||
*/
|
||||
data class MemorySnapshot(
|
||||
val usedMemory: Long,
|
||||
val maxMemory: Long,
|
||||
val timestamp: Long
|
||||
)
|
||||
|
||||
/**
|
||||
* 实时性能数据
|
||||
*/
|
||||
data class PerformanceData(
|
||||
val cacheHitRate: Float = 0f,
|
||||
val averageLoadTime: Float = 0f,
|
||||
val memoryUsagePercent: Float = 0f,
|
||||
val totalOperations: Int = 0,
|
||||
val activeMetrics: Int = 0,
|
||||
val timestamp: Long = 0L
|
||||
)
|
||||
|
||||
/**
|
||||
* 性能报告
|
||||
*/
|
||||
data class PerformanceReport(
|
||||
val totalOperations: Int,
|
||||
val cacheHitRate: Float,
|
||||
val totalLoadTime: Long,
|
||||
val successfulLoads: Int,
|
||||
val failedLoads: Int,
|
||||
val averageLoadTime: Float,
|
||||
val peakMemoryUsage: Long,
|
||||
val topSlowOperations: List<String>,
|
||||
val monitoringDuration: Long
|
||||
)
|
||||
@@ -0,0 +1,663 @@
|
||||
package com.example.gameofmoon.story.migration
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.example.gameofmoon.story.CompleteStoryData
|
||||
import com.example.gameofmoon.story.engine.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
/**
|
||||
* 迁移执行器
|
||||
*
|
||||
* 负责执行完整的故事内容迁移,将CompleteStoryData中的所有内容
|
||||
* 转换为DSL格式并生成模块文件
|
||||
*/
|
||||
class MigrationExecutor(private val context: Context) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MigrationExecutor"
|
||||
private const val OUTPUT_DIR = "story_migration_output"
|
||||
}
|
||||
|
||||
private val migrationTool = StoryMigrationTool()
|
||||
private val documentExtractor = StoryDocumentExtractor()
|
||||
|
||||
/**
|
||||
* 执行完整迁移
|
||||
*/
|
||||
suspend fun executeFullMigration(): MigrationReport = withContext(Dispatchers.IO) {
|
||||
Log.i(TAG, "🚀 Starting full story migration...")
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
val report = MigrationReport()
|
||||
|
||||
try {
|
||||
// 步骤1:创建输出目录
|
||||
val outputDir = createOutputDirectory()
|
||||
Log.i(TAG, "📁 Created output directory: ${outputDir.absolutePath}")
|
||||
|
||||
// 步骤2:分析现有内容
|
||||
val analysisResult = analyzeExistingContent()
|
||||
report.totalNodes = analysisResult.totalNodes
|
||||
report.totalChoices = analysisResult.totalChoices
|
||||
Log.i(TAG, "📊 Content analysis: ${analysisResult.totalNodes} nodes, ${analysisResult.totalChoices} choices")
|
||||
|
||||
// 步骤3:按类型分组节点
|
||||
val nodeGroups = categorizeNodes(CompleteStoryData.getAllStoryNodes())
|
||||
Log.i(TAG, "🗂️ Categorized nodes into ${nodeGroups.size} groups")
|
||||
|
||||
// 步骤4:生成主要模块
|
||||
generateMainStoryModules(outputDir, nodeGroups, report)
|
||||
|
||||
// 步骤5:生成支线模块
|
||||
generateSideStoryModules(outputDir, nodeGroups, report)
|
||||
|
||||
// 步骤6:生成共享模块
|
||||
generateSharedModules(outputDir, report)
|
||||
|
||||
// 步骤7:生成配置文件
|
||||
generateConfigurationFiles(outputDir, report)
|
||||
|
||||
// 步骤8:验证生成的DSL文件
|
||||
validateGeneratedDSL(outputDir, report)
|
||||
|
||||
report.duration = System.currentTimeMillis() - startTime
|
||||
report.success = true
|
||||
|
||||
Log.i(TAG, "✅ Migration completed successfully in ${report.duration}ms")
|
||||
|
||||
} catch (e: Exception) {
|
||||
report.success = false
|
||||
report.error = e.message ?: "Unknown error"
|
||||
Log.e(TAG, "❌ Migration failed: ${e.message}", e)
|
||||
}
|
||||
|
||||
logMigrationReport(report)
|
||||
report
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建输出目录
|
||||
*/
|
||||
private fun createOutputDirectory(): File {
|
||||
val outputDir = File(context.getExternalFilesDir(null), OUTPUT_DIR)
|
||||
if (outputDir.exists()) {
|
||||
outputDir.deleteRecursively()
|
||||
}
|
||||
outputDir.mkdirs()
|
||||
|
||||
// 创建子目录结构
|
||||
File(outputDir, "modules").mkdirs()
|
||||
File(outputDir, "shared").mkdirs()
|
||||
File(outputDir, "config").mkdirs()
|
||||
File(outputDir, "validation").mkdirs()
|
||||
|
||||
return outputDir
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析现有内容
|
||||
*/
|
||||
private fun analyzeExistingContent(): ContentAnalysis {
|
||||
val allNodes = CompleteStoryData.getAllStoryNodes()
|
||||
val totalChoices = allNodes.values.sumOf { it.choices.size }
|
||||
|
||||
return ContentAnalysis(
|
||||
totalNodes = allNodes.size,
|
||||
totalChoices = totalChoices,
|
||||
mainStoryNodes = allNodes.filter { it.key.contains("awakening") || it.key.contains("eva") || it.key.contains("main") }.size,
|
||||
sideStoryNodes = allNodes.filter { it.key.contains("garden") || it.key.contains("photo") || it.key.contains("crew") }.size,
|
||||
endingNodes = allNodes.filter { it.key.contains("ending") || it.key.contains("destruction") || it.key.contains("truth") }.size
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按类型分组节点
|
||||
*/
|
||||
private fun categorizeNodes(allNodes: Map<String, com.example.gameofmoon.model.SimpleStoryNode>): Map<String, List<com.example.gameofmoon.model.SimpleStoryNode>> {
|
||||
return mapOf(
|
||||
"main_chapter_1" to allNodes.values.filter {
|
||||
it.id.contains("awakening") || it.id.contains("eva_first") || it.id.contains("medical") || it.id.contains("exploration")
|
||||
},
|
||||
"main_chapter_2" to allNodes.values.filter {
|
||||
it.id.contains("investigation") || it.id.contains("revelation") || it.id.contains("trust") || it.id.contains("memory")
|
||||
},
|
||||
"main_chapter_3" to allNodes.values.filter {
|
||||
it.id.contains("confrontation") || it.id.contains("truth") || it.id.contains("choice") || it.id.contains("climax")
|
||||
},
|
||||
"emotional_stories" to allNodes.values.filter {
|
||||
it.id.contains("comfort") || it.id.contains("sharing") || it.id.contains("identity") || it.id.contains("inner_strength")
|
||||
},
|
||||
"investigation_branch" to allNodes.values.filter {
|
||||
it.id.contains("stealth") || it.id.contains("eavesdrop") || it.id.contains("data") || it.id.contains("evidence")
|
||||
},
|
||||
"side_stories" to allNodes.values.filter {
|
||||
it.id.contains("garden") || it.id.contains("photo") || it.id.contains("crew_analysis") || it.id.contains("philosophical")
|
||||
},
|
||||
"endings" to allNodes.values.filter {
|
||||
it.id.contains("ending") || it.id.contains("destruction") || it.id.contains("eternal_loop") || it.id.contains("earth_truth")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主线故事模块
|
||||
*/
|
||||
private fun generateMainStoryModules(
|
||||
outputDir: File,
|
||||
nodeGroups: Map<String, List<com.example.gameofmoon.model.SimpleStoryNode>>,
|
||||
report: MigrationReport
|
||||
) {
|
||||
val mainChapters = listOf("main_chapter_1", "main_chapter_2", "main_chapter_3")
|
||||
|
||||
for (chapter in mainChapters) {
|
||||
val nodes = nodeGroups[chapter] ?: continue
|
||||
if (nodes.isEmpty()) continue
|
||||
|
||||
try {
|
||||
val dslContent = generateChapterDSL(chapter, nodes)
|
||||
val outputFile = File(File(outputDir, "modules"), "$chapter.story")
|
||||
outputFile.writeText(dslContent)
|
||||
|
||||
report.generatedFiles.add("modules/$chapter.story")
|
||||
report.processedNodes += nodes.size
|
||||
|
||||
Log.i(TAG, "📄 Generated $chapter.story with ${nodes.size} nodes")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to generate $chapter: ${e.message}")
|
||||
report.errors.add("Failed to generate $chapter: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支线故事模块
|
||||
*/
|
||||
private fun generateSideStoryModules(
|
||||
outputDir: File,
|
||||
nodeGroups: Map<String, List<com.example.gameofmoon.model.SimpleStoryNode>>,
|
||||
report: MigrationReport
|
||||
) {
|
||||
val sideModules = listOf("emotional_stories", "investigation_branch", "side_stories", "endings")
|
||||
|
||||
for (module in sideModules) {
|
||||
val nodes = nodeGroups[module] ?: continue
|
||||
if (nodes.isEmpty()) continue
|
||||
|
||||
try {
|
||||
val dslContent = generateModuleDSL(module, nodes)
|
||||
val outputFile = File(File(outputDir, "modules"), "$module.story")
|
||||
outputFile.writeText(dslContent)
|
||||
|
||||
report.generatedFiles.add("modules/$module.story")
|
||||
report.processedNodes += nodes.size
|
||||
|
||||
Log.i(TAG, "📄 Generated $module.story with ${nodes.size} nodes")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to generate $module: ${e.message}")
|
||||
report.errors.add("Failed to generate $module: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成章节DSL内容
|
||||
*/
|
||||
private fun generateChapterDSL(
|
||||
chapterName: String,
|
||||
nodes: List<com.example.gameofmoon.model.SimpleStoryNode>
|
||||
): String {
|
||||
val dslBuilder = StringBuilder()
|
||||
|
||||
// 模块头部
|
||||
dslBuilder.appendLine("@story_module $chapterName")
|
||||
dslBuilder.appendLine("@version 2.0")
|
||||
dslBuilder.appendLine("@dependencies [characters, audio_config, anchors]")
|
||||
dslBuilder.appendLine("@description \"${getChapterDescription(chapterName)}\"")
|
||||
dslBuilder.appendLine()
|
||||
|
||||
// 音频配置
|
||||
dslBuilder.appendLine("@audio")
|
||||
dslBuilder.appendLine(" background: ${getChapterAudio(chapterName)}")
|
||||
dslBuilder.appendLine(" transition: discovery_chime.mp3")
|
||||
dslBuilder.appendLine("@end")
|
||||
dslBuilder.appendLine()
|
||||
|
||||
// 生成所有节点
|
||||
for (node in nodes) {
|
||||
dslBuilder.append(convertNodeToDSL(node))
|
||||
dslBuilder.appendLine()
|
||||
}
|
||||
|
||||
return dslBuilder.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成模块DSL内容
|
||||
*/
|
||||
private fun generateModuleDSL(
|
||||
moduleName: String,
|
||||
nodes: List<com.example.gameofmoon.model.SimpleStoryNode>
|
||||
): String {
|
||||
val dslBuilder = StringBuilder()
|
||||
|
||||
// 模块头部
|
||||
dslBuilder.appendLine("@story_module $moduleName")
|
||||
dslBuilder.appendLine("@version 2.0")
|
||||
dslBuilder.appendLine("@dependencies [characters, audio_config, anchors]")
|
||||
dslBuilder.appendLine("@description \"${getModuleDescription(moduleName)}\"")
|
||||
dslBuilder.appendLine()
|
||||
|
||||
// 生成所有节点
|
||||
for (node in nodes) {
|
||||
dslBuilder.append(convertNodeToDSL(node))
|
||||
dslBuilder.appendLine()
|
||||
}
|
||||
|
||||
return dslBuilder.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换单个节点为DSL
|
||||
*/
|
||||
private fun convertNodeToDSL(node: com.example.gameofmoon.model.SimpleStoryNode): String {
|
||||
val dslBuilder = StringBuilder()
|
||||
|
||||
dslBuilder.appendLine("@node ${node.id}")
|
||||
dslBuilder.appendLine("@title \"${node.title}\"")
|
||||
|
||||
// 音频配置(如果需要)
|
||||
val audioConfig = getNodeAudioConfig(node.id)
|
||||
if (audioConfig.isNotEmpty()) {
|
||||
dslBuilder.appendLine("@audio_bg $audioConfig")
|
||||
}
|
||||
|
||||
// 内容
|
||||
dslBuilder.appendLine("@content \"\"\"")
|
||||
dslBuilder.appendLine(node.content.trim())
|
||||
dslBuilder.appendLine("\"\"\"")
|
||||
dslBuilder.appendLine()
|
||||
|
||||
// 选择
|
||||
if (node.choices.isNotEmpty()) {
|
||||
dslBuilder.appendLine("@choices ${node.choices.size}")
|
||||
for ((index, choice) in node.choices.withIndex()) {
|
||||
val choiceBuilder = StringBuilder()
|
||||
choiceBuilder.append(" choice_${index + 1}: \"${choice.text}\" -> ${choice.nextNodeId}")
|
||||
|
||||
// 效果
|
||||
if (choice.effects.isNotEmpty()) {
|
||||
val effectStrings = choice.effects.map { effect ->
|
||||
when (effect.type) {
|
||||
com.example.gameofmoon.model.SimpleEffectType.HEALTH_CHANGE -> "health${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.STAMINA_CHANGE -> "stamina${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.SECRET_UNLOCK -> "secret_${effect.value}"
|
||||
else -> "${effect.type.name.lowercase()}_${effect.value}"
|
||||
}
|
||||
}
|
||||
choiceBuilder.append(" [effect: ${effectStrings.joinToString(", ")}]")
|
||||
}
|
||||
|
||||
// 要求
|
||||
if (choice.requirements.isNotEmpty()) {
|
||||
val reqStrings = choice.requirements.map { req ->
|
||||
when (req.type) {
|
||||
com.example.gameofmoon.model.SimpleRequirementType.MIN_STAMINA -> "stamina >= ${req.value}"
|
||||
com.example.gameofmoon.model.SimpleRequirementType.MIN_HEALTH -> "health >= ${req.value}"
|
||||
else -> "${req.type.name.lowercase()}_${req.value}"
|
||||
}
|
||||
}
|
||||
choiceBuilder.append(" [require: ${reqStrings.joinToString(" AND ")}]")
|
||||
}
|
||||
|
||||
// 音效
|
||||
choiceBuilder.append(" [audio: button_click.mp3]")
|
||||
|
||||
dslBuilder.appendLine(choiceBuilder.toString())
|
||||
}
|
||||
dslBuilder.appendLine("@end")
|
||||
}
|
||||
|
||||
return dslBuilder.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成共享模块
|
||||
*/
|
||||
private fun generateSharedModules(outputDir: File, report: MigrationReport) {
|
||||
// 这些文件已经存在于assets中,我们复制并完善它们
|
||||
val sharedFiles = listOf("characters.story", "audio.story", "anchors.story")
|
||||
|
||||
for (fileName in sharedFiles) {
|
||||
try {
|
||||
val sourceFile = File(context.assets.list("story/shared")?.let {
|
||||
if (fileName in it) "story/shared/$fileName" else null
|
||||
} ?: continue)
|
||||
|
||||
val targetFile = File(File(outputDir, "shared"), fileName)
|
||||
// 如果assets中有文件,我们增强它;否则创建新的
|
||||
val content = enhanceSharedModule(fileName)
|
||||
targetFile.writeText(content)
|
||||
|
||||
report.generatedFiles.add("shared/$fileName")
|
||||
Log.i(TAG, "📄 Generated enhanced shared/$fileName")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to generate shared/$fileName: ${e.message}")
|
||||
report.errors.add("Failed to generate shared/$fileName: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成配置文件
|
||||
*/
|
||||
private fun generateConfigurationFiles(outputDir: File, report: MigrationReport) {
|
||||
try {
|
||||
// 生成主配置文件
|
||||
val configContent = generateMainConfig()
|
||||
File(File(outputDir, "config"), "config.json").writeText(configContent)
|
||||
|
||||
// 生成模块索引
|
||||
val indexContent = generateModuleIndex(report.generatedFiles)
|
||||
File(File(outputDir, "config"), "modules.json").writeText(indexContent)
|
||||
|
||||
report.generatedFiles.add("config/config.json")
|
||||
report.generatedFiles.add("config/modules.json")
|
||||
|
||||
Log.i(TAG, "📄 Generated configuration files")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to generate config files: ${e.message}")
|
||||
report.errors.add("Failed to generate config files: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证生成的DSL文件
|
||||
*/
|
||||
private suspend fun validateGeneratedDSL(outputDir: File, report: MigrationReport) {
|
||||
val parser = StoryDSLParser()
|
||||
val modulesDir = File(outputDir, "modules")
|
||||
|
||||
for (moduleFile in modulesDir.listFiles() ?: emptyArray()) {
|
||||
if (!moduleFile.name.endsWith(".story")) continue
|
||||
|
||||
try {
|
||||
val content = moduleFile.readText()
|
||||
when (val result = parser.parseContent(content)) {
|
||||
is ParseResult.Success -> {
|
||||
val module = result.data
|
||||
report.validatedNodes += module.nodes.size
|
||||
Log.i(TAG, "✅ Validated ${moduleFile.name}: ${module.nodes.size} nodes")
|
||||
}
|
||||
is ParseResult.Error -> {
|
||||
report.errors.add("Validation failed for ${moduleFile.name}: ${result.message}")
|
||||
Log.e(TAG, "❌ Validation failed for ${moduleFile.name}: ${result.message}")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
report.errors.add("Exception validating ${moduleFile.name}: ${e.message}")
|
||||
Log.e(TAG, "Exception validating ${moduleFile.name}: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 辅助方法
|
||||
// ========================================================================
|
||||
|
||||
private fun getChapterDescription(chapterName: String): String = when (chapterName) {
|
||||
"main_chapter_1" -> "第一章:觉醒 - 主角从昏迷中醒来,开始探索月球基地的秘密"
|
||||
"main_chapter_2" -> "第二章:调查 - 深入基地,发现时间锚项目的真相"
|
||||
"main_chapter_3" -> "第三章:抉择 - 面对真相,做出最终的选择"
|
||||
else -> "故事模块:$chapterName"
|
||||
}
|
||||
|
||||
private fun getChapterAudio(chapterName: String): String = when (chapterName) {
|
||||
"main_chapter_1" -> "ambient_mystery.mp3"
|
||||
"main_chapter_2" -> "electronic_tension.mp3"
|
||||
"main_chapter_3" -> "orchestral_revelation.mp3"
|
||||
else -> "ambient_mystery.mp3"
|
||||
}
|
||||
|
||||
private fun getModuleDescription(moduleName: String): String = when (moduleName) {
|
||||
"emotional_stories" -> "情感故事模块 - 探索角色间的情感联系和内心成长"
|
||||
"investigation_branch" -> "调查分支模块 - 深度调查和证据收集的故事线"
|
||||
"side_stories" -> "支线故事模块 - 花园、照片记忆等支线剧情"
|
||||
"endings" -> "结局模块 - 所有可能的故事结局和终章"
|
||||
else -> "故事模块:$moduleName"
|
||||
}
|
||||
|
||||
private fun getNodeAudioConfig(nodeId: String): String = when {
|
||||
nodeId.contains("revelation") || nodeId.contains("truth") -> "orchestral_revelation.mp3"
|
||||
nodeId.contains("tension") || nodeId.contains("confrontation") -> "electronic_tension.mp3"
|
||||
nodeId.contains("garden") || nodeId.contains("peaceful") -> "space_silence.mp3"
|
||||
nodeId.contains("discovery") -> "discovery_chime.mp3"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
private fun enhanceSharedModule(fileName: String): String {
|
||||
// 这里我们返回增强版的共享模块内容
|
||||
// 实际实现中,我们会读取assets中的现有文件并增强
|
||||
return when (fileName) {
|
||||
"characters.story" -> generateEnhancedCharacters()
|
||||
"audio.story" -> generateEnhancedAudio()
|
||||
"anchors.story" -> generateEnhancedAnchors()
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateMainConfig(): String {
|
||||
return """
|
||||
{
|
||||
"version": "2.0",
|
||||
"engine": "DSL Story Engine",
|
||||
"default_language": "zh",
|
||||
"modules": [
|
||||
"characters",
|
||||
"audio_config",
|
||||
"anchors",
|
||||
"main_chapter_1",
|
||||
"main_chapter_2",
|
||||
"main_chapter_3",
|
||||
"emotional_stories",
|
||||
"investigation_branch",
|
||||
"side_stories",
|
||||
"endings"
|
||||
],
|
||||
"audio": {
|
||||
"enabled": true,
|
||||
"default_volume": 0.7,
|
||||
"fade_duration": 1000,
|
||||
"background_loop": true
|
||||
},
|
||||
"gameplay": {
|
||||
"auto_save": true,
|
||||
"choice_timeout": 0,
|
||||
"skip_seen_content": false,
|
||||
"enable_branching": true
|
||||
},
|
||||
"features": {
|
||||
"conditional_navigation": true,
|
||||
"dynamic_anchors": true,
|
||||
"memory_management": true,
|
||||
"effects_system": true
|
||||
},
|
||||
"start_node": "first_awakening"
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private fun generateModuleIndex(generatedFiles: List<String>): String {
|
||||
val modules = generatedFiles.filter { it.startsWith("modules/") }
|
||||
.map { it.substringAfter("modules/").substringBefore(".story") }
|
||||
|
||||
return """
|
||||
{
|
||||
"modules": [
|
||||
${modules.joinToString(",\n ") { "\"$it\"" }}
|
||||
],
|
||||
"total_modules": ${modules.size},
|
||||
"generated_at": "${System.currentTimeMillis()}",
|
||||
"format_version": "2.0"
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private fun generateEnhancedCharacters(): String {
|
||||
// 返回增强版的角色定义
|
||||
return """
|
||||
@story_module characters
|
||||
@version 2.0
|
||||
@description "角色定义模块 - 定义所有游戏角色的属性和特征"
|
||||
|
||||
@character eva
|
||||
name: "伊娃 / EVA"
|
||||
voice_style: gentle
|
||||
description: "基地AI系统,实际上是莉莉的意识转移,温柔而智慧"
|
||||
relationship: "妹妹"
|
||||
personality: "关爱、智慧、略带忧郁"
|
||||
key_traits: ["protective", "intelligent", "emotional"]
|
||||
@end
|
||||
|
||||
@character alex
|
||||
name: "艾利克丝·陈"
|
||||
voice_style: determined
|
||||
description: "月球基地工程师,坚强而富有同情心的主角"
|
||||
relationship: "自己"
|
||||
personality: "坚毅、善良、追求真相"
|
||||
key_traits: ["brave", "empathetic", "curious"]
|
||||
@end
|
||||
|
||||
@character sara
|
||||
name: "萨拉·维特博士"
|
||||
voice_style: professional
|
||||
description: "基地医生,负责心理健康,内心善良但被迫参与实验"
|
||||
relationship: "同事"
|
||||
personality: "专业、内疚、渴望救赎"
|
||||
key_traits: ["caring", "conflicted", "knowledgeable"]
|
||||
@end
|
||||
|
||||
@character dmitri
|
||||
name: "德米特里·彼得罗夫博士"
|
||||
voice_style: serious
|
||||
description: "时间锚项目负责人,科学家,道德复杂"
|
||||
relationship: "上级"
|
||||
personality: "理性、冷酷、但有人性的一面"
|
||||
key_traits: ["logical", "ambitious", "tormented"]
|
||||
@end
|
||||
|
||||
@character marcus
|
||||
name: "马库斯·雷诺兹"
|
||||
voice_style: calm
|
||||
description: "基地安全官,前军人,正义感强烈"
|
||||
relationship: "盟友"
|
||||
personality: "忠诚、正义、保护欲强"
|
||||
key_traits: ["loyal", "protective", "experienced"]
|
||||
@end
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private fun generateEnhancedAudio(): String {
|
||||
return """
|
||||
@story_module audio_config
|
||||
@version 2.0
|
||||
@description "音频配置模块 - 定义所有游戏音频资源"
|
||||
|
||||
@audio
|
||||
// ===== 背景音乐 =====
|
||||
mysterious: ambient_mystery.mp3
|
||||
tension: electronic_tension.mp3
|
||||
peaceful: space_silence.mp3
|
||||
revelation: orchestral_revelation.mp3
|
||||
finale: epic_finale.mp3
|
||||
discovery: discovery_chime.mp3
|
||||
|
||||
// ===== 环境音效 =====
|
||||
base_ambient: reactor_hum.mp3
|
||||
ventilation: ventilation_soft.mp3
|
||||
storm: solar_storm.mp3
|
||||
heartbeat: heart_monitor.mp3
|
||||
time_warp: time_distortion.mp3
|
||||
|
||||
// ===== 交互音效 =====
|
||||
button_click: button_click.mp3
|
||||
notification: notification_beep.mp3
|
||||
discovery_sound: discovery_chime.mp3
|
||||
alert: error_alert.mp3
|
||||
success: notification_beep.mp3
|
||||
@end
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private fun generateEnhancedAnchors(): String {
|
||||
return """
|
||||
@story_module anchors
|
||||
@version 2.0
|
||||
@description "锚点系统 - 定义动态故事导航的智能锚点"
|
||||
|
||||
@anchor_conditions
|
||||
// ===== 关键剧情解锁条件 =====
|
||||
eva_reveal_ready: secrets_found >= 3 AND trust_level >= 5
|
||||
investigation_unlocked: harrison_recording_found == true
|
||||
deep_truth_ready: eva_reveal_ready == true AND investigation_unlocked == true
|
||||
perfect_ending_available: secrets_found >= 15 AND health > 50
|
||||
|
||||
// ===== 结局分支条件 =====
|
||||
freedom_ending_ready: anchor_destruction_chosen == true
|
||||
loop_ending_ready: eternal_loop_chosen == true
|
||||
truth_ending_ready: earth_truth_revealed == true
|
||||
|
||||
// ===== 情感状态条件 =====
|
||||
emotional_stability: health > 70 AND trust_level > 8
|
||||
sister_bond_strong: eva_interactions >= 10
|
||||
@end
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private fun logMigrationReport(report: MigrationReport) {
|
||||
Log.i(TAG, """
|
||||
📊 === MIGRATION REPORT ===
|
||||
✅ Success: ${report.success}
|
||||
📊 Total Nodes: ${report.totalNodes}
|
||||
✅ Processed: ${report.processedNodes}
|
||||
🔍 Validated: ${report.validatedNodes}
|
||||
📄 Generated Files: ${report.generatedFiles.size}
|
||||
❌ Errors: ${report.errors.size}
|
||||
⏱️ Duration: ${report.duration}ms
|
||||
|
||||
📁 Generated Files:
|
||||
${report.generatedFiles.joinToString("\n ")}
|
||||
|
||||
${if (report.errors.isNotEmpty()) {
|
||||
"❌ Errors:\n ${report.errors.joinToString("\n ")}"
|
||||
} else ""}
|
||||
=== END REPORT ===
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类
|
||||
// ============================================================================
|
||||
|
||||
data class MigrationReport(
|
||||
var success: Boolean = false,
|
||||
var totalNodes: Int = 0,
|
||||
var processedNodes: Int = 0,
|
||||
var validatedNodes: Int = 0,
|
||||
var totalChoices: Int = 0,
|
||||
var generatedFiles: MutableList<String> = mutableListOf(),
|
||||
var errors: MutableList<String> = mutableListOf(),
|
||||
var duration: Long = 0,
|
||||
var error: String? = null
|
||||
)
|
||||
|
||||
data class ContentAnalysis(
|
||||
val totalNodes: Int,
|
||||
val totalChoices: Int,
|
||||
val mainStoryNodes: Int,
|
||||
val sideStoryNodes: Int,
|
||||
val endingNodes: Int
|
||||
)
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.example.gameofmoon.story.migration
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* 故事迁移执行器
|
||||
* 统一执行整个迁移流程,将现有内容转换为DSL格式
|
||||
*/
|
||||
class MigrationRunner {
|
||||
|
||||
companion object {
|
||||
private const val PROJECT_ROOT = "/Users/maxliu/Documents/GameOfMoon"
|
||||
private const val STORY_DOCS_PATH = "$PROJECT_ROOT/Story"
|
||||
private const val ASSETS_OUTPUT_PATH = "$PROJECT_ROOT/app/src/main/assets/story"
|
||||
private const val EXTRACTED_OUTPUT_PATH = "$PROJECT_ROOT/extracted_story"
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行完整的迁移流程
|
||||
*/
|
||||
fun runFullMigration() {
|
||||
println("🚀 Starting full story migration process...")
|
||||
println("Project root: $PROJECT_ROOT")
|
||||
println("Story docs: $STORY_DOCS_PATH")
|
||||
println("Output path: $ASSETS_OUTPUT_PATH")
|
||||
println()
|
||||
|
||||
try {
|
||||
// Phase 2.1: 从现有代码中提取故事数据
|
||||
migrateFromExistingCode()
|
||||
|
||||
// Phase 2.2: 从Story文档中提取内容
|
||||
extractFromStoryDocuments()
|
||||
|
||||
// Phase 2.3: 合并和优化内容
|
||||
mergeAndOptimizeContent()
|
||||
|
||||
// Phase 2.4: 验证迁移结果
|
||||
validateMigrationResults()
|
||||
|
||||
println("✅ Full migration completed successfully!")
|
||||
|
||||
} catch (e: Exception) {
|
||||
println("❌ Migration failed: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2.1: 从现有代码迁移
|
||||
*/
|
||||
private fun migrateFromExistingCode() {
|
||||
println("📦 Phase 2.1: Migrating from existing code...")
|
||||
|
||||
val migrationTool = StoryMigrationTool()
|
||||
migrationTool.migrateAll(PROJECT_ROOT)
|
||||
|
||||
println("✅ Code migration completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2.2: 从Story文档提取
|
||||
*/
|
||||
private fun extractFromStoryDocuments() {
|
||||
println("📚 Phase 2.2: Extracting from story documents...")
|
||||
|
||||
val extractor = StoryDocumentExtractor()
|
||||
extractor.extractAllDocuments(STORY_DOCS_PATH, EXTRACTED_OUTPUT_PATH)
|
||||
|
||||
println("✅ Document extraction completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2.3: 合并和优化内容
|
||||
*/
|
||||
private fun mergeAndOptimizeContent() {
|
||||
println("🔄 Phase 2.3: Merging and optimizing content...")
|
||||
|
||||
val merger = ContentMerger()
|
||||
merger.mergeContent(ASSETS_OUTPUT_PATH, EXTRACTED_OUTPUT_PATH)
|
||||
|
||||
println("✅ Content merging completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2.4: 验证迁移结果
|
||||
*/
|
||||
private fun validateMigrationResults() {
|
||||
println("🔍 Phase 2.4: Validating migration results...")
|
||||
|
||||
val validator = MigrationValidator()
|
||||
val results = validator.validateMigration(ASSETS_OUTPUT_PATH)
|
||||
|
||||
println("Validation results:")
|
||||
println(" - Files created: ${results.filesCreated}")
|
||||
println(" - Nodes migrated: ${results.nodesMigrated}")
|
||||
println(" - Errors found: ${results.errors.size}")
|
||||
|
||||
if (results.errors.isNotEmpty()) {
|
||||
println("⚠️ Validation errors:")
|
||||
results.errors.forEach { println(" - $it") }
|
||||
}
|
||||
|
||||
println("✅ Validation completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅执行代码迁移(用于测试)
|
||||
*/
|
||||
fun runCodeMigrationOnly() {
|
||||
println("🔧 Running code migration only...")
|
||||
migrateFromExistingCode()
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅执行文档提取(用于测试)
|
||||
*/
|
||||
fun runDocumentExtractionOnly() {
|
||||
println("📖 Running document extraction only...")
|
||||
extractFromStoryDocuments()
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理迁移输出(用于重新开始)
|
||||
*/
|
||||
fun cleanMigrationOutput() {
|
||||
println("🧹 Cleaning migration output...")
|
||||
|
||||
listOf(ASSETS_OUTPUT_PATH, EXTRACTED_OUTPUT_PATH).forEach { path ->
|
||||
val dir = File(path)
|
||||
if (dir.exists()) {
|
||||
dir.deleteRecursively()
|
||||
println(" - Cleaned: $path")
|
||||
}
|
||||
}
|
||||
|
||||
println("✅ Cleanup completed")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容合并器
|
||||
*/
|
||||
class ContentMerger {
|
||||
|
||||
fun mergeContent(assetsPath: String, extractedPath: String) {
|
||||
// 实现内容合并逻辑
|
||||
// 优先使用代码中的内容,用文档内容补充
|
||||
println(" - Merging code content with document content...")
|
||||
|
||||
val assetsDir = File(assetsPath)
|
||||
val extractedDir = File(extractedPath)
|
||||
|
||||
if (!assetsDir.exists() || !extractedDir.exists()) {
|
||||
println(" Warning: Source directories not found")
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: 实现具体的合并逻辑
|
||||
// 1. 比较两个源的节点
|
||||
// 2. 合并选择和效果
|
||||
// 3. 优化内容结构
|
||||
// 4. 生成最终的DSL文件
|
||||
|
||||
println(" - Content merging completed")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移验证器
|
||||
*/
|
||||
class MigrationValidator {
|
||||
|
||||
fun validateMigration(outputPath: String): ValidationResults {
|
||||
val results = ValidationResults()
|
||||
val outputDir = File(outputPath)
|
||||
|
||||
if (!outputDir.exists()) {
|
||||
results.errors.add("Output directory does not exist: $outputPath")
|
||||
return results
|
||||
}
|
||||
|
||||
// 统计生成的文件
|
||||
val storyFiles = outputDir.walkTopDown()
|
||||
.filter { it.isFile && it.name.endsWith(".story") }
|
||||
.toList()
|
||||
|
||||
results.filesCreated = storyFiles.size
|
||||
|
||||
// 验证每个文件
|
||||
for (file in storyFiles) {
|
||||
try {
|
||||
validateStoryFile(file, results)
|
||||
} catch (e: Exception) {
|
||||
results.errors.add("Failed to validate ${file.name}: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
private fun validateStoryFile(file: File, results: ValidationResults) {
|
||||
val content = file.readText()
|
||||
|
||||
// 检查基本DSL结构
|
||||
if (!content.contains("@story_module")) {
|
||||
results.errors.add("${file.name}: Missing @story_module declaration")
|
||||
}
|
||||
|
||||
if (!content.contains("@version")) {
|
||||
results.errors.add("${file.name}: Missing @version declaration")
|
||||
}
|
||||
|
||||
// 统计节点数量
|
||||
val nodeCount = content.split("@node ").size - 1
|
||||
results.nodesMigrated += nodeCount
|
||||
|
||||
// 检查节点完整性
|
||||
val nodes = content.split("@node ").drop(1)
|
||||
for ((index, node) in nodes.withIndex()) {
|
||||
if (!node.contains("@title")) {
|
||||
results.errors.add("${file.name}: Node ${index + 1} missing @title")
|
||||
}
|
||||
if (!node.contains("@content")) {
|
||||
results.errors.add("${file.name}: Node ${index + 1} missing @content")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证结果
|
||||
*/
|
||||
data class ValidationResults(
|
||||
var filesCreated: Int = 0,
|
||||
var nodesMigrated: Int = 0,
|
||||
val errors: MutableList<String> = mutableListOf()
|
||||
)
|
||||
|
||||
/**
|
||||
* 主函数 - 用于测试迁移流程
|
||||
*/
|
||||
fun main() {
|
||||
val runner = MigrationRunner()
|
||||
|
||||
// 清理之前的输出
|
||||
// runner.cleanMigrationOutput()
|
||||
|
||||
// 执行完整迁移
|
||||
runner.runFullMigration()
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
package com.example.gameofmoon.story.migration
|
||||
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* 故事文档提取器
|
||||
* 从Story文件夹的.md文件中提取故事内容并转换为DSL格式
|
||||
*/
|
||||
class StoryDocumentExtractor {
|
||||
|
||||
companion object {
|
||||
// 匹配节点标题的正则模式
|
||||
private val NODE_TITLE_PATTERN = Pattern.compile("###?\\s*\\*\\*节点\\d+:?\\s*([^*]+)\\*\\*[^\\n]*")
|
||||
private val SECTION_TITLE_PATTERN = Pattern.compile("###?\\s*\\*\\*([^*]+)\\*\\*")
|
||||
private val CODE_BLOCK_PATTERN = Pattern.compile("```([\\s\\S]*?)```")
|
||||
private val DIALOGUE_PATTERN = Pattern.compile("\"([^\"]+)\"")
|
||||
private val CHOICE_PATTERN = Pattern.compile("\\*\\*选择\\d+\\*\\*:?\\s*([^\\n]+)")
|
||||
private val EFFECT_PATTERN = Pattern.compile("\\[([^\\]]+)\\]")
|
||||
|
||||
// 匹配四阶段结构
|
||||
private val PHASE_PATTERN = Pattern.compile("###?\\s*\\*\\*第([一二三四])阶段[::]([^*]+)\\*\\*")
|
||||
|
||||
// 匹配角色对话
|
||||
private val CHARACTER_DIALOGUE_PATTERN = Pattern.compile("([伊娃|艾利克丝|萨拉|德米特里|马库斯|哈里森])[::]\\s*\"([^\"]+)\"")
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取所有故事文档
|
||||
*/
|
||||
fun extractAllDocuments(storyPath: String, outputPath: String) {
|
||||
println("📚 Starting story document extraction...")
|
||||
|
||||
val storyDir = File(storyPath)
|
||||
if (!storyDir.exists() || !storyDir.isDirectory) {
|
||||
println("❌ Story directory not found: $storyPath")
|
||||
return
|
||||
}
|
||||
|
||||
val mdFiles = storyDir.listFiles { file -> file.name.endsWith(".md") }
|
||||
if (mdFiles.isNullOrEmpty()) {
|
||||
println("❌ No .md files found in story directory")
|
||||
return
|
||||
}
|
||||
|
||||
println("Found ${mdFiles.size} markdown files:")
|
||||
mdFiles.forEach { println(" - ${it.name}") }
|
||||
|
||||
// 处理各种类型的文档
|
||||
val extractedContent = mutableMapOf<String, ExtractedStoryData>()
|
||||
|
||||
for (file in mdFiles) {
|
||||
when {
|
||||
file.name.contains("MainNodes") -> {
|
||||
extractedContent["main_nodes"] = extractMainNodes(file)
|
||||
}
|
||||
file.name.contains("AllSidelines") -> {
|
||||
extractedContent["side_stories"] = extractSideStories(file)
|
||||
}
|
||||
file.name.contains("BridgeNodes") -> {
|
||||
extractedContent["bridge_nodes"] = extractBridgeNodes(file)
|
||||
}
|
||||
file.name.contains("DialogueSystem") -> {
|
||||
extractedContent["dialogue_system"] = extractDialogueSystem(file)
|
||||
}
|
||||
file.name.contains("MoralSystem") -> {
|
||||
extractedContent["moral_system"] = extractMoralSystem(file)
|
||||
}
|
||||
file.name.contains("CoreDesign") -> {
|
||||
extractedContent["core_design"] = extractCoreDesign(file)
|
||||
}
|
||||
file.name.contains("StoryIndex") -> {
|
||||
extractedContent["story_index"] = extractStoryIndex(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成DSL文件
|
||||
generateDSLFiles(extractedContent, outputPath)
|
||||
|
||||
println("✅ Story document extraction completed")
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取主线节点
|
||||
*/
|
||||
private fun extractMainNodes(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
val nodes = mutableListOf<ExtractedNode>()
|
||||
|
||||
// 查找所有节点
|
||||
val nodeMatcher = NODE_TITLE_PATTERN.matcher(content)
|
||||
var lastEnd = 0
|
||||
|
||||
while (nodeMatcher.find()) {
|
||||
if (lastEnd > 0) {
|
||||
// 处理上一个节点的内容
|
||||
val nodeContent = content.substring(lastEnd, nodeMatcher.start())
|
||||
nodes.lastOrNull()?.content = cleanNodeContent(nodeContent)
|
||||
}
|
||||
|
||||
val nodeTitle = nodeMatcher.group(1).trim()
|
||||
val nodeId = generateNodeId(nodeTitle)
|
||||
|
||||
nodes.add(ExtractedNode(
|
||||
id = nodeId,
|
||||
title = nodeTitle,
|
||||
content = "",
|
||||
type = "main",
|
||||
choices = mutableListOf(),
|
||||
metadata = extractNodeMetadata(nodeTitle)
|
||||
))
|
||||
|
||||
lastEnd = nodeMatcher.end()
|
||||
}
|
||||
|
||||
// 处理最后一个节点
|
||||
if (nodes.isNotEmpty() && lastEnd < content.length) {
|
||||
nodes.last().content = cleanNodeContent(content.substring(lastEnd))
|
||||
}
|
||||
|
||||
// 为每个节点提取选择
|
||||
for (node in nodes) {
|
||||
node.choices.addAll(extractChoicesFromContent(node.content))
|
||||
}
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "main_story",
|
||||
title = "主线故事",
|
||||
nodes = nodes,
|
||||
metadata = mapOf("source" to file.name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取支线故事
|
||||
*/
|
||||
private fun extractSideStories(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
val nodes = mutableListOf<ExtractedNode>()
|
||||
|
||||
// 支线故事通常有不同的结构,需要特殊处理
|
||||
val sections = content.split("---").filter { it.trim().isNotEmpty() }
|
||||
|
||||
for (section in sections) {
|
||||
val sectionNodes = extractNodesFromSection(section, "side")
|
||||
nodes.addAll(sectionNodes)
|
||||
}
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "side_stories",
|
||||
title = "支线故事",
|
||||
nodes = nodes,
|
||||
metadata = mapOf("source" to file.name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取桥接节点
|
||||
*/
|
||||
private fun extractBridgeNodes(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
val nodes = extractNodesFromSection(content, "bridge")
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "bridge_nodes",
|
||||
title = "桥接节点",
|
||||
nodes = nodes,
|
||||
metadata = mapOf("source" to file.name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取对话系统
|
||||
*/
|
||||
private fun extractDialogueSystem(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
val nodes = mutableListOf<ExtractedNode>()
|
||||
|
||||
// 查找对话样例
|
||||
val dialogues = extractDialogueExamples(content)
|
||||
|
||||
for ((index, dialogue) in dialogues.withIndex()) {
|
||||
nodes.add(ExtractedNode(
|
||||
id = "dialogue_example_${index + 1}",
|
||||
title = dialogue.title,
|
||||
content = dialogue.content,
|
||||
type = "dialogue",
|
||||
choices = dialogue.choices,
|
||||
metadata = mapOf("characters" to dialogue.characters)
|
||||
))
|
||||
}
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "dialogue_system",
|
||||
title = "对话系统",
|
||||
nodes = nodes,
|
||||
metadata = mapOf("source" to file.name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取道德系统
|
||||
*/
|
||||
private fun extractMoralSystem(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "moral_system",
|
||||
title = "道德系统",
|
||||
nodes = emptyList(),
|
||||
metadata = mapOf(
|
||||
"source" to file.name,
|
||||
"moral_principles" to extractMoralPrinciples(content)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取核心设计
|
||||
*/
|
||||
private fun extractCoreDesign(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "core_design",
|
||||
title = "核心设计",
|
||||
nodes = emptyList(),
|
||||
metadata = mapOf(
|
||||
"source" to file.name,
|
||||
"design_principles" to extractDesignPrinciples(content)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取故事索引
|
||||
*/
|
||||
private fun extractStoryIndex(file: File): ExtractedStoryData {
|
||||
val content = file.readText()
|
||||
|
||||
return ExtractedStoryData(
|
||||
type = "story_index",
|
||||
title = "故事索引",
|
||||
nodes = emptyList(),
|
||||
metadata = mapOf(
|
||||
"source" to file.name,
|
||||
"story_structure" to extractStoryStructure(content)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 从章节中提取节点
|
||||
*/
|
||||
private fun extractNodesFromSection(section: String, nodeType: String): List<ExtractedNode> {
|
||||
val nodes = mutableListOf<ExtractedNode>()
|
||||
|
||||
// 查找代码块中的内容
|
||||
val codeBlocks = extractCodeBlocks(section)
|
||||
|
||||
for ((index, codeBlock) in codeBlocks.withIndex()) {
|
||||
val title = extractTitleFromCodeBlock(codeBlock) ?: "未知节点 ${index + 1}"
|
||||
val nodeId = generateNodeId(title)
|
||||
|
||||
nodes.add(ExtractedNode(
|
||||
id = nodeId,
|
||||
title = title,
|
||||
content = cleanNodeContent(codeBlock),
|
||||
type = nodeType,
|
||||
choices = extractChoicesFromContent(codeBlock),
|
||||
metadata = mapOf("order" to index)
|
||||
))
|
||||
}
|
||||
|
||||
return nodes
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取代码块
|
||||
*/
|
||||
private fun extractCodeBlocks(content: String): List<String> {
|
||||
val blocks = mutableListOf<String>()
|
||||
val matcher = CODE_BLOCK_PATTERN.matcher(content)
|
||||
|
||||
while (matcher.find()) {
|
||||
blocks.add(matcher.group(1))
|
||||
}
|
||||
|
||||
return blocks
|
||||
}
|
||||
|
||||
/**
|
||||
* 从代码块中提取标题
|
||||
*/
|
||||
private fun extractTitleFromCodeBlock(codeBlock: String): String? {
|
||||
val lines = codeBlock.lines()
|
||||
for (line in lines.take(5)) { // 只看前5行
|
||||
if (line.trim().isNotEmpty() && !line.startsWith("//")) {
|
||||
return line.trim().take(50) // 限制标题长度
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理节点内容
|
||||
*/
|
||||
private fun cleanNodeContent(content: String): String {
|
||||
return content
|
||||
.replace(Regex("```[\\s\\S]*?```"), "") // 移除代码块标记
|
||||
.replace(Regex("###?\\s*\\*\\*[^*]+\\*\\*"), "") // 移除标题
|
||||
.replace(Regex("\\*\\*选择\\d+\\*\\*[^\\n]*"), "") // 移除选择标记
|
||||
.lines()
|
||||
.filter { it.trim().isNotEmpty() }
|
||||
.joinToString("\n")
|
||||
.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* 从内容中提取选择
|
||||
*/
|
||||
private fun extractChoicesFromContent(content: String): MutableList<ExtractedChoice> {
|
||||
val choices = mutableListOf<ExtractedChoice>()
|
||||
val matcher = CHOICE_PATTERN.matcher(content)
|
||||
|
||||
while (matcher.find()) {
|
||||
val choiceText = matcher.group(1).trim()
|
||||
choices.add(ExtractedChoice(
|
||||
text = choiceText,
|
||||
nextNodeId = "", // 需要后续处理
|
||||
effects = extractEffectsFromText(choiceText),
|
||||
requirements = emptyList()
|
||||
))
|
||||
}
|
||||
|
||||
return choices
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文本中提取效果
|
||||
*/
|
||||
private fun extractEffectsFromText(text: String): List<String> {
|
||||
val effects = mutableListOf<String>()
|
||||
val matcher = EFFECT_PATTERN.matcher(text)
|
||||
|
||||
while (matcher.find()) {
|
||||
effects.add(matcher.group(1))
|
||||
}
|
||||
|
||||
return effects
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取对话示例
|
||||
*/
|
||||
private fun extractDialogueExamples(content: String): List<DialogueExample> {
|
||||
val examples = mutableListOf<DialogueExample>()
|
||||
|
||||
// 这里需要根据实际的对话文档格式来实现
|
||||
// 暂时返回空列表
|
||||
|
||||
return examples
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取道德原则
|
||||
*/
|
||||
private fun extractMoralPrinciples(content: String): List<String> {
|
||||
val principles = mutableListOf<String>()
|
||||
|
||||
// 查找道德相关的要点
|
||||
val lines = content.lines()
|
||||
for (line in lines) {
|
||||
if (line.trim().startsWith("-") && line.contains("道德")) {
|
||||
principles.add(line.trim().removePrefix("-").trim())
|
||||
}
|
||||
}
|
||||
|
||||
return principles
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取设计原则
|
||||
*/
|
||||
private fun extractDesignPrinciples(content: String): List<String> {
|
||||
val principles = mutableListOf<String>()
|
||||
|
||||
val lines = content.lines()
|
||||
for (line in lines) {
|
||||
if (line.trim().startsWith("-") && (line.contains("设计") || line.contains("原则"))) {
|
||||
principles.add(line.trim().removePrefix("-").trim())
|
||||
}
|
||||
}
|
||||
|
||||
return principles
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取故事结构
|
||||
*/
|
||||
private fun extractStoryStructure(content: String): Map<String, Any> {
|
||||
val structure = mutableMapOf<String, Any>()
|
||||
|
||||
// 提取阶段信息
|
||||
val phases = mutableListOf<Map<String, String>>()
|
||||
val phaseMatcher = PHASE_PATTERN.matcher(content)
|
||||
|
||||
while (phaseMatcher.find()) {
|
||||
val phaseNumber = phaseMatcher.group(1)
|
||||
val phaseTitle = phaseMatcher.group(2).trim()
|
||||
|
||||
phases.add(mapOf(
|
||||
"number" to phaseNumber,
|
||||
"title" to phaseTitle
|
||||
))
|
||||
}
|
||||
|
||||
structure["phases"] = phases
|
||||
|
||||
return structure
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成节点ID
|
||||
*/
|
||||
private fun generateNodeId(title: String): String {
|
||||
return title
|
||||
.replace(Regex("[^\\w\\s]"), "")
|
||||
.replace(Regex("\\s+"), "_")
|
||||
.lowercase()
|
||||
.take(30)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取节点元数据
|
||||
*/
|
||||
private fun extractNodeMetadata(title: String): Map<String, Any> {
|
||||
val metadata = mutableMapOf<String, Any>()
|
||||
|
||||
when {
|
||||
title.contains("觉醒") -> metadata["difficulty"] = 1
|
||||
title.contains("探索") -> metadata["difficulty"] = 2
|
||||
title.contains("真相") -> metadata["difficulty"] = 3
|
||||
title.contains("决战") -> metadata["difficulty"] = 4
|
||||
}
|
||||
|
||||
if (title.contains("伊娃") || title.contains("EVA")) {
|
||||
metadata["key_character"] = "eva"
|
||||
}
|
||||
|
||||
return metadata
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成DSL文件
|
||||
*/
|
||||
private fun generateDSLFiles(extractedContent: Map<String, ExtractedStoryData>, outputPath: String) {
|
||||
val outputDir = File(outputPath)
|
||||
outputDir.mkdirs()
|
||||
|
||||
for ((key, data) in extractedContent) {
|
||||
if (data.nodes.isNotEmpty()) {
|
||||
val dslContent = convertToDSL(data)
|
||||
val fileName = "${key}.story"
|
||||
File(outputDir, fileName).writeText(dslContent)
|
||||
println("📝 Generated $fileName (${data.nodes.size} nodes)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为DSL格式
|
||||
*/
|
||||
private fun convertToDSL(data: ExtractedStoryData): String {
|
||||
val dsl = StringBuilder()
|
||||
|
||||
dsl.appendLine("@story_module ${data.type}")
|
||||
dsl.appendLine("@version 1.0")
|
||||
dsl.appendLine("@dependencies [characters, audio_config]")
|
||||
dsl.appendLine()
|
||||
|
||||
dsl.appendLine("@audio")
|
||||
dsl.appendLine(" background: ambient_mystery.mp3")
|
||||
dsl.appendLine(" transition: discovery_chime.mp3")
|
||||
dsl.appendLine("@end")
|
||||
dsl.appendLine()
|
||||
|
||||
for (node in data.nodes) {
|
||||
dsl.appendLine("@node ${node.id}")
|
||||
dsl.appendLine("@title \"${escapeString(node.title)}\"")
|
||||
dsl.appendLine("@content \"\"\"")
|
||||
dsl.appendLine(node.content)
|
||||
dsl.appendLine("\"\"\"")
|
||||
|
||||
if (node.choices.isNotEmpty()) {
|
||||
dsl.appendLine()
|
||||
dsl.appendLine("@choices ${node.choices.size}")
|
||||
for ((index, choice) in node.choices.withIndex()) {
|
||||
dsl.append(" choice_${index + 1}: \"${escapeString(choice.text)}\" -> ${choice.nextNodeId}")
|
||||
if (choice.effects.isNotEmpty()) {
|
||||
dsl.append(" [effect: ${choice.effects.joinToString(", ")}]")
|
||||
}
|
||||
dsl.appendLine()
|
||||
}
|
||||
dsl.appendLine("@end")
|
||||
}
|
||||
dsl.appendLine()
|
||||
}
|
||||
|
||||
return dsl.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 转义字符串
|
||||
*/
|
||||
private fun escapeString(str: String): String {
|
||||
return str.replace("\"", "\\\"")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\t", "\\t")
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据类定义
|
||||
// ============================================================================
|
||||
|
||||
data class ExtractedStoryData(
|
||||
val type: String,
|
||||
val title: String,
|
||||
val nodes: List<ExtractedNode>,
|
||||
val metadata: Map<String, Any>
|
||||
)
|
||||
|
||||
data class ExtractedNode(
|
||||
val id: String,
|
||||
val title: String,
|
||||
var content: String,
|
||||
val type: String,
|
||||
val choices: MutableList<ExtractedChoice>,
|
||||
val metadata: Map<String, Any>
|
||||
)
|
||||
|
||||
data class ExtractedChoice(
|
||||
val text: String,
|
||||
val nextNodeId: String,
|
||||
val effects: List<String>,
|
||||
val requirements: List<String>
|
||||
)
|
||||
|
||||
data class DialogueExample(
|
||||
val title: String,
|
||||
val content: String,
|
||||
val characters: List<String>,
|
||||
val choices: MutableList<ExtractedChoice>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
package com.example.gameofmoon.story.migration
|
||||
|
||||
import com.example.gameofmoon.model.SimpleChoice
|
||||
import com.example.gameofmoon.model.SimpleStoryNode
|
||||
import com.example.gameofmoon.story.CompleteStoryData
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
/**
|
||||
* 故事迁移工具
|
||||
* 将现有的硬编码故事数据转换为DSL格式文件
|
||||
*/
|
||||
class StoryMigrationTool {
|
||||
|
||||
companion object {
|
||||
private const val ASSETS_STORY_PATH = "app/src/main/assets/story"
|
||||
private const val MODULES_PATH = "$ASSETS_STORY_PATH/modules"
|
||||
private const val SHARED_PATH = "$ASSETS_STORY_PATH/shared"
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行完整的迁移流程
|
||||
*/
|
||||
fun migrateAll(projectRoot: String) {
|
||||
println("🚀 Starting story migration process...")
|
||||
|
||||
// 创建目录结构
|
||||
createDirectoryStructure(projectRoot)
|
||||
|
||||
// 迁移配置文件
|
||||
migrateConfig(projectRoot)
|
||||
|
||||
// 迁移角色定义
|
||||
migrateCharacters(projectRoot)
|
||||
|
||||
// 迁移音频配置
|
||||
migrateAudioConfig(projectRoot)
|
||||
|
||||
// 迁移故事内容
|
||||
migrateStoryContent(projectRoot)
|
||||
|
||||
// 创建锚点映射
|
||||
createAnchorMappings(projectRoot)
|
||||
|
||||
println("✅ Migration completed successfully!")
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录结构
|
||||
*/
|
||||
private fun createDirectoryStructure(projectRoot: String) {
|
||||
val directories = listOf(
|
||||
"$projectRoot/$ASSETS_STORY_PATH",
|
||||
"$projectRoot/$MODULES_PATH",
|
||||
"$projectRoot/$SHARED_PATH",
|
||||
"$projectRoot/$ASSETS_STORY_PATH/localization/zh",
|
||||
"$projectRoot/$ASSETS_STORY_PATH/localization/en"
|
||||
)
|
||||
|
||||
directories.forEach { path ->
|
||||
File(path).mkdirs()
|
||||
}
|
||||
|
||||
println("📁 Created directory structure")
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移总配置文件
|
||||
*/
|
||||
private fun migrateConfig(projectRoot: String) {
|
||||
val configContent = """
|
||||
{
|
||||
"version": "1.0",
|
||||
"default_language": "zh",
|
||||
"modules": [
|
||||
"main_chapter_1",
|
||||
"main_chapter_2",
|
||||
"main_chapter_3",
|
||||
"side_stories",
|
||||
"investigation_branch",
|
||||
"endings"
|
||||
],
|
||||
"audio": {
|
||||
"enabled": true,
|
||||
"default_volume": 0.7,
|
||||
"fade_duration": 1000
|
||||
},
|
||||
"gameplay": {
|
||||
"auto_save": true,
|
||||
"choice_timeout": 0,
|
||||
"skip_seen_content": false
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
writeFile("$projectRoot/$ASSETS_STORY_PATH/config.json", configContent)
|
||||
println("📄 Created config.json")
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移角色定义
|
||||
*/
|
||||
private fun migrateCharacters(projectRoot: String) {
|
||||
val charactersContent = """
|
||||
@story_module characters
|
||||
@version 1.0
|
||||
|
||||
@character eva
|
||||
name: "伊娃 / EVA"
|
||||
voice_style: gentle
|
||||
description: "基地AI系统,实际上是莉莉的意识转移"
|
||||
relationship: "妹妹"
|
||||
@end
|
||||
|
||||
@character alex
|
||||
name: "艾利克丝·陈"
|
||||
voice_style: determined
|
||||
description: "月球基地工程师,主角"
|
||||
relationship: "自己"
|
||||
@end
|
||||
|
||||
@character sara
|
||||
name: "萨拉博士"
|
||||
voice_style: professional
|
||||
description: "基地医生,负责心理健康"
|
||||
relationship: "同事"
|
||||
@end
|
||||
|
||||
@character dmitri
|
||||
name: "德米特里博士"
|
||||
voice_style: serious
|
||||
description: "时间锚项目负责人"
|
||||
relationship: "上级"
|
||||
@end
|
||||
|
||||
@character marcus
|
||||
name: "马库斯"
|
||||
voice_style: calm
|
||||
description: "基地安全官,前军人"
|
||||
relationship: "盟友"
|
||||
@end
|
||||
|
||||
@character harrison
|
||||
name: "哈里森指挥官"
|
||||
voice_style: authoritative
|
||||
description: "已故的基地前指挥官"
|
||||
relationship: "殉道者"
|
||||
@end
|
||||
""".trimIndent()
|
||||
|
||||
writeFile("$projectRoot/$SHARED_PATH/characters.story", charactersContent)
|
||||
println("👥 Created characters.story")
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移音频配置
|
||||
*/
|
||||
private fun migrateAudioConfig(projectRoot: String) {
|
||||
val audioContent = """
|
||||
@story_module audio_config
|
||||
@version 1.0
|
||||
|
||||
@audio
|
||||
// 背景音乐
|
||||
mysterious: ambient_mystery.mp3
|
||||
tension: electronic_tension.mp3
|
||||
peaceful: space_silence.mp3
|
||||
revelation: orchestral_revelation.mp3
|
||||
finale: epic_finale.mp3
|
||||
|
||||
// 环境音效
|
||||
base_ambient: reactor_hum.mp3
|
||||
ventilation: ventilation_soft.mp3
|
||||
storm: solar_storm.mp3
|
||||
|
||||
// 交互音效
|
||||
button_click: button_click.mp3
|
||||
notification: notification_beep.mp3
|
||||
discovery: discovery_chime.mp3
|
||||
alert: error_alert.mp3
|
||||
heartbeat: heart_monitor.mp3
|
||||
|
||||
// 特殊音效
|
||||
time_distortion: time_distortion.mp3
|
||||
oxygen_leak: oxygen_leak_alert.mp3
|
||||
rain: rain_light.mp3
|
||||
wind: wind_gentle.mp3
|
||||
storm_cyber: storm_cyber.mp3
|
||||
@end
|
||||
""".trimIndent()
|
||||
|
||||
writeFile("$projectRoot/$SHARED_PATH/audio.story", audioContent)
|
||||
println("🎵 Created audio.story")
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移故事内容 - 这是核心功能
|
||||
*/
|
||||
private fun migrateStoryContent(projectRoot: String) {
|
||||
val allNodes = CompleteStoryData.getAllStoryNodes()
|
||||
|
||||
// 按章节和类型分组节点
|
||||
val nodeGroups = categorizeNodes(allNodes)
|
||||
|
||||
// 生成各个模块文件
|
||||
generateMainChapter1(projectRoot, nodeGroups["main_chapter_1"] ?: emptyList())
|
||||
generateMainChapter2(projectRoot, nodeGroups["main_chapter_2"] ?: emptyList())
|
||||
generateMainChapter3(projectRoot, nodeGroups["main_chapter_3"] ?: emptyList())
|
||||
generateSideStories(projectRoot, nodeGroups["side_stories"] ?: emptyList())
|
||||
generateInvestigationBranch(projectRoot, nodeGroups["investigation"] ?: emptyList())
|
||||
generateEndings(projectRoot, nodeGroups["endings"] ?: emptyList())
|
||||
|
||||
println("📚 Migrated all story content")
|
||||
}
|
||||
|
||||
/**
|
||||
* 对节点进行分类
|
||||
*/
|
||||
private fun categorizeNodes(nodes: Map<String, SimpleStoryNode>): Map<String, List<SimpleStoryNode>> {
|
||||
val categories = mutableMapOf<String, MutableList<SimpleStoryNode>>()
|
||||
|
||||
for (node in nodes.values) {
|
||||
val category = determineNodeCategory(node)
|
||||
categories.getOrPut(category) { mutableListOf() }.add(node)
|
||||
}
|
||||
|
||||
return categories
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定节点类别
|
||||
*/
|
||||
private fun determineNodeCategory(node: SimpleStoryNode): String {
|
||||
return when {
|
||||
// 结局节点
|
||||
node.id.contains("ending") ||
|
||||
node.id.contains("resolution") ||
|
||||
node.id.contains("anchor_destruction") ||
|
||||
node.id.contains("eternal_loop") ||
|
||||
node.id.contains("earth_truth") -> "endings"
|
||||
|
||||
// 调查支线
|
||||
node.id.contains("investigation") ||
|
||||
node.id.contains("stealth") ||
|
||||
node.id.contains("confrontation") ||
|
||||
node.id.contains("harrison") ||
|
||||
node.id.contains("conspiracy") -> "investigation"
|
||||
|
||||
// 侧线故事
|
||||
node.id.startsWith("side_") ||
|
||||
node.id.contains("garden") ||
|
||||
node.id.contains("photo") ||
|
||||
node.id.contains("memory_reconstruction") ||
|
||||
node.id.contains("philosophical") -> "side_stories"
|
||||
|
||||
// 第三章节 (深度探索和高级内容)
|
||||
node.id.contains("deep_") ||
|
||||
node.id.contains("eva_consultation") ||
|
||||
node.id.contains("digital_revolution") ||
|
||||
node.id.contains("reality_crisis") -> "main_chapter_3"
|
||||
|
||||
// 第二章节 (中期发展)
|
||||
node.id.contains("eva_identity") ||
|
||||
node.id.contains("time_loop") ||
|
||||
node.id.contains("crew_") ||
|
||||
node.id.contains("emotional_") ||
|
||||
node.id.contains("memory_sharing") -> "main_chapter_2"
|
||||
|
||||
// 第一章节 (开始和基础发现)
|
||||
else -> "main_chapter_1"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主章节1文件
|
||||
*/
|
||||
private fun generateMainChapter1(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module main_chapter_1")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: ambient_mystery.mp3")
|
||||
content.appendLine(" transition: discovery_chime.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/main_chapter_1.story", content.toString())
|
||||
println("📖 Generated main_chapter_1.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主章节2文件
|
||||
*/
|
||||
private fun generateMainChapter2(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module main_chapter_2")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [main_chapter_1, characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: electronic_tension.mp3")
|
||||
content.appendLine(" transition: discovery_chime.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/main_chapter_2.story", content.toString())
|
||||
println("📖 Generated main_chapter_2.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主章节3文件
|
||||
*/
|
||||
private fun generateMainChapter3(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module main_chapter_3")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [main_chapter_2, characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: orchestral_revelation.mp3")
|
||||
content.appendLine(" transition: time_distortion.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/main_chapter_3.story", content.toString())
|
||||
println("📖 Generated main_chapter_3.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支线故事文件
|
||||
*/
|
||||
private fun generateSideStories(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module side_stories")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: space_silence.mp3")
|
||||
content.appendLine(" transition: discovery_chime.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/side_stories.story", content.toString())
|
||||
println("📖 Generated side_stories.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成调查支线文件
|
||||
*/
|
||||
private fun generateInvestigationBranch(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module investigation_branch")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [main_chapter_2, characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: electronic_tension.mp3")
|
||||
content.appendLine(" transition: discovery_chime.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/investigation_branch.story", content.toString())
|
||||
println("📖 Generated investigation_branch.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成结局文件
|
||||
*/
|
||||
private fun generateEndings(projectRoot: String, nodes: List<SimpleStoryNode>) {
|
||||
val content = StringBuilder()
|
||||
content.appendLine("@story_module endings")
|
||||
content.appendLine("@version 1.0")
|
||||
content.appendLine("@dependencies [main_chapter_3, characters, audio_config]")
|
||||
content.appendLine()
|
||||
|
||||
content.appendLine("@audio")
|
||||
content.appendLine(" background: epic_finale.mp3")
|
||||
content.appendLine(" transition: orchestral_revelation.mp3")
|
||||
content.appendLine("@end")
|
||||
content.appendLine()
|
||||
|
||||
for (node in nodes.sortedBy { it.id }) {
|
||||
content.append(convertNodeToDSL(node))
|
||||
content.appendLine()
|
||||
}
|
||||
|
||||
writeFile("$projectRoot/$MODULES_PATH/endings.story", content.toString())
|
||||
println("📖 Generated endings.story (${nodes.size} nodes)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 将SimpleStoryNode转换为DSL格式
|
||||
*/
|
||||
private fun convertNodeToDSL(node: SimpleStoryNode): String {
|
||||
val dsl = StringBuilder()
|
||||
|
||||
dsl.appendLine("@node ${node.id}")
|
||||
dsl.appendLine("@title \"${escapeString(node.title)}\"")
|
||||
|
||||
// 根据内容推断音频
|
||||
val audioFile = inferAudioFromContent(node)
|
||||
if (audioFile.isNotEmpty()) {
|
||||
dsl.appendLine("@audio_bg $audioFile")
|
||||
}
|
||||
|
||||
dsl.appendLine("@content \"\"\"")
|
||||
dsl.appendLine(node.content.trim())
|
||||
dsl.appendLine("\"\"\"")
|
||||
dsl.appendLine()
|
||||
|
||||
if (node.choices.isNotEmpty()) {
|
||||
dsl.appendLine("@choices ${node.choices.size}")
|
||||
for ((index, choice) in node.choices.withIndex()) {
|
||||
val choiceText = escapeString(choice.text)
|
||||
val effectsStr = convertEffectsToString(choice.effects)
|
||||
val requirementsStr = convertRequirementsToString(choice.requirements)
|
||||
val audioEffect = inferChoiceAudio(choice)
|
||||
|
||||
dsl.append(" choice_${index + 1}: \"$choiceText\" -> ${choice.nextNodeId}")
|
||||
|
||||
if (effectsStr.isNotEmpty()) {
|
||||
dsl.append(" [effect: $effectsStr]")
|
||||
}
|
||||
|
||||
if (requirementsStr.isNotEmpty()) {
|
||||
dsl.append(" [require: $requirementsStr]")
|
||||
}
|
||||
|
||||
if (audioEffect.isNotEmpty()) {
|
||||
dsl.append(" [audio: $audioEffect]")
|
||||
}
|
||||
|
||||
dsl.appendLine()
|
||||
}
|
||||
dsl.appendLine("@end")
|
||||
}
|
||||
dsl.appendLine()
|
||||
|
||||
return dsl.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据内容推断音频文件
|
||||
*/
|
||||
private fun inferAudioFromContent(node: SimpleStoryNode): String {
|
||||
val content = node.content.lowercase()
|
||||
return when {
|
||||
content.contains("警报") || content.contains("危险") || content.contains("紧急") -> "error_alert.mp3"
|
||||
content.contains("发现") || content.contains("找到") || content.contains("揭露") -> "discovery_chime.mp3"
|
||||
content.contains("心跳") || content.contains("紧张") || content.contains("恐惧") -> "heart_monitor.mp3"
|
||||
content.contains("花园") || content.contains("植物") || content.contains("平静") -> "space_silence.mp3"
|
||||
content.contains("风暴") || content.contains("混乱") -> "solar_storm.mp3"
|
||||
content.contains("时间") || content.contains("循环") -> "time_distortion.mp3"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推断选择音效
|
||||
*/
|
||||
private fun inferChoiceAudio(choice: SimpleChoice): String {
|
||||
val text = choice.text.lowercase()
|
||||
return when {
|
||||
text.contains("警告") || text.contains("危险") -> "error_alert.mp3"
|
||||
text.contains("发现") || text.contains("查看") -> "discovery_chime.mp3"
|
||||
else -> "button_click.mp3"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换效果为字符串
|
||||
*/
|
||||
private fun convertEffectsToString(effects: List<com.example.gameofmoon.model.SimpleEffect>): String {
|
||||
return effects.joinToString(", ") { effect ->
|
||||
when (effect.type) {
|
||||
com.example.gameofmoon.model.SimpleEffectType.HEALTH_CHANGE -> "health${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.STAMINA_CHANGE -> "stamina${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.SECRET_UNLOCK -> "secret_${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.LOCATION_DISCOVER -> "location_${effect.value}"
|
||||
com.example.gameofmoon.model.SimpleEffectType.LOOP_CHANGE -> "loop${effect.value}"
|
||||
else -> "${effect.type.name.lowercase()}_${effect.value}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换需求为字符串
|
||||
*/
|
||||
private fun convertRequirementsToString(requirements: List<com.example.gameofmoon.model.SimpleRequirement>): String {
|
||||
if (requirements.isEmpty()) return "none"
|
||||
|
||||
return requirements.joinToString(", ") { req ->
|
||||
when (req.type) {
|
||||
com.example.gameofmoon.model.SimpleRequirementType.MIN_STAMINA -> "stamina >= ${req.value}"
|
||||
com.example.gameofmoon.model.SimpleRequirementType.MIN_HEALTH -> "health >= ${req.value}"
|
||||
else -> "${req.type.name.lowercase()}_${req.value}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建锚点映射文件
|
||||
*/
|
||||
private fun createAnchorMappings(projectRoot: String) {
|
||||
val anchorContent = """
|
||||
@story_module anchors
|
||||
@version 1.0
|
||||
|
||||
@anchor_conditions
|
||||
eva_reveal_ready: secrets_found >= 3 AND trust_level >= 5
|
||||
investigation_unlocked: harrison_recording_found == true
|
||||
perfect_ending_available: secrets_found >= 15 AND health > 50 AND all_crew_saved == true
|
||||
garden_unlocked: sara_trust >= 3
|
||||
deep_truth_ready: eva_reveal_ready == true AND investigation_unlocked == true
|
||||
final_choice_ready: perfect_ending_available == true OR deep_truth_ready == true
|
||||
@end
|
||||
""".trimIndent()
|
||||
|
||||
writeFile("$projectRoot/$SHARED_PATH/anchors.story", anchorContent)
|
||||
println("⚓ Created anchors.story")
|
||||
}
|
||||
|
||||
/**
|
||||
* 转义字符串中的特殊字符
|
||||
*/
|
||||
private fun escapeString(str: String): String {
|
||||
return str.replace("\"", "\\\"")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\t", "\\t")
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入文件
|
||||
*/
|
||||
private fun writeFile(path: String, content: String) {
|
||||
val file = File(path)
|
||||
file.parentFile?.mkdirs()
|
||||
FileWriter(file).use { writer ->
|
||||
writer.write(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
11
app/src/main/java/com/example/gameofmoon/ui/theme/Color.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.example.gameofmoon.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
56
app/src/main/java/com/example/gameofmoon/ui/theme/Theme.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.example.gameofmoon.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80,
|
||||
background = Color(0xFF000000), // 强制黑色背景
|
||||
surface = Color(0xFF0A0A0A), // 深黑色表面
|
||||
onBackground = Color(0xFFE0E0E0), // 亮色文字
|
||||
onSurface = Color(0xFFE0E0E0) // 亮色文字
|
||||
)
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40
|
||||
|
||||
/* Other default colors to override
|
||||
background = Color(0xFFFFFBFE),
|
||||
surface = Color(0xFFFFFBFE),
|
||||
onPrimary = Color.White,
|
||||
onSecondary = Color.White,
|
||||
onTertiary = Color.White,
|
||||
onBackground = Color(0xFF1C1B1F),
|
||||
onSurface = Color(0xFF1C1B1F),
|
||||
*/
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun GameofMoonTheme(
|
||||
darkTheme: Boolean = true, // 始终使用暗色主题
|
||||
// Dynamic color is available on Android 12+
|
||||
dynamicColor: Boolean = false, // 禁用动态颜色,确保一致性
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
// 强制使用暗色方案,确保黑色背景
|
||||
val colorScheme = DarkColorScheme
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
34
app/src/main/java/com/example/gameofmoon/ui/theme/Type.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.example.gameofmoon.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
BIN
app/src/main/res/.DS_Store
vendored
Normal file
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
30
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
6
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
6
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
app/src/main/res/raw/.DS_Store
vendored
Normal file
BIN
app/src/main/res/raw/ambient_mystery.mp3
Normal file
BIN
app/src/main/res/raw/button_click.mp3
Normal file
BIN
app/src/main/res/raw/discovery_chime.mp3
Normal file
BIN
app/src/main/res/raw/electronic_tension.mp3
Normal file
BIN
app/src/main/res/raw/epic_finale.mp3
Normal file
BIN
app/src/main/res/raw/error_alert.mp3
Normal file
BIN
app/src/main/res/raw/heart_monitor.mp3
Normal file
BIN
app/src/main/res/raw/notification_beep.mp3
Normal file
BIN
app/src/main/res/raw/orchestral_revelation.mp3
Normal file
BIN
app/src/main/res/raw/oxygen_leak_alert.mp3
Normal file
BIN
app/src/main/res/raw/rain_light.mp3
Normal file
BIN
app/src/main/res/raw/reactor_hum.mp3
Normal file
29
app/src/main/res/raw/readme_audio.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
音频文件下载说明
|
||||
=================
|
||||
|
||||
本目录包含游戏所需的 18 个音频文件。
|
||||
|
||||
当前状态:
|
||||
- ✅ 部分文件可能已通过脚本自动下载
|
||||
- 📄 其他文件为占位符,需要手动下载替换
|
||||
|
||||
手动下载步骤:
|
||||
1. 访问 https://pixabay.com/sound-effects/
|
||||
2. 搜索对应的音效类型 (例如: "button click", "ambient space")
|
||||
3. 下载 MP3 格式的音频文件
|
||||
4. 重命名为对应的文件名 (如 button_click.mp3)
|
||||
5. 替换本目录中的占位符文件
|
||||
|
||||
自动化工具:
|
||||
- 运行 ../../../audio_rename.sh 自动重命名下载的文件
|
||||
- 查看 ../../../AUDIO_DOWNLOAD_GUIDE.md 获取详细下载指南
|
||||
|
||||
测试音频系统:
|
||||
即使使用占位文件,游戏的音频系统也能正常运行,
|
||||
这样你就可以先测试功能,稍后再添加真实音频。
|
||||
|
||||
编译游戏:
|
||||
cd ../../../
|
||||
./gradlew assembleDebug
|
||||
|
||||
下载完成后,游戏将拥有完整的音频体验!
|
||||
BIN
app/src/main/res/raw/solar_storm.mp3
Normal file
BIN
app/src/main/res/raw/space_silence.mp3
Normal file
BIN
app/src/main/res/raw/storm_cyber.mp3
Normal file
BIN
app/src/main/res/raw/time_distortion.mp3
Normal file
BIN
app/src/main/res/raw/ventilation_soft.mp3
Normal file
BIN
app/src/main/res/raw/wind_gentle.mp3
Normal file
6
app/src/main/res/values/api_keys.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Gemini API配置 -->
|
||||
<string name="gemini_api_key">AIzaSyAO7glJMBH5BiJhqYBAOD7FTgv4tVi2HLE</string>
|
||||
<string name="gemini_api_base_url">https://generativelanguage.googleapis.com/v1beta/</string>
|
||||
</resources>
|
||||
10
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
3
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">GameofMoon</string>
|
||||
</resources>
|
||||
5
app/src/main/res/values/themes.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Theme.GameofMoon" parent="android:Theme.Material.Light.NoActionBar" />
|
||||
</resources>
|
||||
13
app/src/main/res/xml/backup_rules.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older that API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
-->
|
||||
</full-backup-content>
|
||||
19
app/src/main/res/xml/data_extraction_rules.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
17
app/src/test/java/com/example/gameofmoon/ExampleUnitTest.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.example.gameofmoon
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||