Code Search for Developers
 
 
  

Select.java from Riot in Emerald city at Krugle


Show Select.java syntax highlighted

/*
 * Copyright (C) 2001-2005 Pleasant nightmare studio
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.pleasantnightmare.riotinecity.console;

import com.jme.scene.Spatial;
import org.pleasantnightmare.riotinecity.spatials.InteractibleNode;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Selects InteractibleNode into context, allowing easier calling of
 * its methods.
 *
 * @author deus
 * @version 1.0
 * @since Apr 9, 2007 6:28:57 PM
 */
public class Select extends InputProcessor {
    public static final String COMMAND = "sel";
    private static final Pattern INPUT = Pattern.compile(COMMAND + " (.+)");
    private static final String SELECT_NONE = "none";

    public void process(String input) throws ProcessingError {
        Matcher m = INPUT.matcher(input);
        if (!m.matches())
            throw new ProcessingError("Bad command usage. See help.");
        else
            engine.select(findInteractible(m.group(1)));
    }

    private InteractibleNode findInteractible(String name) throws ProcessingError {
        if (name.equals(SELECT_NONE))
            return null;

        Spatial spatial = rootNode.getChild(name);
        if (spatial == null || !isInteractible(spatial))
            throw new ProcessingError("Not an Interactible: " + name);
        else
            return (InteractibleNode) spatial;
    }

    private boolean isInteractible(Spatial calledSpatial) {
        // Fast test first, then reflective cast
        return calledSpatial.getType() == Spatial.NODE
                && calledSpatial instanceof InteractibleNode;
    }

    public boolean isProcessable(String input) {
        return input.trim().startsWith(COMMAND);
    }

    public String getCommand() {
        return COMMAND;
    }
}




See more files for this project here

Riot in Emerald city

Cyberpunk third-person 2100. noir RPG thriller using JMonkey. Its going to be mix between Bloodnet, Neuromancer, DeusEx in gameplay, with pieces of Uplink and many other mini-games for dealing with variety of tasks (lockpicking, hacking...)

Project homepage: http://sourceforge.net/projects/riot-in-ecity
Programming language(s): Java,XML
License: other

  ActionList.java
  Call.java
  ConsoleEngine.java
  ConsoleModel.java
  ConsoleSpatial.java
  ConsoleToggleAction.java
  Help.java
  InputProcessor.java
  ProcessingError.java
  Select.java
  Test.java