More progress.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3936 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-10 04:02:32 +00:00
parent ca66f91ac7
commit 600a74ee39
11 changed files with 314 additions and 116 deletions
@@ -82,7 +82,7 @@ import com.threerings.crowd.chat.data.UserSystemMessage;
* messaging.
*/
public class ChatDirector extends BasicDirector
implements ChatCodes, LocationObserver, MessageListener
implements LocationObserver, MessageListener
{
/**
* Creates a chat director and initializes it with the supplied
@@ -94,7 +94,8 @@ public class ChatDirector extends BasicDirector
* @param bundle the message bundle from which we obtain our
* chat-related translation strings.
*/
public ChatDirector (CrowdContext ctx, MessageManager msgmgr, String bundle)
public function ChatDirector (
ctx :CrowdContext, msgmgr :MessageManager, bundle :String)
{
super(ctx);
@@ -111,7 +112,7 @@ public class ChatDirector extends BasicDirector
Log.warning("Null bundle or message manager given to ChatDirector");
return;
}
MessageBundle msg = _msgmgr.getBundle(_bundle);
var msg :MessageBundle = _msgmgr.getBundle(_bundle);
registerCommandHandler(msg, "help", new HelpHandler());
registerCommandHandler(msg, "clear", new ClearHandler());
registerCommandHandler(msg, "speak", new SpeakHandler());
@@ -728,7 +729,7 @@ public class ChatDirector extends BasicDirector
* @return {@link ChatCodes#SUCCESS} if the message was delivered or a
* string indicating why it failed.
*/
protected String deliverChat (
internal String deliverChat (
SpeakService speakSvc, String message, byte mode)
{
// run the message through our mogrification process
@@ -1044,114 +1045,6 @@ public class ChatDirector extends BasicDirector
protected ChatMessage _message;
}
/** Implements <code>/help</code>. */
protected class HelpHandler extends CommandHandler
{
public String handleCommand (
SpeakService speakSvc, String command, String args, String[] history)
{
String hcmd = "";
// grab the command they want help on
if (!StringUtil.isBlank(args)) {
hcmd = args;
int sidx = args.indexOf(" ");
if (sidx != -1) {
hcmd = args.substring(0, sidx);
}
}
// let the user give commands with or with the /
if (hcmd.startsWith("/")) {
hcmd = hcmd.substring(1);
}
// handle "/help help" and "/help someboguscommand"
HashMap possibleCommands = getCommandHandlers(hcmd);
if (hcmd.equals("help") || possibleCommands.isEmpty()) {
possibleCommands = getCommandHandlers("");
possibleCommands.remove("help"); // remove help from the list
}
// if there is only one possible command display its usage
switch (possibleCommands.size()) {
case 1:
Iterator itr = possibleCommands.keySet().iterator();
// this is a little funny, but we display the feeback
// message by hand and return SUCCESS so that the chat
// entry field doesn't think that we've failed and
// preserve our command text
displayFeedback(null, "m.usage_" + (String)itr.next());
return ChatCodes.SUCCESS;
default:
Object[] commands = possibleCommands.keySet().toArray();
Arrays.sort(commands);
String commandList = "";
for (int ii = 0; ii < commands.length; ii++) {
commandList += " /" + commands[ii];
}
return MessageBundle.tcompose("m.usage_help", commandList);
}
}
}
/** Implements <code>/clear</code>. */
protected class ClearHandler extends CommandHandler
{
public String handleCommand (
SpeakService speakSvc, String command, String args, String[] history)
{
clearDisplays();
return ChatCodes.SUCCESS;
}
}
/** Implements <code>/speak</code>. */
protected class SpeakHandler extends CommandHandler
{
public String handleCommand (
SpeakService speakSvc, String command, String args, String[] history)
{
if (StringUtil.isBlank(args)) {
return "m.usage_speak";
}
// note the command to be stored in the history
history[0] = command + " ";
return requestChat(null, args, true);
}
}
/** Implements <code>/emote</code>. */
protected class EmoteHandler extends CommandHandler
{
public String handleCommand (
SpeakService speakSvc, String command, String args, String[] history)
{
if (StringUtil.isBlank(args)) {
return "m.usage_emote";
}
// note the command to be stored in the history
history[0] = command + " ";
return deliverChat(speakSvc, args, ChatCodes.EMOTE_MODE);
}
}
/** Implements <code>/think</code>. */
protected class ThinkHandler extends CommandHandler
{
public String handleCommand (
SpeakService speakSvc, String command, String args, String[] history)
{
if (StringUtil.isBlank(args)) {
return "m.usage_think";
}
// note the command to be stored in the history
history[0] = command + " ";
return deliverChat(speakSvc, args, ChatCodes.THINK_MODE);
}
}
/** Our active chat context. */
protected CrowdContext _ctx;
@@ -0,0 +1,21 @@
package com.threerings.crowd.chat.client {
public class ClearHandler extends CommandHandler
{
public function ClearHandler (chatdir :ChatDirector)
{
_chatdir = chatdir;
}
public override function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:String
{
_chatdir.clearDisplays();
return ChatCodes.SUCCESS;
}
/** Our ChatDirector. */
protected var _chatdir :ChatDirector;
}
}
@@ -27,7 +27,7 @@ public /* abstract */ class CommandHandler
*/
public function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:void
:String
{
throw new Error("abstract");
}
@@ -0,0 +1,28 @@
package com.threerings.crowd.chat.client {
import com.threerings.util.StringUtil;
import com.threerings.crowd.chat.data.ChatCodes;
public class EmoteHandler extends CommandHandler
{
public function EmoteHandler (chatdir :ChatDirector)
{
_chatdir = chatdir;
}
public override function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:String
{
if (StringUtil.isBlank(args)) {
return "m.usage_emote";
}
history[0] = cmd + " ";
return _chatdir.deliverChat(speakSvc, args, ChatCodes.EMOTE_MODE);
}
/** Our ChatDirector. */
protected var _chatdir :ChatDirector;
}
}
@@ -0,0 +1,61 @@
package com.threerings.crowd.chat.client {
import com.threerings.util.MessageBundle;
import com.threerings.util.StringUtil;
import com.threerings.crowd.chat.data.ChatCodes;
public class HelpHandler extends CommandHandler
{
public function HelpHandler (chatdir :ChatDirector)
{
_chatdir = chatdir;
}
public override function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:String
{
var hcmd :String = "";
// grab the command they want help on
if (!StringUtil.isBlank(args)) {
hcmd = args;
var sidx :int = args.indexOf(" ");
if (sidx != -1) {
hcmd = args.substring(0, sidx);
}
}
// let the user give commands with or without the /
if (hcmd.charAt(0) == "/") {
hcmd = hcm.substring(1);
}
// handle "/help help" and "/help boguscmd"
var possibleCmds :SimpleMap = _chatdir.getCommandHandlers(hcmd);
if ((hcmd === "help") || (possibleCmds.size() == 0)) {
possibleCmds = _chatdir.getCommandHandlers("");
possibleCmds.remove("help"); // remove help from the list
}
switch (possibleCmds.size()) {
case 1:
_chatdir.displayFeedback(null, "m.usage_" + possibleCmds.keys()[0]);
return ChatCodes.SUCCESS;
default:
var cmds :Array = possibleCmds.keys();
cmds.sort();
var cmdList :String = "";
for (var skey :String in cmds) {
cmdList += " /" + skey;
}
return MessageBundle.tcompose("m.usage_help", cmdList);
}
}
/** Our ChatDirector. */
protected var _chatdir :ChatDirector;
}
}
@@ -0,0 +1,28 @@
package com.threerings.crowd.chat.client {
import com.threerings.util.StringUtil;
import com.threerings.crowd.chat.data.ChatCodes;
public class SpeakHandler extends CommandHandler
{
public function SpeakHandler (chatdir :ChatDirector)
{
_chatdir = chatdir;
}
public override function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:String
{
if (StringUtil.isBlank(args)) {
return "m.usage_speak";
}
history[0] = cmd + " ";
return _chatdir.requestChat(null, args, true);
}
/** Our ChatDirector. */
protected var _chatdir :ChatDirector;
}
}
@@ -0,0 +1,28 @@
package com.threerings.crowd.chat.client {
import com.threerings.util.StringUtil;
import com.threerings.crowd.chat.data.ChatCodes;
public class ThinkHandler extends CommandHandler
{
public function ThinkHandler (chatdir :ChatDirector)
{
_chatdir = chatdir;
}
public override function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
:String
{
if (StringUtil.isBlank(args)) {
return "m.usage_think";
}
history[0] = cmd + " ";
return _chatdir.deliverChat(speakSvc, args, ChatCodes.THINK_MODE);
}
/** Our ChatDirector. */
protected var _chatdir :ChatDirector;
}
}