Spaces:
No application file
No application file
| <html lang="zh-CN"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Gamification Design Studio - 游戏化机制设计工坊</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet"> | |
| <style> | |
| body { font-family: 'Inter', sans-serif; } | |
| /* Custom scrollbar for dark mode feeling */ | |
| ::-webkit-scrollbar { width: 8px; } | |
| ::-webkit-scrollbar-track { background: #1f2937; } | |
| ::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 4px; } | |
| ::-webkit-scrollbar-thumb:hover { background: #6b7280; } | |
| </style> | |
| <script> | |
| tailwind.config = { | |
| darkMode: 'class', | |
| theme: { | |
| extend: { | |
| colors: { | |
| primary: '#6366f1', | |
| secondary: '#ec4899', | |
| dark: '#111827', | |
| darker: '#0b0f19', | |
| surface: '#1f2937' | |
| } | |
| } | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body class="bg-gray-100 dark:bg-darker text-gray-900 dark:text-gray-100 transition-colors duration-200 h-screen overflow-hidden flex flex-col"> | |
| <div id="app" class="flex flex-col h-full" v-cloak> | |
| <!-- Header --> | |
| <header class="bg-white dark:bg-surface border-b dark:border-gray-700 p-4 flex justify-between items-center shadow-sm z-10"> | |
| <div class="flex items-center space-x-3"> | |
| <div class="bg-gradient-to-r from-primary to-secondary p-2 rounded-lg text-white font-bold text-xl"> | |
| GDS | |
| </div> | |
| <div> | |
| <h1 class="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-primary to-secondary"> | |
| 游戏化机制设计工坊 | |
| </h1> | |
| <p class="text-xs text-gray-500 dark:text-gray-400">Gamification Design Studio</p> | |
| </div> | |
| </div> | |
| <div class="flex items-center space-x-4"> | |
| <button @click="toggleTheme" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 transition" title="切换主题"> | |
| <span v-if="isDark">🌞</span> | |
| <span v-else>🌙</span> | |
| </button> | |
| <div class="relative group"> | |
| <button class="bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 px-4 py-2 rounded-md text-sm font-medium transition"> | |
| 预设模版 | |
| </button> | |
| <div class="absolute right-0 mt-2 w-48 bg-white dark:bg-surface border dark:border-gray-700 rounded-md shadow-lg hidden group-hover:block z-50"> | |
| <a href="#" @click.prevent="loadPreset('community')" class="block px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700">社区运营 (Community)</a> | |
| <a href="#" @click.prevent="loadPreset('rpg')" class="block px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700">RPG 游戏 (Game)</a> | |
| <a href="#" @click.prevent="loadPreset('education')" class="block px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700">教育学习 (Edu)</a> | |
| </div> | |
| </div> | |
| <button @click="resetConfig" class="text-red-500 hover:text-red-600 px-3 py-2 text-sm font-medium transition" title="重置"> | |
| <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg> | |
| </button> | |
| <div class="flex space-x-2"> | |
| <label class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition cursor-pointer flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg> | |
| 导入 | |
| <input type="file" @change="importConfig" class="hidden" accept=".json"> | |
| </label> | |
| <button @click="exportConfig" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-md text-sm font-medium transition flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg> | |
| 导出 | |
| </button> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Main Content --> | |
| <main class="flex-1 flex overflow-hidden"> | |
| <!-- Left Panel: Configuration --> | |
| <div class="w-1/3 min-w-[350px] bg-gray-50 dark:bg-dark border-r dark:border-gray-700 flex flex-col overflow-hidden"> | |
| <div class="p-4 border-b dark:border-gray-700 bg-white dark:bg-surface"> | |
| <h2 class="font-semibold text-lg flex items-center"> | |
| <span class="mr-2">🛠️</span> 机制配置 | |
| </h2> | |
| </div> | |
| <div class="flex-1 overflow-y-auto p-4 space-y-6"> | |
| <!-- Actions Section --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-4 shadow-sm border dark:border-gray-700"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="font-medium text-primary">用户行为 (Actions)</h3> | |
| <button @click="addAction" class="text-xs bg-primary hover:bg-indigo-700 text-white px-2 py-1 rounded">+ 添加</button> | |
| </div> | |
| <div class="space-y-3"> | |
| <div v-for="(action, index) in actions" :key="index" class="bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border dark:border-gray-700 group relative"> | |
| <div class="flex justify-between items-start mb-2"> | |
| <input v-model="action.name" class="bg-transparent font-medium text-sm w-full focus:outline-none border-b border-transparent focus:border-primary" placeholder="行为名称"> | |
| <button @click="removeAction(index)" class="text-gray-400 hover:text-red-500 opacity-0 group-hover:opacity-100 transition">×</button> | |
| </div> | |
| <div class="grid grid-cols-3 gap-2 text-xs"> | |
| <div> | |
| <label class="text-gray-500">XP 奖励</label> | |
| <input type="number" v-model.number="action.xp" class="w-full bg-white dark:bg-gray-700 rounded px-2 py-1 mt-1 border dark:border-gray-600"> | |
| </div> | |
| <div> | |
| <label class="text-gray-500">金币奖励</label> | |
| <input type="number" v-model.number="action.gold" class="w-full bg-white dark:bg-gray-700 rounded px-2 py-1 mt-1 border dark:border-gray-600"> | |
| </div> | |
| <div> | |
| <label class="text-gray-500">每日频率</label> | |
| <input type="number" v-model.number="action.dailyFreq" step="0.1" class="w-full bg-white dark:bg-gray-700 rounded px-2 py-1 mt-1 border dark:border-gray-600"> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Levels Section --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-4 shadow-sm border dark:border-gray-700"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="font-medium text-secondary">等级系统 (Levels)</h3> | |
| </div> | |
| <div class="space-y-4"> | |
| <div> | |
| <label class="text-xs text-gray-500 block mb-1">最大等级</label> | |
| <input type="range" v-model.number="levelConfig.maxLevel" min="5" max="100" class="w-full accent-secondary"> | |
| <div class="text-right text-xs text-gray-400">[[ levelConfig.maxLevel ]] 级</div> | |
| </div> | |
| <div> | |
| <label class="text-xs text-gray-500 block mb-1">升级曲线系数 (Exp Factor)</label> | |
| <div class="flex items-center space-x-2"> | |
| <input type="range" v-model.number="levelConfig.factor" min="1.0" max="3.0" step="0.1" class="w-full accent-secondary"> | |
| <span class="text-xs w-8">[[ levelConfig.factor ]]</span> | |
| </div> | |
| <p class="text-[10px] text-gray-400 mt-1">XP = 基础值 * (等级 ^ 系数)</p> | |
| </div> | |
| <div> | |
| <label class="text-xs text-gray-500 block mb-1">1级基础XP</label> | |
| <input type="number" v-model.number="levelConfig.baseXp" class="w-full bg-gray-50 dark:bg-gray-800 rounded px-2 py-1 border dark:border-gray-600 text-sm"> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Sinks Section --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-4 shadow-sm border dark:border-gray-700"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="font-medium text-yellow-500">金币消耗 (Sinks)</h3> | |
| <button @click="addSink" class="text-xs bg-yellow-600 hover:bg-yellow-700 text-white px-2 py-1 rounded">+ 添加</button> | |
| </div> | |
| <div class="space-y-3"> | |
| <div v-for="(sink, index) in sinks" :key="index" class="bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border dark:border-gray-700 group relative"> | |
| <div class="flex justify-between items-start mb-2"> | |
| <input v-model="sink.name" class="bg-transparent font-medium text-sm w-full focus:outline-none border-b border-transparent focus:border-yellow-500" placeholder="物品名称"> | |
| <button @click="removeSink(index)" class="text-gray-400 hover:text-red-500 opacity-0 group-hover:opacity-100 transition">×</button> | |
| </div> | |
| <div class="text-xs"> | |
| <label class="text-gray-500">金币价格</label> | |
| <input type="number" v-model.number="sink.cost" class="w-full bg-white dark:bg-gray-700 rounded px-2 py-1 mt-1 border dark:border-gray-600"> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Right Panel: Simulation & Visualization --> | |
| <div class="flex-1 bg-gray-100 dark:bg-darker flex flex-col overflow-hidden"> | |
| <div class="p-4 border-b dark:border-gray-700 bg-white dark:bg-surface flex justify-between items-center"> | |
| <h2 class="font-semibold text-lg flex items-center"> | |
| <span class="mr-2">📊</span> 模拟推演 (Simulation) | |
| </h2> | |
| <div class="flex items-center space-x-2 text-sm"> | |
| <span class="text-gray-500">模拟天数:</span> | |
| <input type="number" v-model.number="simulationDays" class="w-16 bg-gray-50 dark:bg-gray-700 border dark:border-gray-600 rounded px-2 py-1 text-center"> | |
| </div> | |
| </div> | |
| <div class="flex-1 overflow-y-auto p-6"> | |
| <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6"> | |
| <!-- User Behavior Setting --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-5 shadow-sm border dark:border-gray-700"> | |
| <h3 class="font-medium mb-4 text-sm text-gray-500 uppercase tracking-wider">用户行为假设 (每日频率)</h3> | |
| <div class="space-y-4"> | |
| <div v-for="(action, index) in actions" :key="index" class="flex items-center space-x-4"> | |
| <div class="w-1/3 text-sm truncate" :title="action.name">[[ action.name ]]</div> | |
| <div class="flex-1 flex items-center space-x-2"> | |
| <input type="range" v-model.number="action.dailyFreq" min="0" max="20" step="0.5" class="flex-1 accent-primary"> | |
| <span class="text-xs w-8 text-right">[[ action.dailyFreq ]]次</span> | |
| </div> | |
| </div> | |
| <div class="mt-4 pt-4 border-t dark:border-gray-700"> | |
| <p class="text-xs text-gray-400 mb-2">预估每日产出:</p> | |
| <div class="flex space-x-4 text-sm font-bold"> | |
| <div class="text-primary">+[[ dailyXp ]] XP/天</div> | |
| <div class="text-yellow-500">+[[ dailyGold ]] 金币/天</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Quick Stats --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-5 shadow-sm border dark:border-gray-700 flex flex-col justify-center"> | |
| <div class="grid grid-cols-2 gap-4 text-center"> | |
| <div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"> | |
| <div class="text-xs text-gray-500 mb-1">达到满级所需</div> | |
| <div class="text-2xl font-bold text-secondary">[[ daysToMaxLevel ]] <span class="text-sm font-normal text-gray-400">天</span></div> | |
| <div class="text-xs text-gray-400 mt-1">约 [[ (daysToMaxLevel / 30).toFixed(1) ]] 个月</div> | |
| </div> | |
| <div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"> | |
| <div class="text-xs text-gray-500 mb-1">30天金币积累</div> | |
| <div class="text-2xl font-bold text-yellow-500">[[ totalGold30Days ]]</div> | |
| <div class="text-xs text-gray-400 mt-1">可购买 [[ affordableItems ]] 个不同商品</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Charts --> | |
| <div class="grid grid-cols-1 gap-6"> | |
| <!-- Level Curve --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-5 shadow-sm border dark:border-gray-700 h-80"> | |
| <h3 class="font-medium mb-4 text-sm text-gray-500 uppercase tracking-wider">等级进度曲线 (Level Progression)</h3> | |
| <canvas id="levelChart"></canvas> | |
| </div> | |
| <!-- Economy Balance --> | |
| <div class="bg-white dark:bg-surface rounded-xl p-5 shadow-sm border dark:border-gray-700 h-80"> | |
| <h3 class="font-medium mb-4 text-sm text-gray-500 uppercase tracking-wider">经济积累预测 (Economy Forecast)</h3> | |
| <canvas id="economyChart"></canvas> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| </div> | |
| <script> | |
| const { createApp, ref, computed, onMounted, watch } = Vue; | |
| createApp({ | |
| delimiters: ['[[', ']]'], | |
| setup() { | |
| const isDark = ref(true); | |
| const simulationDays = ref(90); | |
| // Config Data | |
| const actions = ref([ | |
| { name: '每日登录', xp: 10, gold: 5, dailyFreq: 1 }, | |
| { name: '发布内容', xp: 50, gold: 2, dailyFreq: 0.5 }, | |
| { name: '点赞/互动', xp: 5, gold: 1, dailyFreq: 5 }, | |
| { name: '完成新手任务', xp: 200, gold: 50, dailyFreq: 0 }, // one-time simulated as 0 daily but initial | |
| { name: '邀请好友', xp: 100, gold: 20, dailyFreq: 0.1 } | |
| ]); | |
| const sinks = ref([ | |
| { name: '头像框', cost: 100 }, | |
| { name: '高级皮肤', cost: 500 }, | |
| { name: '免广告月卡', cost: 1000 } | |
| ]); | |
| const levelConfig = ref({ | |
| maxLevel: 20, | |
| baseXp: 100, | |
| factor: 1.5 | |
| }); | |
| // Computed | |
| const dailyXp = computed(() => { | |
| return actions.value.reduce((acc, act) => acc + (act.xp * act.dailyFreq), 0); | |
| }); | |
| const dailyGold = computed(() => { | |
| return actions.value.reduce((acc, act) => acc + (act.gold * act.dailyFreq), 0); | |
| }); | |
| const levelTable = computed(() => { | |
| const levels = []; | |
| let totalXp = 0; | |
| for(let i=1; i<=levelConfig.value.maxLevel; i++) { | |
| // Formula: XP needed for level i = base * (i-1)^factor | |
| // Cumulative XP to reach level i | |
| let xpForNext = Math.floor(levelConfig.value.baseXp * Math.pow(i, levelConfig.value.factor)); | |
| if (i === 1) xpForNext = 0; | |
| totalXp += xpForNext; | |
| levels.push({ level: i, xpRequired: xpForNext, totalXp: totalXp }); | |
| } | |
| return levels; | |
| }); | |
| const daysToMaxLevel = computed(() => { | |
| if (dailyXp.value <= 0) return '∞'; | |
| const maxXp = levelTable.value[levelTable.value.length - 1].totalXp; | |
| return Math.ceil(maxXp / dailyXp.value); | |
| }); | |
| const totalGold30Days = computed(() => { | |
| return Math.floor(dailyGold.value * 30); | |
| }); | |
| const affordableItems = computed(() => { | |
| let gold = totalGold30Days.value; | |
| let count = 0; | |
| // Simple check: how many unique items could I buy one of? | |
| // Sort cheap to expensive | |
| const sortedSinks = [...sinks.value].sort((a,b) => a.cost - b.cost); | |
| for(let item of sortedSinks) { | |
| if(gold >= item.cost) { | |
| gold -= item.cost; | |
| count++; | |
| } | |
| } | |
| return count; | |
| }); | |
| // Chart instances | |
| let levelChartInstance = null; | |
| let economyChartInstance = null; | |
| const defaultPresets = { | |
| community: { | |
| actions: [ | |
| { name: '每日登录', xp: 10, gold: 5, dailyFreq: 1 }, | |
| { name: '发布帖子', xp: 50, gold: 10, dailyFreq: 0.2 }, | |
| { name: '点赞互动', xp: 5, gold: 2, dailyFreq: 5 }, | |
| { name: '被精选', xp: 200, gold: 50, dailyFreq: 0.05 }, | |
| { name: '邀请好友', xp: 100, gold: 30, dailyFreq: 0.1 } | |
| ], | |
| sinks: [ | |
| { name: '社区勋章', cost: 200 }, | |
| { name: '置顶卡', cost: 500 }, | |
| { name: '周边T恤', cost: 2000 } | |
| ], | |
| levelConfig: { maxLevel: 10, baseXp: 100, factor: 1.8 } | |
| }, | |
| rpg: { | |
| actions: [ | |
| { name: '击杀小怪', xp: 20, gold: 15, dailyFreq: 20 }, | |
| { name: '完成副本', xp: 500, gold: 300, dailyFreq: 1 }, | |
| { name: 'PVP胜利', xp: 100, gold: 50, dailyFreq: 3 }, | |
| { name: '出售装备', xp: 0, gold: 100, dailyFreq: 2 } | |
| ], | |
| sinks: [ | |
| { name: '生命药水', cost: 50 }, | |
| { name: '强化石', cost: 500 }, | |
| { name: '稀有坐骑', cost: 10000 } | |
| ], | |
| levelConfig: { maxLevel: 60, baseXp: 200, factor: 2.2 } | |
| }, | |
| education: { | |
| actions: [ | |
| { name: '完成作业', xp: 50, gold: 10, dailyFreq: 1 }, | |
| { name: '课堂发言', xp: 20, gold: 5, dailyFreq: 2 }, | |
| { name: '满分测验', xp: 100, gold: 50, dailyFreq: 0.2 }, | |
| { name: '阅读打卡', xp: 30, gold: 10, dailyFreq: 1 } | |
| ], | |
| sinks: [ | |
| { name: '免做卡', cost: 500 }, | |
| { name: '额外加分', cost: 1000 }, | |
| { name: '文具盲盒', cost: 300 } | |
| ], | |
| levelConfig: { maxLevel: 12, baseXp: 100, factor: 1.5 } | |
| } | |
| }; | |
| // Methods | |
| const toggleTheme = () => { | |
| isDark.value = !isDark.value; | |
| if (isDark.value) { | |
| document.documentElement.classList.add('dark'); | |
| } else { | |
| document.documentElement.classList.remove('dark'); | |
| } | |
| updateCharts(); | |
| }; | |
| const resetConfig = () => { | |
| if(confirm('确定要重置所有配置吗?')) { | |
| loadPreset('community'); | |
| } | |
| }; | |
| const loadPreset = (type) => { | |
| if (defaultPresets[type]) { | |
| const p = defaultPresets[type]; | |
| actions.value = JSON.parse(JSON.stringify(p.actions)); | |
| sinks.value = JSON.parse(JSON.stringify(p.sinks)); | |
| levelConfig.value = JSON.parse(JSON.stringify(p.levelConfig)); | |
| } | |
| }; | |
| const importConfig = (event) => { | |
| const file = event.target.files[0]; | |
| if (!file) return; | |
| const reader = new FileReader(); | |
| reader.onload = (e) => { | |
| try { | |
| const config = JSON.parse(e.target.result); | |
| if (config.actions) actions.value = config.actions; | |
| if (config.sinks) sinks.value = config.sinks; | |
| if (config.levelConfig) levelConfig.value = config.levelConfig; | |
| // Optionally simulation result, but that's computed | |
| alert('导入成功!'); | |
| } catch (err) { | |
| alert('文件格式错误,请上传有效的 JSON 配置文件。'); | |
| } | |
| }; | |
| reader.readAsText(file); | |
| // Reset input | |
| event.target.value = ''; | |
| }; | |
| const addAction = () => { | |
| actions.value.push({ name: '新行为', xp: 10, gold: 0, dailyFreq: 1 }); | |
| }; | |
| const removeAction = (index) => { | |
| actions.value.splice(index, 1); | |
| }; | |
| const addSink = () => { | |
| sinks.value.push({ name: '新商品', cost: 100 }); | |
| }; | |
| const removeSink = (index) => { | |
| sinks.value.splice(index, 1); | |
| }; | |
| const exportConfig = () => { | |
| const config = { | |
| actions: actions.value, | |
| sinks: sinks.value, | |
| levelConfig: levelConfig.value, | |
| simulationResult: { | |
| dailyXp: dailyXp.value, | |
| daysToMaxLevel: daysToMaxLevel.value | |
| } | |
| }; | |
| const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(config, null, 2)); | |
| const downloadAnchorNode = document.createElement('a'); | |
| downloadAnchorNode.setAttribute("href", dataStr); | |
| downloadAnchorNode.setAttribute("download", "gamification_design.json"); | |
| document.body.appendChild(downloadAnchorNode); | |
| downloadAnchorNode.click(); | |
| downloadAnchorNode.remove(); | |
| }; | |
| const updateCharts = () => { | |
| const ctxLevel = document.getElementById('levelChart'); | |
| const ctxEco = document.getElementById('economyChart'); | |
| if(!ctxLevel || !ctxEco) return; | |
| const textColor = isDark.value ? '#9ca3af' : '#4b5563'; | |
| const gridColor = isDark.value ? '#374151' : '#e5e7eb'; | |
| // Prepare Level Data | |
| const days = []; | |
| const xpProgress = []; | |
| const currentLevel = []; | |
| let accumulatedXp = 0; | |
| // Simulate day by day | |
| const simLimit = Math.min(simulationDays.value, 365); // Limit points to render | |
| const step = Math.max(1, Math.floor(simLimit / 50)); // Downsample for performance | |
| for(let d=0; d<=simLimit; d+=step) { | |
| days.push(`Day ${d}`); | |
| let xp = d * dailyXp.value; | |
| xpProgress.push(xp); | |
| // Find level | |
| let lvl = 1; | |
| for(let l of levelTable.value) { | |
| if(xp >= l.totalXp) { | |
| lvl = l.level; | |
| } else { | |
| break; | |
| } | |
| } | |
| currentLevel.push(lvl); | |
| } | |
| // Level Chart | |
| if(levelChartInstance) levelChartInstance.destroy(); | |
| levelChartInstance = new Chart(ctxLevel, { | |
| type: 'line', | |
| data: { | |
| labels: days, | |
| datasets: [ | |
| { | |
| label: '累计 XP', | |
| data: xpProgress, | |
| borderColor: '#6366f1', | |
| yAxisID: 'y', | |
| tension: 0.1 | |
| }, | |
| { | |
| label: '当前等级', | |
| data: currentLevel, | |
| borderColor: '#ec4899', | |
| yAxisID: 'y1', | |
| stepped: true, | |
| borderDash: [5, 5] | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| interaction: { mode: 'index', intersect: false }, | |
| scales: { | |
| x: { grid: { color: gridColor }, ticks: { color: textColor } }, | |
| y: { | |
| type: 'linear', display: true, position: 'left', | |
| title: { display: true, text: 'XP' }, | |
| grid: { color: gridColor }, ticks: { color: textColor } | |
| }, | |
| y1: { | |
| type: 'linear', display: true, position: 'right', | |
| title: { display: true, text: 'Level' }, | |
| grid: { drawOnChartArea: false }, ticks: { color: textColor } | |
| } | |
| } | |
| } | |
| }); | |
| // Economy Chart | |
| const goldProgress = days.map((_, idx) => idx * step * dailyGold.value); | |
| if(economyChartInstance) economyChartInstance.destroy(); | |
| economyChartInstance = new Chart(ctxEco, { | |
| type: 'bar', | |
| data: { | |
| labels: days, | |
| datasets: [{ | |
| label: '累计金币 (Cumulative Gold)', | |
| data: goldProgress, | |
| backgroundColor: '#eab308', | |
| borderRadius: 4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| x: { grid: { color: gridColor }, ticks: { color: textColor } }, | |
| y: { grid: { color: gridColor }, ticks: { color: textColor } } | |
| } | |
| } | |
| }); | |
| }; | |
| onMounted(() => { | |
| if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | |
| isDark.value = true; | |
| document.documentElement.classList.add('dark'); | |
| } else { | |
| isDark.value = false; // Default to light if system is light, but my CSS defaults to dark class manually added? No, let's sync. | |
| document.documentElement.classList.remove('dark'); | |
| } | |
| // Force dark mode default as per design pref | |
| isDark.value = true; | |
| document.documentElement.classList.add('dark'); | |
| updateCharts(); | |
| }); | |
| watch([actions, levelConfig, simulationDays, isDark], () => { | |
| updateCharts(); | |
| }, { deep: true }); | |
| return { | |
| isDark, toggleTheme, | |
| actions, sinks, levelConfig, simulationDays, | |
| addAction, removeAction, addSink, removeSink, exportConfig, | |
| dailyXp, dailyGold, daysToMaxLevel, totalGold30Days, affordableItems | |
| }; | |
| } | |
| }).mount('#app'); | |
| </script> | |
| </body> | |
| </html> | |