Adding two dictionary-related functions: checking a word against a dictionary,

and retrieving a set of language-specific letters. This is just a transient checkin, since 
it only pushes data both ways through the ActionScript/Java interface ("small step for 
mankind, huge step for me" kind of a thing ;). Word lookup logic will be coming next.



git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@181 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Robert Zubeck
2007-02-12 23:32:37 +00:00
parent 7a36e3a858
commit 400389ca03
9 changed files with 269 additions and 33 deletions
@@ -218,6 +218,42 @@ public class EZGameControl extends EventDispatcher
}
}
/**
* Requests a set of random letters from the dictionary service.
* The letters will arrive in a separate message with the specified key,
* as an array of strings.
*
* @param locale RFC 3066 string that represents language settings
* @param count the number of letters to be produced
* @param callback the function that will process the results, of the form:
* function (letters :Array) :void
* where letters is an array of strings containing letters
* for the given language settings (potentially empty).
*/
public function getDictionaryLetterSet (
locale :String, count :int, callback :Function) :void
{
callEZCode("getDictionaryLetterSet_v1", locale, count, callback);
}
/**
* Requests a set of random letters from the dictionary service.
* The letters will arrive in a separate message with the specified key,
* as an array of strings.
*
* @param RFC 3066 string that represents language settings
* @param word the string contains the word to be checked
* @param callback the function that will process the results, of the form:
* function (word :String, result :Boolean) :void
* where word is a copy of the word that was requested, and result
* specifies whether the word is valid given language settings
*/
public function checkDictionaryWord (
locale :String, word :String, callback :Function) :void
{
callEZCode("checkDictionaryWord_v1", locale, word, callback);
}
/**
* Set the specified collection to contain the specified values,
* clearing any previous values.
@@ -27,7 +27,9 @@ import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.client.InvocationService_ConfirmListener;
import com.threerings.presents.client.InvocationService_InvocationListener;
import com.threerings.presents.client.InvocationService_ResultListener;
import com.threerings.presents.data.InvocationMarshaller_ConfirmMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ResultMarshaller;
/**
* An ActionScript version of the Java EZGameService interface.
@@ -37,6 +39,9 @@ public interface EZGameService extends InvocationService
// from Java interface EZGameService
function addToCollection (arg1 :Client, arg2 :String, arg3 :Array, arg4 :Boolean, arg5 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService
function checkDictionaryWord (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_ResultListener) :void;
// from Java interface EZGameService
function endGame (arg1 :Client, arg2 :Array, arg3 :InvocationService_InvocationListener) :void;
@@ -46,6 +51,9 @@ public interface EZGameService extends InvocationService
// from Java interface EZGameService
function getCookie (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService
function getDictionaryLetterSet (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_ResultListener) :void;
// from Java interface EZGameService
function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void;
@@ -27,7 +27,9 @@ import com.threerings.util.Name;
import com.threerings.util.StringUtil;
import com.threerings.presents.client.ConfirmAdapter;
import com.threerings.presents.client.ResultWrapper;
import com.threerings.presents.client.InvocationService_ConfirmListener;
import com.threerings.presents.client.InvocationService_ResultListener;
import com.threerings.presents.dobj.EntryAddedEvent;
import com.threerings.presents.dobj.EntryRemovedEvent;
@@ -138,6 +140,8 @@ public class GameControlBackend
o["isInPlay_v1"] = isInPlay_v1;
o["endTurn_v1"] = endTurn_v1;
o["endGame_v1"] = endGame_v1;
o["getDictionaryLetterSet_v1"] = getDictionaryLetterSet_v1;
o["checkDictionaryWord_v1"] = checkDictionaryWord_v1;
o["populateCollection_v1"] = populateCollection_v1;
o["getFromCollection_v1"] = getFromCollection_v1;
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
@@ -152,7 +156,7 @@ public class GameControlBackend
var encoded :Object = EZObjectMarshaller.encode(value, (index == -1));
_ezObj.ezGameService.setProperty(
_ctx.getClient(), propName, encoded, index,
createLoggingListener("setProperty"));
createLoggingConfirmListener("setProperty"));
// set it immediately in the game object
_ezObj.applyPropertySet(propName, value, index);
@@ -164,7 +168,7 @@ public class GameControlBackend
validateName(srcColl);
validateName(intoColl);
_ezObj.ezGameService.mergeCollection(_ctx.getClient(),
srcColl, intoColl, createLoggingListener("mergeCollection"));
srcColl, intoColl, createLoggingConfirmListener("mergeCollection"));
}
public function sendMessage_v1 (
@@ -176,14 +180,14 @@ public class GameControlBackend
var encoded :Object = EZObjectMarshaller.encode(value, false);
_ezObj.ezGameService.sendMessage(_ctx.getClient(),
messageName, encoded, playerIndex,
createLoggingListener("sendMessage"));
createLoggingConfirmListener("sendMessage"));
}
public function setTicker_v1 (tickerName :String, msOfDelay :int) :void
{
validateName(tickerName);
_ezObj.ezGameService.setTicker(_ctx.getClient(),
tickerName, msOfDelay, createLoggingListener("setTicker"));
tickerName, msOfDelay, createLoggingConfirmListener("setTicker"));
}
public function sendChat_v1 (msg :String) :void
@@ -289,7 +293,7 @@ public class GameControlBackend
// request it to be made so by the server
_ezObj.ezGameService.getCookie(_ctx.getClient(), playerIndex,
createLoggingListener("getUserCookie"));
createLoggingConfirmListener("getUserCookie"));
}
public function setUserCookie_v1 (cookie :Object) :Boolean
@@ -302,7 +306,7 @@ public class GameControlBackend
}
_ezObj.ezGameService.setCookie(_ctx.getClient(), ba,
createLoggingListener("setUserCookie"));
createLoggingConfirmListener("setUserCookie"));
return true;
}
@@ -319,7 +323,7 @@ public class GameControlBackend
public function endTurn_v1 (nextPlayerIndex :int = -1) :void
{
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerIndex,
createLoggingListener("endTurn"));
createLoggingConfirmListener("endTurn"));
}
public function endGame_v1 (... winnerDexes) :void
@@ -329,7 +333,54 @@ public class GameControlBackend
winners.push(int(winnerDexes.shift()));
}
_ezObj.ezGameService.endGame(_ctx.getClient(), winners,
createLoggingListener("endGame"));
createLoggingConfirmListener("endGame"));
}
public function getDictionaryLetterSet_v1 (
locale :String, count :int, callback :Function) :void
{
var listener :InvocationService_ResultListener;
if (callback != null) {
var failure :Function = function (cause :String = null) :void {
// ignore the cause, return an empty array
callback ([]);
}
var success :Function = function (result :String = null) :void {
// splice the resulting string, and return as array
var r : Array = result.split(",");
callback (r);
};
listener = new ResultWrapper (failure, success);
} else {
listener = createLoggingResultListener ("checkDictionaryWord");
}
// just relay the data over to the server
_ezObj.ezGameService.getDictionaryLetterSet(_ctx.getClient(), locale, count, listener);
}
public function checkDictionaryWord_v1 (
locale :String, word :String, callback :Function) :void
{
var listener :InvocationService_ResultListener;
if (callback != null) {
var failure :Function = function (cause :String = null) :void {
// ignore the cause, return failure
callback (word, false);
}
var success :Function = function (result :Object = null) :void {
// server returns a boolean, so convert it and send it over
var r : Boolean = Boolean(result);
callback (word, r);
};
listener = new ResultWrapper (failure, success);
} else {
listener = createLoggingResultListener ("checkDictionaryWord");
}
// just relay the data over to the server
_ezObj.ezGameService.checkDictionaryWord(_ctx.getClient(), locale, word, listener);
}
/**
@@ -349,7 +400,7 @@ public class GameControlBackend
_ezObj.ezGameService.addToCollection(
_ctx.getClient(), collName, encodedValues, clearExisting,
createLoggingListener("populateCollection"));
createLoggingConfirmListener("populateCollection"));
}
/**
@@ -379,7 +430,7 @@ public class GameControlBackend
listener = new ConfirmAdapter(fn, fn);
} else {
listener = createLoggingListener("getFromCollection");
listener = createLoggingConfirmListener("getFromCollection");
}
_ezObj.ezGameService.getFromCollection(
@@ -422,9 +473,9 @@ public class GameControlBackend
}
/**
* Create a listener for service requests.
* Create a logging confirm listener for service requests.
*/
protected function createLoggingListener (
protected function createLoggingConfirmListener (
service :String) :InvocationService_ConfirmListener
{
return new ConfirmAdapter(function (cause :String) :void {
@@ -433,6 +484,18 @@ public class GameControlBackend
});
}
/**
* Create a logging result listener for service requests.
*/
protected function createLoggingResultListener (
service :String) :InvocationService_ResultListener
{
return new ResultWrapper(function (cause :String) :void {
Log.getLog(this).warning("Service failure " +
"[service=" + service + ", cause=" + cause + "].");
});
}
/**
* Verify that the property name / value are valid.
*/
@@ -28,9 +28,11 @@ import com.threerings.ezgame.client.EZGameService;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService_ConfirmListener;
import com.threerings.presents.client.InvocationService_InvocationListener;
import com.threerings.presents.client.InvocationService_ResultListener;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ConfirmMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ResultMarshaller;
/**
* Provides the implementation of the {@link EZGameService} interface
@@ -55,8 +57,21 @@ public class EZGameMarshaller extends InvocationMarshaller
]);
}
/** The method id used to dispatch {@link #checkDictionaryWord} requests. */
public static const CHECK_DICTIONARY_WORD :int = 2;
// from interface EZGameService
public function checkDictionaryWord (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_ResultListener) :void
{
var listener4 :InvocationMarshaller_ResultMarshaller = new InvocationMarshaller_ResultMarshaller();
listener4.listener = arg4;
sendRequest(arg1, CHECK_DICTIONARY_WORD, [
arg2, arg3, listener4
]);
}
/** The method id used to dispatch {@link #endGame} requests. */
public static const END_GAME :int = 2;
public static const END_GAME :int = 3;
// from interface EZGameService
public function endGame (arg1 :Client, arg2 :Array, arg3 :InvocationService_InvocationListener) :void
@@ -69,7 +84,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #endTurn} requests. */
public static const END_TURN :int = 3;
public static const END_TURN :int = 4;
// from interface EZGameService
public function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -82,7 +97,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #getCookie} requests. */
public static const GET_COOKIE :int = 4;
public static const GET_COOKIE :int = 5;
// from interface EZGameService
public function getCookie (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -94,8 +109,21 @@ public class EZGameMarshaller extends InvocationMarshaller
]);
}
/** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */
public static const GET_DICTIONARY_LETTER_SET :int = 6;
// from interface EZGameService
public function getDictionaryLetterSet (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_ResultListener) :void
{
var listener4 :InvocationMarshaller_ResultMarshaller = new InvocationMarshaller_ResultMarshaller();
listener4.listener = arg4;
sendRequest(arg1, GET_DICTIONARY_LETTER_SET, [
arg2, Integer.valueOf(arg3), listener4
]);
}
/** The method id used to dispatch {@link #getFromCollection} requests. */
public static const GET_FROM_COLLECTION :int = 5;
public static const GET_FROM_COLLECTION :int = 7;
// from interface EZGameService
public function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void
@@ -108,7 +136,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #mergeCollection} requests. */
public static const MERGE_COLLECTION :int = 6;
public static const MERGE_COLLECTION :int = 8;
// from interface EZGameService
public function mergeCollection (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_InvocationListener) :void
@@ -121,7 +149,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #sendMessage} requests. */
public static const SEND_MESSAGE :int = 7;
public static const SEND_MESSAGE :int = 9;
// from interface EZGameService
public function sendMessage (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
@@ -134,7 +162,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setCookie} requests. */
public static const SET_COOKIE :int = 8;
public static const SET_COOKIE :int = 10;
// from interface EZGameService
public function setCookie (arg1 :Client, arg2 :ByteArray, arg3 :InvocationService_InvocationListener) :void
@@ -147,7 +175,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setProperty} requests. */
public static const SET_PROPERTY :int = 9;
public static const SET_PROPERTY :int = 11;
// from interface EZGameService
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
@@ -160,7 +188,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setTicker} requests. */
public static const SET_TICKER :int = 10;
public static const SET_TICKER :int = 12;
// from interface EZGameService
public function setTicker (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_InvocationListener) :void
@@ -48,6 +48,34 @@ public interface EZGameService extends InvocationService
Client client, String msgName, Object value, int playerIdx,
InvocationListener listener);
/**
* Ask the dictionary service for a set of random letters
* appropriate for the given language/culture settings. These will be
* returned via a message back to the caller.
*
* @param client stores information about the caller
* @param locale is an RFC 3066 string specifying language settings,
* for example, "en" or "en-us".
* @param count is the number of letters to be returned.
* @param listener is the callback function
*/
public void getDictionaryLetterSet (
Client client, String locale, int count, ResultListener listener);
/**
* Ask the dictionary service whether the specified word is valid
* with the given language/culture settings. The result will be returned
* via a message back to the caller.
*
* @param client stores information about the caller
* @param locale is an RFC 3066 string specifying language settings,
* for example, "en" or "en-us".
* @param word is the word to be checked against the dictionary.
* @param listener is the callback function
*/
public void checkDictionaryWord (
Client client, String locale, String word, ResultListener listener);
/**
* Add to the specified named collection.
*
@@ -50,8 +50,21 @@ public class EZGameMarshaller extends InvocationMarshaller
});
}
/** The method id used to dispatch {@link #checkDictionaryWord} requests. */
public static final int CHECK_DICTIONARY_WORD = 2;
// from interface EZGameService
public void checkDictionaryWord (Client arg1, String arg2, String arg3, InvocationService.ResultListener arg4)
{
InvocationMarshaller.ResultMarshaller listener4 = new InvocationMarshaller.ResultMarshaller();
listener4.listener = arg4;
sendRequest(arg1, CHECK_DICTIONARY_WORD, new Object[] {
arg2, arg3, listener4
});
}
/** The method id used to dispatch {@link #endGame} requests. */
public static final int END_GAME = 2;
public static final int END_GAME = 3;
// from interface EZGameService
public void endGame (Client arg1, int[] arg2, InvocationService.InvocationListener arg3)
@@ -64,7 +77,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #endTurn} requests. */
public static final int END_TURN = 3;
public static final int END_TURN = 4;
// from interface EZGameService
public void endTurn (Client arg1, int arg2, InvocationService.InvocationListener arg3)
@@ -77,7 +90,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #getCookie} requests. */
public static final int GET_COOKIE = 4;
public static final int GET_COOKIE = 5;
// from interface EZGameService
public void getCookie (Client arg1, int arg2, InvocationService.InvocationListener arg3)
@@ -89,8 +102,21 @@ public class EZGameMarshaller extends InvocationMarshaller
});
}
/** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */
public static final int GET_DICTIONARY_LETTER_SET = 6;
// from interface EZGameService
public void getDictionaryLetterSet (Client arg1, String arg2, int arg3, InvocationService.ResultListener arg4)
{
InvocationMarshaller.ResultMarshaller listener4 = new InvocationMarshaller.ResultMarshaller();
listener4.listener = arg4;
sendRequest(arg1, GET_DICTIONARY_LETTER_SET, new Object[] {
arg2, Integer.valueOf(arg3), listener4
});
}
/** The method id used to dispatch {@link #getFromCollection} requests. */
public static final int GET_FROM_COLLECTION = 5;
public static final int GET_FROM_COLLECTION = 7;
// from interface EZGameService
public void getFromCollection (Client arg1, String arg2, boolean arg3, int arg4, String arg5, int arg6, InvocationService.ConfirmListener arg7)
@@ -103,7 +129,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #mergeCollection} requests. */
public static final int MERGE_COLLECTION = 6;
public static final int MERGE_COLLECTION = 8;
// from interface EZGameService
public void mergeCollection (Client arg1, String arg2, String arg3, InvocationService.InvocationListener arg4)
@@ -116,7 +142,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #sendMessage} requests. */
public static final int SEND_MESSAGE = 7;
public static final int SEND_MESSAGE = 9;
// from interface EZGameService
public void sendMessage (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5)
@@ -129,7 +155,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setCookie} requests. */
public static final int SET_COOKIE = 8;
public static final int SET_COOKIE = 10;
// from interface EZGameService
public void setCookie (Client arg1, byte[] arg2, InvocationService.InvocationListener arg3)
@@ -142,7 +168,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setProperty} requests. */
public static final int SET_PROPERTY = 9;
public static final int SET_PROPERTY = 11;
// from interface EZGameService
public void setProperty (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5)
@@ -155,7 +181,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setTicker} requests. */
public static final int SET_TICKER = 10;
public static final int SET_TICKER = 12;
// from interface EZGameService
public void setTicker (Client arg1, String arg2, int arg3, InvocationService.InvocationListener arg4)
@@ -63,6 +63,13 @@ public class EZGameDispatcher extends InvocationDispatcher
);
return;
case EZGameMarshaller.CHECK_DICTIONARY_WORD:
((EZGameProvider)provider).checkDictionaryWord(
source,
(String)args[0], (String)args[1], (InvocationService.ResultListener)args[2]
);
return;
case EZGameMarshaller.END_GAME:
((EZGameProvider)provider).endGame(
source,
@@ -84,6 +91,13 @@ public class EZGameDispatcher extends InvocationDispatcher
);
return;
case EZGameMarshaller.GET_DICTIONARY_LETTER_SET:
((EZGameProvider)provider).getDictionaryLetterSet(
source,
(String)args[0], ((Integer)args[1]).intValue(), (InvocationService.ResultListener)args[2]
);
return;
case EZGameMarshaller.GET_FROM_COLLECTION:
((EZGameProvider)provider).getFromCollection(
source,
@@ -123,6 +123,27 @@ public class EZGameManager extends GameManager
setProperty(propName, data, index);
}
// from EZGameProvider
public void getDictionaryLetterSet (
ClientObject caller, String locale, int count,
InvocationService.ResultListener listener)
throws InvocationException
{
// TODO: real logic here :)
String letters = "A,B,C";
listener.requestProcessed(letters);
}
// from EZGameProvider
public void checkDictionaryWord (
ClientObject caller, String locale, String word,
InvocationService.ResultListener listener)
throws InvocationException
{
// TODO: real logic here :)
listener.requestProcessed (true);
}
// from EZGameProvider
public void addToCollection (
ClientObject caller, String collName, byte[][] data,
@@ -176,7 +197,7 @@ public class EZGameManager extends GameManager
if (playerIndex >= 0 && playerIndex < _gameObj.players.length) {
sendPrivateMessage(playerIndex, msgOrPropName, result);
} else {
setProperty(msgOrPropName, result, -1);
}
@@ -185,11 +206,11 @@ public class EZGameManager extends GameManager
return;
}
}
// TODO: decide what we want to return here
throw new InvocationException(String.valueOf(srcSize));
}
// from EZGameProvider
public void mergeCollection (
ClientObject caller, String srcColl, String intoColl,
@@ -39,6 +39,12 @@ public interface EZGameProvider extends InvocationProvider
public void addToCollection (ClientObject caller, String arg1, byte[][] arg2, boolean arg3, InvocationService.InvocationListener arg4)
throws InvocationException;
/**
* Handles a {@link EZGameService#checkDictionaryWord} request.
*/
public void checkDictionaryWord (ClientObject caller, String arg1, String arg2, InvocationService.ResultListener arg3)
throws InvocationException;
/**
* Handles a {@link EZGameService#endGame} request.
*/
@@ -57,6 +63,12 @@ public interface EZGameProvider extends InvocationProvider
public void getCookie (ClientObject caller, int arg1, InvocationService.InvocationListener arg2)
throws InvocationException;
/**
* Handles a {@link EZGameService#getDictionaryLetterSet} request.
*/
public void getDictionaryLetterSet (ClientObject caller, String arg1, int arg2, InvocationService.ResultListener arg3)
throws InvocationException;
/**
* Handles a {@link EZGameService#getFromCollection} request.
*/