瀏覽代碼

change `:: ModManager` to be more flexible

Stephan Fuchs 2 月之前
父節點
當前提交
4359936ba5
共有 1 個文件被更改,包括 14 次插入18 次删除
  1. 14 18
      sugarcube/src/start/index.tw

+ 14 - 18
sugarcube/src/start/index.tw

@@ -102,24 +102,20 @@
 <<image "system/1_openings/splashes/splash#.jpg" 1 14>>
 
 :: ModManager[menu]
-	<<set _existingMods = {cheatmenu:{'label':'CheatMenu','description':'Adds a cheat menu. You can reach it ingame via the menu-button ingame.','path':'mod_cm.html'}}>>
+	<<set _modPaths = JSON.parse(localStorage.getItem('modPaths') || '[]')>>
+	<<set _modPathsDisplay = _modPaths.join('\n')>>
 
-	<<set _currentModSettings = JSON.parse(localStorage.getItem("glife_mods") || "{}")>>
-	<<run console.log("CurrentModSettings",_currentModSettings)>>
-
-	<<for _modId,_modData range _existingMods>>
-		<<set _existingMods[_modId].enabled = (_currentModSettings[_modId]?.enabled === true)>>
-		<p><<checkbox `"_existingMods['"+_modId+"'].enabled"` false true autocheck>>_modData.label : _modData.description</p>
-	<</for>>
+	<<textarea "_modPathsDisplay" _modPathsDisplay>>
 
+	<<button 'Apply'>>
+		<<set _modPaths = _modPathsDisplay.split(/\r?\n|\r|\n/g)>>
+		<<set _modPaths = _modPaths.map((raw)=>raw.trim()).filter((path)=>path!='')>>
+		<<if _modPaths.length>>
+			<<run localStorage.setItem('modPaths',JSON.stringify(_modPaths))>>
+		<<else>>
+			<<run localStorage.setItem('modPaths',"[]")>>
+		<</if>>
+		<<run location.reload()>>
+	<</button>>
 
-	<<button 'Confirm'>>
-		<<set _enabledMods = {}>>
-		<<for _modId,_modData range _existingMods>>
-			<<if _modData.enabled>>
-				<<set _enabledMods[_modId] = {enabled: true, path: _modData.path}>>
-			<</if>>
-		<</for>>
-		<<run localStorage.setItem("glife_mods",JSON.stringify(_enabledMods))>>
-		<<run location.reload(true)>>
-	<</button>>
+	<<link "Back">><<goto "index">><</link>>