Page 2 of 6
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 12:25 pm
by Elvashi
Luac exists as a specific solution for specific problems, by and large you shouldn't ever have to actually use it, and doing so is advised against, as it negates several of Lua's advantages (both in the toolchain, and at runtime) for very little gain.
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 5:23 pm
by pygy
Back to the topic, I'm currently working on Unicode support, patterns and multiple assignments.
Here's an example :
Code: Select all
Polygamy.keyboard.add("calculator", {
[ { "+", "-", "*" "/", ".", "return", "c" "%d" } ] = function(k) calculator.send(k) end
})
And a basic Xwing clone could see it's input written like this:
Code: Select all
Polygamy.keyboard.add("X-Wing",{
[ "[1-4]" ] = function(s) spaceShip.setSpeed(s+0) end,
[ "[5-8]" ] = function(w) spaceShip.setWeapon(w-4) end,
[ { [[ %arrows ]], "[WASD]"} ] = { held = function(k,dt) spaceShip.move(k,dt) end },
[" "] = {
pressed = spaceship.shoot,
held = function(k,dt) spaceShip.accumulateEnergy(dt) end,
released = spaceShip.unleashBigBlow
},
b = spaceShip.launchBomb
escape = game.quit
})
I'm also thinking of adding a new constants: Polygamy.before that will catch all keys before it's sent down the road. Good for logging.
Polygamy.keybaord is actually becoming a keyboard definition DSL. I like that.
Now it's time to debug.
Next up: serialization to allow the possibility of saving the configuration.
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 5:27 pm
by Robin
If you use pattern matching, I don't think the calculator example will work. I think you should change it to this:
Code: Select all
Polygamy.keyboard.add("calculator", {
[ { "\+", "\-", "\*" "/", "\.", "return", "c" "%d"}] = function(k) calculator.send(k) end
})
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 5:35 pm
by pygy
No, I'm using custom patterns, with a hand made parser. Their syntax is based on the standard Lua one, but it's more limited and more capable at the same time. Currently %a, %d, %w, %arrows, [0-9], [a-z] and [whatever,one_key-at/a.time!including+restricted*characters] are supported, but with only one pattern per string.
The point is to make the common case easy, and to keep the code readable.
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 5:42 pm
by Robin
Oh, that's awesome.
Would that mean that one would be able to represent the example code as:
Code: Select all
Polygamy.keyboard.add("calculator", {
[ { "[+-*return.c/]", "%d"}] = function(k) calculator.send(k) end
})
?
(btw, I made a mistake earlier: in Lua, special characters in patterns are escaped with %, not \. I apologize to anyone I might have offended. Such as bartbes.)
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 5:49 pm
by pygy
You could do
Code: Select all
[ { "[+-*.c/]", "return", "%d" } ] = calculator.send
Your example would blindly assign the r, e, t, u, r, and n keys to the same function.
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 6:15 pm
by Robin
pygy wrote:Your example would blindly assign the r, e, t, u, r, and n keys to the same function.
Woops
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Fri Jan 29, 2010 6:38 pm
by mikembley
I've only skimmed through all of these posts, But from what i see this seems helpful
The reason i posted is because i saw a reference to the Lost Vikings! I loved that game as a child! Required plenty of strategic skill and logic unlike all these next gen titles which are so linear and mindnumbing...
Keep up the good work
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Mon Feb 01, 2010 2:12 am
by Geti
Robin wrote:The whole point of Lua is that you don't have to compile it to make it work.
I know, i just find it nicer to have compiled libs but i'm not going to push the issue
This lib keeps getting better and better though, keep it up
Re: Pölygamy: a collection of LÖVE helper libraries
Posted: Wed Feb 03, 2010 6:53 pm
by pygy
v 0.3.1 is online (see first post) and it works !!
The most important new features is the keyboard-based patterns expansions (see below for examples). To make this more useful, the coordinates of each keys are now passed to the bound functions along the key string and unicode number if relevant. They only work properly on US qwerty keyboards, due to a current limitation of LÖVE itself. It can still be useful if you target the subset common to qwerty,qwertz and azerty (sorry, Dvorak users
)
Code: Select all
Polygamy.keyboard.add("function keys",{
[ "[f1-f5]" ]=function(key,row,column,unicode) engine.throttle(column) end
}
v0.3.1 (2010/02/03)
- First working version published .
- [q-r] => {q, w, e, r} (horizontal). -- [x-5] => {x, d, r, 5} (diagonal) -- [6-h] => {6, y, h} (vertical) -- [f1-f10] => {f1, f2, ... , f10} -- Assumes an US qwerty keyboard at the moment.
- Simplified the callbacks a bit.
- Don't use doto().replaceWith() at the moment (there's a known bug regarding inheritance preservation).
v0.3 (2010/02/02)
- /!\ Still not tested (and completely broken)
- TypeMatic (key repeat).
- Unicode.
- Track the active context (to reset options).
- Reset options on doto actions.
- Pattern matching.
- pass key coordinates to all callbacks.
- "Before" blocks.
- Extensive code documentation.
[/size]
Some corner cases may still be problematic, of course, but it should be usable as is for most purposes.
Have fun