Adam's Lair Forum

game development and casual madness
It is currently 2017/04/28, 02:20

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: [Plugin] Input Mapping
PostPosted: 2016/06/14, 21:06 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
(edit - 2017.04.01.: this description is outdated, but I choose to keep it for historical purposes. The current status of the project and instructions can be found in the fresh posts in this topic, and on GitHub.)

Hey,
This weekend's project was something for Duality, a keyboard mapping / input manager plugin. It's a feature that most engines out there have, definitely useful, and relatively straightforward, and last, but not least I had good time working on it, so if you don't really have any free-time activity nowdays, Duality plugin development is something I'd recommend :]

Usage
Under 'View' menu, there's a new entry called 'Input Mapping'. It spawns a new editor window, which can be snapped, docked and positioned like any other. In that menu, you need to add and name the so called Virtual Buttons, then assign physical keys to them. Do this by selecting the key's name in the drop down list next to the green plus icon, then clicking the icon. The assigned keys can be removed by clicking the red minus icon, or they can be modified just by The plugin saves these changes automatically to the 'keyMapping.res' resource file, which you need to ship with the project.

Image


If the Virtual Buttons are created, you can refer to them in the code by their name. Notice, that first you need to add the assembly to the Visual Studio project as a reference.

Example:
Code:
using MFEP.Duality.Plugins.InputPlugin;

Vector2 direction = Vector2.Zero;
if (InputManager.IsButtonPressed("Right")) //Right is the Virtual Button's name
{
    direction += Vector2.UnitX;
}

There are also IsButtonHit and IsButtonReleased methods available.

Known Issues
  • At the moment, the user can assing new VirtualButtons to the InputManager via code. These changes do not reflect in the editor window. The user might need to do this (in game keybinding management for example), so it'd be nice to implement this.
  • FIXED Multiple instances of the single key cannot be added to the same Virtual Button, but if the user changes an existing key, the program allows the same key. This leads to weird behaviour, thus needs to be fixed.

What's next
The plugin is not tested extensively, I'd be grateful if I got any help on this. The above mentioned bugs need to be fixed, and a package should be released (although I don't really know how that stuff works)
As always, input (and some testing) is most appreciated! :]

Github


Last edited by loeller on 2017/04/01, 23:30, edited 3 times in total.

Top
 Profile  
 
PostPosted: 2016/06/14, 22:51 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1949
Location: Germany
Role: Professional
Nice ^^ Something like this is indeed missing in Duality. As soon as you're ready for a stable release, make sure to add your plugin to the list of community projects!

Gave it a short test, added numpad key controls and all seems to be working as expected. Are you planning to add support for mapping input across Gamepad / Joystick / Mouse as well?

Quickly glanced over some code and found that you're essentially using a dummy resource to load and save your settings. You don't actually need to do this though :) If you just quickly want to save or load some data that is not part of the content system, you can do this:

Code:
Foo obj = ...;
Serializer.WriteObject(obj, "file.xyz", typeof(XmlSerializer));
Foo obj = Serializer.TryReadObject<Foo>("file.xyz");


Congratulations to your first Duality plugin btw!

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2016/06/15, 18:47 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
Thanks for the feedback!
Adam wrote:
Are you planning to add support for mapping input across Gamepad / Joystick / Mouse as well?

Yeah, I've been thinking about this stuff, and I don't want to implement gamepad support just for the digital gamepad buttons. Instead, a proper handling for analogue controls would be necessary, which is not in the scope until the current system is cleaned up.
Although including the mouse buttons is a good - if not a neccessary step. Just forgot about them... :redface:
Thank you for the code snippet too :]


Top
 Profile  
 
PostPosted: 2016/06/17, 10:42 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
Fixed some bugs, and marked the button-adding interface internal until proper communication is built between the ui and the core plugin.
Also uploaded the nuget packages. They can be downloaded in the Duality package manager, but it does not copy the .dll-s to the Plugins folder, although I tagged the packages accordingly (Duality Core/Editor Plugin ...). Can someone point me what I'm doing wrong?
Thanks in advance :]


Top
 Profile  
 
PostPosted: 2016/06/17, 10:58 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1949
Location: Germany
Role: Professional
I've downloaded the package and extracted it to have a look at the nuspec file, since I couldn't find it in your github repo. Not sure if it has been altered by the building process, but apparently there are no files defined in it?

Code:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>MFEP.Duality.Plugins.InputPlugin</id>
    <version>1.0.0</version>
    <title>InputPlugin (Core)</title>
    <authors>Lőrinc Serfőző</authors>
    <owners>Lőrinc Serfőző</owners>
    <licenseUrl>https://raw.githubusercontent.com/mfep/Duality.InputPlugin/master/LICENSE</licenseUrl>
    <projectUrl>https://github.com/mfep/Duality.InputPlugin</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/mfep/Duality.InputPlugin/master/icon_keyboard.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Keyboard abstraction plugin for Duality game engine.</description>
    <summary>Keyboard abstraction plugin for Duality game engine.</summary>
    <releaseNotes>Initial release.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>Duality Core Plugin Keyboard Input Manager Abstraction</tags>
    <dependencies>
      <dependency id="AdamsLair.Duality" version="2.0.0" />
    </dependencies>
  </metadata>
</package>

To get an idea on how to define the files for a package, take a look at some of the official nuspecs, this one for example.

If you did define the file correctly, which I'd assume because the dll is actually in the lib folder, then I'm not entirely sure what's wrong. Can you share your original nuspec files?

Edit: Okay, so I debugged this with my local source version of Duality an when investigating your packages, they do have the Duality tag, along with Keyboard, Input, etc., but they do not have the Plugin tag. This makes the package manager think it's a non-plugin binary and so it ends up in the main directory. In the nuspec I retrieved, there does seem to be a Plugin tag... same for the NuGet gallery entry. But when asking the NuGet library at runtime, it's just not there. "Core" is missing too, but that's not actually vital.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2016/06/17, 11:42 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
Hmm, the original .nuspec files are in the CorePlugin and EditorPlugin folders on github, but these are different from the embedded ones, since I modified them using nuget.org's online editor (adding tags, etc). I suppose this is the problem, so now will edit the original .nuspec files, create the packages with them, push to nuget.org and see what happens

Edit: The weird thing is, that even though the .nuspec contains the <files> element, after processing it using the command nuget pack InputPlugin.core.nuspec, the created .nupkg does not contain them.

Edit of edit: The former stuff is true for the other Duality .nupkg-s so I guess it's normal, and not a failure.


Top
 Profile  
 
PostPosted: 2016/06/17, 12:02 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
Now it seems to be working. Thanks for the quick help :]


Top
 Profile  
 
PostPosted: 2016/06/17, 12:13 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1949
Location: Germany
Role: Professional
Great! And good thinking with the online editor as potential cause for the tags problem. I was about to take a deep-dive into the NuGet.Core source code and trust me, I'm very glad your quick solution spared me of that :D

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2016/06/24, 09:36 
Veteran Member
Veteran Member
User avatar

Joined: 2015/10/04, 15:48
Posts: 153
Location: Germany
Role: Hobbyist
Wow! Great job! :)

_________________
Twitter | GitHub | Join Duality on Discord | itch.io


Top
 Profile  
 
PostPosted: 2016/06/24, 11:49 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 144
Location: Budapest
Role: Hobbyist
Cross wrote:
Wow! Great job! :)

Thank you! :]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group