Hi,
as I recently posted, I need to subclass some of the original Slick classes, StateBasedGame is the most important one. In this class, I had to override the
update and
render methods, which are declared as final - why?
To circumvent this problem, I had to copy the files from the SVN and midified them accordingly - a pretty ugly solution as I think : D
Additionally, some methods in Input like these would be nice:
Returns the controller id for a device name
Code:
public int getControllerID(final String name) {
int id = 0;
for (final Controller c : Input.controllers) {
if (c.getName().equals(name)) {
return id;
}
++id;
}
return Integer.MIN_VALUE;
}
Returns the name of the controller which has this ID
Code:
public String getControllerName(final int controller) {
if (controller > Input.controllers.size()) {
throw new IllegalArgumentException("Controller " + controller + " does not exist!");
}
return (Input.controllers.get(controller)).getName();
}
Returns true if there is such a controller
Code:
public boolean hasController(final String name) {
for (final Controller c : Input.controllers) {
if (c.getName().equals(name)) {
return true;
}
}
return false;
}
Returns all controllers
Code:
public List<Controller> getControllers() {
return Input.controllers;
}
Gets the controller which has this name
Code:
public Controller getController(final String deviceName) {
for (final Controller c : Input.controllers) {
if (c.getName().equals(deviceName)) {
return c;
}
}
throw new IllegalArgumentException("This controller does not exist!");
}
Reloads the controllers, the first if clause was removed
Code:
public void reinitControllers() throws SlickException {
controllersInited = true;
try {
Controllers.create();
int count = Controllers.getControllerCount();
for (int i = 0; i < count; i++) {
Controller controller = Controllers.getController(i);
if ((controller.getButtonCount() >= 3) && (controller.getButtonCount() < MAX_BUTTONS)) {
controllers.add(controller);
}
}
Log.info("Found "+controllers.size()+" controllers");
for (int i=0;i<controllers.size();i++) {
Log.info(i+" : "+((Controller) controllers.get(i)).getName());
}
} catch (LWJGLException e) {
if (e.getCause() instanceof ClassNotFoundException) {
throw new SlickException("Unable to create controller - no jinput found - add jinput.jar to your classpath");
}
throw new SlickException("Unable to create controllers");
} catch (NoClassDefFoundError e) {
// forget it, no jinput availble
}
}
KM