mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-30 23:23:03 +00:00 
			
		
		
		
	alternative optimize
This commit is contained in:
		| @@ -3,62 +3,46 @@ local Config = require('opus.config') | ||||
| local Util   = require('opus.util') | ||||
|  | ||||
| local function getConfig() | ||||
|     return Config.load('alternate', { | ||||
|         default = { | ||||
|             shell = 'sys/apps/shell.lua', | ||||
|             lua = 'sys/apps/Lua.lua', | ||||
|             files = 'sys/apps/Files.lua', | ||||
|         }, | ||||
|         choices = { | ||||
|             shell = { | ||||
|                 'sys/apps/shell.lua', | ||||
|                 'rom/programs/shell', | ||||
|             }, | ||||
|             lua = { | ||||
|                 'sys/apps/Lua.lua', | ||||
|                 'rom/programs/lua.lua', | ||||
|             }, | ||||
|             files = { | ||||
|                 'sys/apps/Files.lua', | ||||
|             } | ||||
|         } | ||||
|     }) | ||||
| 	return Config.load('alternate', { | ||||
| 		shell = { | ||||
| 			'sys/apps/shell.lua', | ||||
| 			'rom/programs/shell', | ||||
| 		}, | ||||
| 		lua = { | ||||
| 			'sys/apps/Lua.lua', | ||||
| 			'rom/programs/lua.lua', | ||||
| 		}, | ||||
| 		files = { | ||||
| 			'sys/apps/Files.lua', | ||||
| 		} | ||||
| 	}) | ||||
| end | ||||
|  | ||||
| local Alt = { } | ||||
|  | ||||
| function Alt.get(key) | ||||
|     return getConfig().default[key] | ||||
| 	return getConfig()[key][1] | ||||
| end | ||||
|  | ||||
| function Alt.set(key, value) | ||||
|     Alt.addChoice(key, value) | ||||
|  | ||||
|     local config = getConfig() | ||||
|     config.default[key] = value | ||||
|     Config.update('alternate', config) | ||||
| 	local config = getConfig() | ||||
| 	Array.removeByValue(config[key], value) | ||||
| 	table.insert(config[key], 1, value) | ||||
| 	Config.update('alternate', config) | ||||
| end | ||||
|  | ||||
| function Alt.remove(key, value) | ||||
|     local config = getConfig() | ||||
|  | ||||
|     Array.removeByValue(config.choices[key], value) | ||||
|     if config.default[key] == value then | ||||
|         config.default[key] = config.choices[key][1] | ||||
|     end | ||||
|     Config.update('alternate', config) | ||||
| 	local config = getConfig() | ||||
| 	Array.removeByValue(config[key], value) | ||||
| 	Config.update('alternate', config) | ||||
| end | ||||
|  | ||||
| function Alt.addChoice(key, value) | ||||
|     local config = getConfig() | ||||
|  | ||||
|     if not config.choices[key] then | ||||
|         config.choices[key] = { } | ||||
|     end | ||||
|     if not Util.contains(config.choices[key], value) then | ||||
|         table.insert(config.choices[key], value) | ||||
|         Config.update('alternate', config) | ||||
|     end | ||||
| function Alt.add(key, value) | ||||
| 	local config = getConfig() | ||||
| 	if not Util.contains(config[key], value) then | ||||
| 		table.insert(config[key], value) | ||||
| 		Config.update('alternate', config) | ||||
| 	end | ||||
| end | ||||
|  | ||||
| return Alt | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com