As part of the second pass on AS recoloring, setup recoloring scenes appropriately.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@935 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
//
|
||||
// Vilya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/vilya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.stage.client {
|
||||
|
||||
import com.threerings.media.image.ClassRecord;
|
||||
import com.threerings.media.image.ColorPository;
|
||||
import com.threerings.media.image.ColorRecord;
|
||||
import com.threerings.media.image.Colorization;
|
||||
import com.threerings.stage.data.StageScene;
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.media.tile.Colorizer;
|
||||
import com.threerings.util.Log;
|
||||
import com.threerings.util.Maps;
|
||||
import com.threerings.util.Map;
|
||||
|
||||
/**
|
||||
* Handles colorization of object tiles in a scene.
|
||||
*/
|
||||
public class SceneColorizer implements Colorizer
|
||||
{
|
||||
private var log :Log = Log.getLog(SceneColorizer);
|
||||
|
||||
/**
|
||||
* Creates a scene colorizer for the supplied scene.
|
||||
*/
|
||||
public function SceneColorizer (cpos :ColorPository, scene :StageScene)
|
||||
{
|
||||
_cpos = cpos;
|
||||
_scene = scene;
|
||||
|
||||
// enumerate the color ids for all possible colorization classes
|
||||
for each (var colClass :ClassRecord in _cpos.getClasses()) {
|
||||
_cids.put(colClass.name, _cpos.getColorIds(colClass.name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an auxiliary colorizer that overrides our colorizations.
|
||||
*/
|
||||
public function setAuxiliary (aux :Colorizer) :void
|
||||
{
|
||||
_aux = aux;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a colorizer for the supplied scene object.
|
||||
*/
|
||||
public function getColorizer (oinfo :ObjectInfo) :Colorizer
|
||||
{
|
||||
// if the object has no custom colorizations, return the default
|
||||
// colorizer
|
||||
if (oinfo.zations == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// otherwise create a custom colorizer that returns this object's
|
||||
// custom colorization assignments
|
||||
return new BaseColorizer(oinfo, this, _cpos);
|
||||
}
|
||||
|
||||
// documentation inherited from interface Colorizer
|
||||
public function getColorization (index :int, zation :String) :Colorization
|
||||
{
|
||||
// This method is called when an object in the scene has no colorization
|
||||
// of its own defined for a particular color class.
|
||||
if (_aux != null) {
|
||||
var c :Colorization = _aux.getColorization(index, zation);
|
||||
if (c != null) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return _cpos.getColorizationByNameAndId(zation, getColorId(zation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the colorId to use for the specified colorization.
|
||||
*/
|
||||
public function getColorId (zation :String) :int
|
||||
{
|
||||
// 1. We see if the scene contains a default color we should use.
|
||||
var rec :ClassRecord = _cpos.getClassRecordByName(zation);
|
||||
var colorId :int = _scene.getDefaultColor(rec.classId);
|
||||
if (colorId == -1) {
|
||||
// 2. If the scene does not contain a color, see if a default
|
||||
// is defined for that color class.
|
||||
var def :ColorRecord = rec.getDefault();
|
||||
if (def != null) {
|
||||
return def.colorId;
|
||||
}
|
||||
|
||||
// 3. If there are no defaults whatsoever, just hash on the zoneId.
|
||||
var cids :Array= _cids.get(zation);
|
||||
if (cids == null) {
|
||||
log.warning("Zoiks, have no colorizations for '" + zation + "'.");
|
||||
return -1;
|
||||
} else {
|
||||
colorId = cids[_scene.getZoneId() % cids.length];
|
||||
}
|
||||
}
|
||||
return colorId;
|
||||
}
|
||||
|
||||
/** An auxiliary colorizer which may temporarily return
|
||||
* non-standard colorizations. */
|
||||
protected var _aux :Colorizer;
|
||||
|
||||
/** The entity from which we obtain colorization info. */
|
||||
protected var _cpos :ColorPository;
|
||||
|
||||
/** The scene for which we're providing zations. */
|
||||
protected var _scene :StageScene;
|
||||
|
||||
/** Contains our colorization class information. */
|
||||
protected var _cids :Map = Maps.newMapOf(String);
|
||||
}
|
||||
}
|
||||
|
||||
import com.threerings.media.image.Colorization;
|
||||
import com.threerings.media.image.ColorPository;
|
||||
import com.threerings.media.tile.Colorizer;
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.stage.client.SceneColorizer;
|
||||
|
||||
class BaseColorizer implements Colorizer {
|
||||
public function BaseColorizer (oInfo :ObjectInfo, defColorizer :SceneColorizer,
|
||||
cpos :ColorPository)
|
||||
{
|
||||
_oInfo = oInfo;
|
||||
_defColorizer = defColorizer;
|
||||
_cpos = cpos;
|
||||
}
|
||||
|
||||
public function getColorization (index :int, zation :String) :Colorization {
|
||||
var colorId :int = 0;
|
||||
switch (index) {
|
||||
case 0: colorId = _oInfo.getPrimaryZation(); break;
|
||||
case 1: colorId = _oInfo.getSecondaryZation(); break;
|
||||
case 2: colorId = _oInfo.getTertiaryZation(); break;
|
||||
case 3: colorId = _oInfo.getQuaternaryZation(); break;
|
||||
}
|
||||
|
||||
if (colorId == 0) {
|
||||
return _defColorizer.getColorization(index, zation);
|
||||
} else {
|
||||
return _cpos.getColorizationByNameAndId(zation, colorId);
|
||||
}
|
||||
}
|
||||
|
||||
protected var _oInfo :ObjectInfo;
|
||||
protected var _defColorizer :SceneColorizer;
|
||||
protected var _cpos :ColorPository;
|
||||
}
|
||||
@@ -21,9 +21,14 @@
|
||||
package com.threerings.stage.client {
|
||||
|
||||
import com.threerings.util.Controller;
|
||||
import com.threerings.util.Log;
|
||||
import com.threerings.whirled.data.SceneUpdate;
|
||||
import com.threerings.media.tile.Colorizer;
|
||||
import com.threerings.miso.client.MisoScenePanel;
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.miso.util.MisoSceneMetrics;
|
||||
import com.threerings.stage.data.StageMisoSceneModel;
|
||||
import com.threerings.stage.data.StageScene;
|
||||
import com.threerings.stage.util.StageContext;
|
||||
|
||||
/**
|
||||
@@ -31,14 +36,50 @@ import com.threerings.stage.util.StageContext;
|
||||
*/
|
||||
public class StageScenePanel extends MisoScenePanel
|
||||
{
|
||||
private var log :Log = Log.getLog(StageScenePanel);
|
||||
|
||||
public function StageScenePanel (ctx :StageContext, ctrl :Controller, metrics :MisoSceneMetrics)
|
||||
{
|
||||
super(ctx, metrics);
|
||||
_sCtx = ctx;
|
||||
}
|
||||
|
||||
public function setScene (scene :StageScene) :void
|
||||
{
|
||||
_scene = scene;
|
||||
if (_scene != null) {
|
||||
_rizer = new SceneColorizer(_sCtx.getColorPository(), _scene);
|
||||
recomputePortals();
|
||||
setSceneModel(StageMisoSceneModel.getSceneModel(scene.getSceneModel()));
|
||||
} else {
|
||||
log.warning("Zoiks! We can't display a null scene!");
|
||||
// TODO: display something to the user letting them know that
|
||||
// we're so hosed that we don't even know what time it is
|
||||
}
|
||||
}
|
||||
|
||||
public function recomputePortals () :void
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public function sceneUpdated (update :SceneUpdate) :void
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected override function getColorizer (oinfo :ObjectInfo) :Colorizer
|
||||
{
|
||||
return _rizer.getColorizer(oinfo);
|
||||
}
|
||||
|
||||
/** The scene we're presenting in our panel. */
|
||||
protected var _scene :StageScene;
|
||||
|
||||
/** Used to recolor any tiles in our scene. */
|
||||
protected var _rizer :SceneColorizer;
|
||||
|
||||
/** Our appropriately-cast stage client context. */
|
||||
protected var _sCtx :StageContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Vilya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/vilya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.stage.data {
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.whirled.data.SceneImpl;
|
||||
|
||||
public class StageScene extends SceneImpl
|
||||
{
|
||||
public function StageScene (model :StageSceneModel, config :PlaceConfig)
|
||||
{
|
||||
super(model, config);
|
||||
_ssModel = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default color id to use for the specified colorization class,
|
||||
* or -1 if no default is set.
|
||||
*/
|
||||
public function getDefaultColor (classId :int) :int
|
||||
{
|
||||
return _ssModel.getDefaultColor(classId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default color to use for the specified colorization class id.
|
||||
* Setting the colorId to -1 disables the default.
|
||||
*/
|
||||
public function setDefaultColor (classId :int, colorId :int) :void
|
||||
{
|
||||
_ssModel.setDefaultColor(classId, colorId);
|
||||
}
|
||||
|
||||
public function getZoneId () :int
|
||||
{
|
||||
return _ssModel.zoneId;
|
||||
}
|
||||
|
||||
protected var _ssModel :StageSceneModel;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
import com.threerings.stage.data.StageSceneModel;
|
||||
import com.threerings.util.Integer;
|
||||
import com.threerings.util.StreamableHashMap;
|
||||
import com.threerings.whirled.spot.data.SpotSceneModel;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
@@ -88,7 +89,7 @@ public class StageSceneModel extends SceneModel
|
||||
public function getDefaultColor (classId :int) :int
|
||||
{
|
||||
if (defaultColors != null) {
|
||||
return defaultColors.get(classId);
|
||||
return defaultColors.get(new Integer(classId));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.threerings.stage.util {
|
||||
|
||||
import com.threerings.media.image.ColorPository;
|
||||
import com.threerings.miso.util.MisoContext;
|
||||
|
||||
/**
|
||||
@@ -8,6 +9,9 @@ import com.threerings.miso.util.MisoContext;
|
||||
*/
|
||||
public interface StageContext extends MisoContext
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a reference to the colorization repository.
|
||||
*/
|
||||
function getColorPository () :ColorPository;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user