From ef9c12672eb08408580285364740adefb89a0fb5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 19 Jan 2002 04:02:11 +0000 Subject: [PATCH] Restructured MiCasaClient such that it could be extended for games that need a custom (extended) client context. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@876 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/micasa/client/MiCasaApp.java | 18 ++++++- .../micasa/client/MiCasaClient.java | 51 ++++++++++++++----- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/java/com/threerings/micasa/client/MiCasaApp.java b/src/java/com/threerings/micasa/client/MiCasaApp.java index fb6957fc3..759322ae0 100644 --- a/src/java/com/threerings/micasa/client/MiCasaApp.java +++ b/src/java/com/threerings/micasa/client/MiCasaApp.java @@ -1,5 +1,5 @@ // -// $Id: MiCasaApp.java,v 1.4 2001/11/26 23:46:47 mdb Exp $ +// $Id: MiCasaApp.java,v 1.5 2002/01/19 04:02:11 mdb Exp $ package com.threerings.micasa.client; @@ -27,7 +27,21 @@ public class MiCasaApp _frame = new MiCasaFrame(); // create our client instance - _client = new MiCasaClient(_frame); + String cclass = System.getProperty("client"); + if (cclass == null) { + cclass = MiCasaClient.class.getName(); + } + + try { + _client = (MiCasaClient)Class.forName(cclass).newInstance(); + } catch (Exception e) { + Log.warning("Unable to instantiate client class " + + "[cclass=" + cclass + "]."); + Log.logStackTrace(e); + } + + // initialize our client instance + _client.init(_frame); } public void run () diff --git a/src/java/com/threerings/micasa/client/MiCasaClient.java b/src/java/com/threerings/micasa/client/MiCasaClient.java index 0f1aa5384..546e35d5b 100644 --- a/src/java/com/threerings/micasa/client/MiCasaClient.java +++ b/src/java/com/threerings/micasa/client/MiCasaClient.java @@ -1,5 +1,5 @@ // -// $Id: MiCasaClient.java,v 1.7 2001/12/20 01:10:51 shaper Exp $ +// $Id: MiCasaClient.java,v 1.8 2002/01/19 04:02:11 mdb Exp $ package com.threerings.micasa.client; @@ -26,29 +26,24 @@ import com.threerings.micasa.util.MiCasaContext; /** * The MiCasa client takes care of instantiating all of the proper * managers and loading up all of the necessary configuration and getting - * the client bootstrapped. + * the client bootstrapped. It can be extended by games that require an + * extended context implementation. */ public class MiCasaClient implements Client.Invoker { /** - * Creates a new client and provides it with a frame in which to + * Initializes a new client and provides it with a frame in which to * display everything. */ - public MiCasaClient (MiCasaFrame frame) + public void init (MiCasaFrame frame) throws IOException { // create our context - _ctx = new MiCasaContextImpl(); + _ctx = createContextImpl(); - // create the handles on our various services - _config = new Config(); - _client = new Client(null, this); - - // create our managers and directors - _locdir = new LocationDirector(_ctx); - _occmgr = new OccupantManager(_ctx); - _pardtr = new ParlorDirector(_ctx); + // create the directors/managers/etc. provided by the context + createContextServices(); // for test purposes, hardcode the server info _client.setServer("bering", 4007); @@ -79,6 +74,36 @@ public class MiCasaClient return _ctx; } + /** + * Creates the {@link MiCasaContext} implementation that will be + * passed around to all of the client code. Derived classes may wish + * to override this and create some extended context implementation. + */ + protected MiCasaContext createContextImpl () + { + return new MiCasaContextImpl(); + } + + /** + * Creates and initializes the various services that are provided by + * the context. Derived classes that provide an extended context + * should override this method and create their own extended + * services. They should be sure to call + * super.createContextServices. + */ + protected void createContextServices () + throws IOException + { + // create the handles on our various services + _config = new Config(); + _client = new Client(null, this); + + // create our managers and directors + _locdir = new LocationDirector(_ctx); + _occmgr = new OccupantManager(_ctx); + _pardtr = new ParlorDirector(_ctx); + } + // documentation inherited public void invokeLater (Runnable run) {