Commits

Anonymous committed f233dfa

fix cupid to actually run at all in 0.9.0, fix unicode input

  • Participants
  • Parent commits 138fcdf

Comments (0)

Files changed (1)

 local main_args = {...}
 
 local wraped_love = {}
-local cupid_stubs = {}
 local game_funcs = {}
-local protected_funcs = {'update','draw','keyreleased','keypressed','load'}
+local protected_funcs = {'update','draw','keyreleased','keypressed','textinput','load'}
+local _love
 local function protector(table, key, value)
 	for k,v in pairs(protected_funcs) do
 		if ( v == key ) then
 			return
 		end
 	end
-	rawset(table, key, value)
+	rawset(_love, key, value)
 end
 
 local mods = {}
 	g.pop()
 end
 
-local _love
 local function cupid_load(args)
 	local use = true
 
 	if use then
-		setmetatable(cupid_stubs, {__index = love})
-		setmetatable(wraped_love, {__index = cupid_stubs, __newindex = protector})
+		setmetatable(wraped_love, {__index = love, __newindex = protector})
 		_love = love
 		love = wraped_love
 		for k,v in pairs(protected_funcs) do
-			cupid_stubs[v] = function(...)
+            _love[v] = function(...)
 				if g == nil then g = love.graphics end
 				local result = {}
 				local arg = {...}
 			g.print("> " .. self.buffer .. "_", xo - 1, self.height - es - 1)
 		end)
 	end,
-	["pre-keypressed"] = function(self, key, unicode)
-		self.lastkey = unicode
-		if key == config.console_key then 
-			self:toggle()
-			return false
-		end
-
+	["pre-keypressed"] = function(self, key, isrepeat)
 		if not self.shown then return true end
 		
-		if unicode == 13 or unicode == 10 then
-			if ( #self.buffer > 0 ) then
-				self:command(self.buffer)
-				self.buffer = ""
-			else
-				self:toggle()
-			end
-		elseif unicode == 127 or unicode == 8 then
-			self.buffer = self.buffer:sub(0, -2)
-		elseif #key == 1 then
-			self.buffer = self.buffer .. string.char(unicode)
-		elseif key == "up" then
+		if key == "up" then
 			if self.history_idx < #self.history then
 				self.history_idx = self.history_idx + 1		
 				self.buffer = self.history[self.history_idx]
 		return false
 	end,
 	["pre-keyreleased"] = function(self, key)
-		if key == "escape" and self.shown then
+		if key == config.console_key then 
+			self:toggle()
+			return false
+         elseif key == "return" then
+			if ( #self.buffer > 0 ) then
+				self:command(self.buffer)
+				self.buffer = ""
+			else
+				self:toggle()
+			end
+         elseif key == "backspace" then
+			self.buffer = self.buffer:sub(0, -2)
+         elseif key == "escape" and self.shown then
 			self:toggle()
 			return false
 		end
 		if self.shown then return false end
 	end,
+	["pre-textinput"] = function(self, text)
+		if not self.shown then return true end
+        if text ~= config.console_key then
+           self.buffer = self.buffer .. text
+        end
+		return false
+	end,
 	["command"] = function(self, cmd)
 		self.history_idx = 0
 		table.insert(self.history, 1, cmd)
 		self.shown = not self.shown 
 		if config.console_key_repeat then
 			if self.shown then
-				self.keyrepeat = {love.keyboard.getKeyRepeat()}
-				love.keyboard.setKeyRepeat(0.75,0.075)
+				self.keyrepeat = love.keyboard.hasKeyRepeat()
+				love.keyboard.setKeyRepeat(true)
 			elseif self.keyrepeat then
-				love.keyboard.setKeyRepeat(unpack(self.keyrepeat))
+				love.keyboard.setKeyRepeat(self.keyrepeat)
 				self.keyrepeat = nil
 			end
 		end
 	["scan"] = function(self)
 		local out = {}
 		local function scan(where)
-			local list = love.filesystem.enumerate(where)
+			local list = love.filesystem.getDirectoryItems(where)
 			for k,v in pairs(list) do
 				local file = where .. v
 				if not love.filesystem.isFile(file) then