Glove: LÖVE Compatibility Library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
slime
Solid Snayke
Posts: 3156
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Glove: LÖVE Compatibility Library

Post by slime »

SiENcE wrote: * getColorMode and setColorMode needs to be added.

I dunno how to emulate this. Any hints!?
viewtopic.php?f=4&t=76678&p=158643#p158643
User avatar
SiENcE
Party member
Posts: 795
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Glove: LÖVE Compatibility Library

Post by SiENcE »

Thx slime. Just found it by myself ... sorry for wasting your time :).
User avatar
SiENcE
Party member
Posts: 795
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Glove: LÖVE Compatibility Library

Post by SiENcE »

I updated the compatibility lib for 0.8.0 -> 0.9.0.

fixed:
- iSupported
- getColorMode/setColorMode dummy

Still some issues: SpriteBatch not working.

Code: Select all

--The "modulate" ColorMode was the default in 0.8.0, and its functionality (multiplying the current color with the texture) is still the default in 0.9.0.
--The effects of the "replace" ColorMode can be duplicated by calling love.graphics.setColor(255, 255, 255).
--
-- spriteBatch does not work correct!
--
--The "combine" ColorMode can be duplicated via a pixel shader. The shader code would look something like this:
--CODE: SELECT ALL
--shader = love.graphics.newShader[[
--vec4 effect(vec4 vcolor, Image texture, vec2 texcoord, vec2 pixcoord)
--{
--    vec4 texcolor = Texel(texture, texcoord);
--    return vec4(texcolor.rgb + vcolor.rgb - vec3(0.5), texcolor.a);
--}
--]]
math.randomseed(os.time())
math.random()
math.random()

love.filesystem.mkdir = love.filesystem.createDirectory
love.filesystem.enumerate = love.filesystem.getDirectoryItems

if love.audio then
  love.audio._newSource = love.audio.newSource

  love.audio.newSource = function(a, b)
  local s
    if b == 'static' then
      s = love.audio._newSource(a, 'static')
    else
      s = love.audio._newSource(a)
    end
   
    local mt = getmetatable(s)
    mt.__index.setDistance = s.setAttenuationDistances
    mt.__index.getDistance = s.getAttenuationDistances
    return s
  end
end

if love.mouse then
  love.mouse.setGrab = love.mouse.setGrabbed
end

if love.timer then
  love.timer.getMicroTime = love.timer.getTime
end

if love.graphics then
  love.graphics.checkMode = function(width, height, fullscreen)
    if fullscreen == false then
      return true
    else
      for i, v in ipairs(love.window.getFullscreenModes()) do
        if width == v.width and height == v.height then
          return true
        end
      end
      return false
    end
  end

  love.graphics.toggleFullscreen = function()
    return love.window.setFullscreen(not love.window.getFullscreen())
  end

  love.graphics.setLine = function(a, b)
    love.graphics.setLineWidth(a)
    love.graphics.setLineStyle(b or 'smooth')
  end

  love.graphics.setPoint = function(a, b)
    love.graphics.setPointSize(a)
    love.graphics.setPointHeight(b)
  end

  love.graphics.setMode = function ( width, height, fullscreen, vsync, fsaa )
    local flags = {} 
    if fullscreen ~= nil then
      flags.fullscreen = fullscreen
    end 
    if vsync ~= nil then
      flags.vsync = vsync
    end 
    if fsaa ~= nil then
      flags.fsaa = fsaa
    end
    love.window.setMode(width, height, flags)
  end

  love.graphics.setIcon = function(a)
    if a:type() == 'Image' then
      a = a:getData()
    end
    love.window.setIcon(a)
  end

  love.graphics._isSupported = love.graphics.isSupported
  function love.graphics.isSupported(...)
    local t = {...}
    for k, v in pairs(t) do
      if v == 'pixeleffect' then
        t[k] = 'shader'
      end
    end
    return love.graphics._isSupported(unpack(t))
  end

  love.graphics.getMode = function()
    local w, h, flags = love.window.getMode()
    return w, h, flags.fullscreen, flags.vsync, flags.fsaa
  end

  love.graphics.newPixelEffect = function(a) return love.graphics.newShader(a) end
  love.graphics.setPixelEffect = love.graphics.setShader
  love.graphics.getPixelEffect = love.graphics.getShader
  love.graphics.getModes = love.window.getFullscreenModes
  love.graphics.quad = love.graphics.polygon
  love.graphics.triangle = love.graphics.polygon
  love.graphics.newStencil = function(a) return a end
  love.graphics.setCaption = love.window.setTitle
  love.graphics.getCaption = love.window.getTitle
  love.graphics.hasFocus = love.window.hasFocus
  love.graphics.isCreated = love.window.isCreated
  love.graphics.setDefaultImageFilter = love.graphics.setDefaultFilter

  love.graphics._newParticleSystem = love.graphics.newParticleSystem

  love.graphics.newParticleSystem = function(...)
    local ps = love.graphics._newParticleSystem(...)
    local mt = getmetatable(ps)
    local sizevariation = mt.__index.setSizeVariation
    mt.__index.setSizeVariation = function(self, min, max)
      if max then
        sizevariation(self, math.min(math.max(min, 0), 1), math.min(math.max(max, 0), 1))
      else
        sizevariation(self, math.min(math.max(min, 0), 1))
      end
    end
    mt.__index.setSprite = ps.setImage 
    mt.__index.setGravity = ps.setLinearAcceleration
    mt.__index.setLifetime = ps.setEmitterLifetime
    mt.__index.setParticleLife = ps.setParticleLifetime
    mt.__index.count = ps.getCount
    mt.__index.isEmpty = function() return ps.count(ps) == 0 end
    mt.__index.setGravity = function(self, min, max) self:setLinearAcceleration(0, min, 0, max) end
    --mt.__index.isFull = function() return false end
    return ps
  end

  love.graphics._newQuad = love.graphics.newQuad
  love.graphics.newQuad = function(x, y, width, height, sw, sh)
    local quad =  love.graphics._newQuad(x, y, width, height, sw, sh)
    return {sw, sh, quad, flip = function(self, h, v)
        if h then
          local x, y, w, h = self[3]:getViewport()
          x = -x-w
          self[1] = -self[1]
          self[3]:setViewport(x, y, w, h, self[1], self[2])
        end
        if v then
          local x, y, w, h = self[3]:getViewport()
          y = -y-h
          self[2] = -self[2]
          self[3]:setViewport(x, y, w, h, self[1], self[2])
        end
      end,
      setViewport = function(self, x, y, w, h) self[3]:setViewport(x, y, w, h) end,
      getViewport = function(self) return self[3]:getViewport() end
    }
  end

  love.graphics.drawq = function(image, quad, ...)
    love.graphics.draw(image, quad[3], ...)
  end

  love.graphics._newSpriteBatch = love.graphics.newSpriteBatch
  love.graphics.newSpriteBatch = function(...)
    local sb = love.graphics._newSpriteBatch(...)
    local mt = getmetatable(sb)
    mt.__index.addq = function(self, quad, x, y, r, sx, sy, ox, oy, kx, ky)
      self.add(self, quad[3], x, y, r, sx, sy, ox, oy, kx, ky)
    end
    mt.__index.setq = function(self, id, quad, x, y, r, sx, sy, ox, oy, kx, ky)
      self.set(self, id, quad[3], x, y, r, sx, sy, ox, oy, kx, ky)
    end
    return sb
  end
end

if love.joystick then
  love.joystick.getNumJoysticks = love.joystick.getJoystickCount
  local __joysticks = love.joystick.getJoysticks()
  love.joystick.isDown = function(i) if __joysticks[i] then return __joysticks[i]:isDown() else return false end end
  love.joystick.getAxes = function(i) if __joysticks[i] then return __joysticks[i]:getAxes() else return 0 end end
  love.joystick.getAxis = function(i) if __joysticks[i] then return __joysticks[i]:getAxis() else return 0 end end
  love.joystick.getHat = function(i) if __joysticks[i] then return __joysticks[i]:getHat() end end
  love.joystick.getName = function(i) if __joysticks[i] then return __joysticks[i]:getName() end end
  love.joystick.getNumAxes = function(i) if __joysticks[i] then return __joysticks[i]:getNumAxes() else return 0 end end
  love.joystick.getNumButtons = function(i) if __joysticks[i] then return __joysticks[i]:getNumButtons() else return 0 end end
  love.joystick.getNumHats = function(i) if __joysticks[i] then return __joysticks[i]:getNumHats() else return 0 end end
  --love.joystick.isOpen = function() return true end
  --love.joystick.open = function() end
  --love.joystick.close = function() end
end

love.graphics.getColorMode = function() end
love.graphics.setColorMode = function() end
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Glove: LÖVE Compatibility Library

Post by Positive07 »

I think that the most difficult part to make backwards compatible is love.thread since probably you would have to require the compatibility file in the thread too (and intercept the requires of love functions) but that library SiENcE posted is great
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
SiENcE
Party member
Posts: 795
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Glove: LÖVE Compatibility Library

Post by SiENcE »

It was first posted by 'Santos'.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Glove: LÖVE Compatibility Library

Post by Positive07 »

You are right! LÖVE Compatibility Library by Santos (Updated by SiENcE) would do better :awesome:

I was thinking and it might be posible to implement the thread thing by changing the new thread to run a file (not the real file that you told it), store the thread in a table and add a parameter to the table with the file that was passed to the thread, on thread start you create a channel just for that thread(again you store it in the table) and pass the file that you will load in the thread.

Then when calling thread:send/receive/etc it would do it through the channel stored in that thread table (object?).

You could also use love.thread.getCount by getting the number of threads in the table.

The file on the thread will define thread:send, receive, etc using the channel loaded and demand the first argument sended that would be the file that it needs to load, you could do require or filesyste.load that file and when it calls the functions thread:send it would be calling channel:send instead

It's just an idea thought, and it would need some more thought to implement it :o:
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Glove: LÖVE Compatibility Library

Post by Positive07 »

Hello, I'm sorry to revive this thread, I want to know how you would implement love.keyboard.[g/s]etKeyRepeat, before two arguments were passed to it, delay and interval, now just the boolean enable is used, should I ignore the delay and interval and just pass true or false? what should I do with this values?
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests