First pass at getting miso working with actual tiles and tileset data.
Still to do: - Handle tile priorities in ISO sorting. - Handle recoloring tiles (this may result in annoyingly significant changes to Tile/TileSet API) - Dynamically loading sections rather than loading all the tiles of a scene. - Better handling of the state where the scene's not yet loaded. - Portals. - Dynamic sizing of the MisoScenePanel git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@932 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
//
|
||||
// Nenya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/nenya/
|
||||
//
|
||||
// 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.miso.client {
|
||||
|
||||
import as3isolib.display.primitive.IsoBox;
|
||||
import as3isolib.graphics.SolidColorFill;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.miso.util.MisoSceneMetrics;
|
||||
|
||||
public class BaseTileIsoSprite extends IsoBox
|
||||
public class BaseTileIsoSprite extends TileIsoSprite
|
||||
{
|
||||
public function BaseTileIsoSprite (x :int, y :int, tileId :int)
|
||||
public function BaseTileIsoSprite (x :int, y :int, tileId :int, tile :Tile,
|
||||
metrics :MisoSceneMetrics)
|
||||
{
|
||||
width = 1;
|
||||
height = VERT_OFFSET;
|
||||
length = 1;
|
||||
super(x, y, tileId, tile, metrics);
|
||||
}
|
||||
|
||||
moveTo(x, y, -VERT_OFFSET);
|
||||
public override function layout (x :int, y :int, tile :Tile) :void
|
||||
{
|
||||
super.layout(x, y, tile);
|
||||
|
||||
// TEMP
|
||||
fill = new SolidColorFill(tileId * 1000, 1.0);
|
||||
setSize(1, 1, VERT_OFFSET);
|
||||
}
|
||||
|
||||
protected static const VERT_OFFSET :Number = 0.01;
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
//
|
||||
// Nenya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/nenya/
|
||||
//
|
||||
// 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.miso.client {
|
||||
|
||||
import flash.utils.getTimer;
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
import flash.events.Event;
|
||||
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
|
||||
@@ -11,6 +32,9 @@ import flash.events.MouseEvent;
|
||||
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.media.tile.NoSuchTileSetError;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.TileUtil;
|
||||
import com.threerings.miso.client.MisoMetricsTransformation;
|
||||
import com.threerings.miso.data.MisoSceneModel;
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
@@ -30,10 +54,13 @@ public class MisoScenePanel extends Sprite
|
||||
{
|
||||
public function MisoScenePanel (ctx :MisoContext, metrics :MisoSceneMetrics)
|
||||
{
|
||||
_ctx = ctx;
|
||||
// Excitingly, we get to override this globally for as3isolib...
|
||||
IsoMath.transformationObject = new MisoMetricsTransformation(metrics,
|
||||
metrics.tilehei * 3 / 4);
|
||||
|
||||
_metrics = metrics;
|
||||
|
||||
_isoView = new IsoView();
|
||||
_isoView.setSize(DEF_WIDTH, DEF_HEIGHT);
|
||||
|
||||
@@ -42,11 +69,6 @@ public class MisoScenePanel extends Sprite
|
||||
addChild(_isoView);
|
||||
}
|
||||
|
||||
public function setSize (width :int, height :int) :void
|
||||
{
|
||||
_isoView.setSize(width, height);
|
||||
}
|
||||
|
||||
public function onClick (event :MouseEvent) :void
|
||||
{
|
||||
var viewPt :Point = _isoView.globalToLocal(new Point(event.stageX, event.stageY));
|
||||
@@ -78,13 +100,43 @@ public class MisoScenePanel extends Sprite
|
||||
var time :int = getTimer();
|
||||
var baseArr :Array = [];
|
||||
|
||||
for (var si :int = -10; si < 3; si++) {
|
||||
for (var sj :int = -8; sj < 4; sj++) {
|
||||
for (var si :int = -2; si < 4; si++) {
|
||||
for (var sj :int = -1; sj < 3; sj++) {
|
||||
var baseScene :IsoScene = new IsoScene();
|
||||
for (var ii :int = 10*si; ii < 10*si + 10; ii++) {
|
||||
for (var jj :int = 10*sj; jj < 10*sj + 10; jj++) {
|
||||
var tileId :int = _model.getBaseTileId(ii, jj);
|
||||
if (tileId <= 0) {
|
||||
var defSet :TileSet;
|
||||
try {
|
||||
var setId :int = _model.getDefaultBaseTileSet();
|
||||
defSet = _ctx.getTileManager().getTileSet(setId);
|
||||
tileId = TileUtil.getFQTileId(setId,
|
||||
TileUtil.getTileHash(ii, jj) % defSet.getTileCount());
|
||||
} catch (err :NoSuchTileSetError) {
|
||||
// Someone else already complained...
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var tileSet :TileSet;
|
||||
try {
|
||||
tileSet =
|
||||
_ctx.getTileManager().getTileSet(TileUtil.getTileSetId(tileId));
|
||||
} catch (err :NoSuchTileSetError) {
|
||||
// Someone else already complained...
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileSet == null) {
|
||||
trace("TileManager returned null tilset: " +
|
||||
TileUtil.getTileSetId(tileId));
|
||||
continue;
|
||||
}
|
||||
|
||||
baseScene.addChild(
|
||||
new BaseTileIsoSprite(ii, jj, _model.getBaseTileId(ii, jj)));
|
||||
new BaseTileIsoSprite(ii, jj, tileId,
|
||||
tileSet.getTile(TileUtil.getTileIndex(tileId)), _metrics));
|
||||
}
|
||||
}
|
||||
baseScene.render();
|
||||
@@ -97,9 +149,24 @@ public class MisoScenePanel extends Sprite
|
||||
time = getTimer();
|
||||
for (ii = 0; ii < set.size(); ii++) {
|
||||
var objInfo :ObjectInfo = set.get(ii);
|
||||
if (objInfo.priority == 0) {
|
||||
scene.addChild(new ObjectTileIsoSprite(objInfo.x, objInfo.y, objInfo.tileId));
|
||||
var objTileId :int = objInfo.tileId;
|
||||
var objTileSet :TileSet;
|
||||
try {
|
||||
objTileSet =
|
||||
_ctx.getTileManager().getTileSet(TileUtil.getTileSetId(objTileId));
|
||||
} catch (err :NoSuchTileSetError) {
|
||||
// Someone else already complained...
|
||||
continue;
|
||||
}
|
||||
|
||||
if (objTileSet == null) {
|
||||
trace("TileManager returned null TileSet: " + TileUtil.getTileSetId(objTileId));
|
||||
continue;
|
||||
}
|
||||
|
||||
scene.addChild(
|
||||
new ObjectTileIsoSprite(objInfo.x, objInfo.y, objTileId,
|
||||
objTileSet.getTile(TileUtil.getTileIndex(objTileId)), _metrics));
|
||||
}
|
||||
|
||||
time = getTimer();
|
||||
@@ -112,6 +179,10 @@ public class MisoScenePanel extends Sprite
|
||||
|
||||
protected var _isoView :IsoView;
|
||||
|
||||
protected var _ctx :MisoContext;
|
||||
|
||||
protected var _metrics :MisoSceneMetrics;
|
||||
|
||||
protected const DEF_WIDTH :int = 985;
|
||||
protected const DEF_HEIGHT :int = 560;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,41 @@
|
||||
//
|
||||
// Nenya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/nenya/
|
||||
//
|
||||
// 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.miso.client {
|
||||
|
||||
import as3isolib.display.primitive.IsoBox;
|
||||
import as3isolib.graphics.SolidColorFill;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.miso.util.MisoSceneMetrics;
|
||||
|
||||
public class ObjectTileIsoSprite extends IsoBox
|
||||
public class ObjectTileIsoSprite extends TileIsoSprite
|
||||
{
|
||||
public function ObjectTileIsoSprite (x :int, y :int, tileId :int)
|
||||
public function ObjectTileIsoSprite (x :int, y :int, tileId :int, tile :Tile,
|
||||
metrics :MisoSceneMetrics)
|
||||
{
|
||||
width = 1;
|
||||
height = 1;
|
||||
length = 1;
|
||||
super(x, y, tileId, tile, metrics);
|
||||
}
|
||||
|
||||
moveTo(x, y, 0);
|
||||
public override function layout (x :int, y :int, tile :Tile) :void
|
||||
{
|
||||
super.layout(x, y, tile);
|
||||
|
||||
// TEMP
|
||||
fill = new SolidColorFill(tileId * 1000, 1.0);
|
||||
setSize(tile.getBaseWidth(), tile.getBaseHeight(), 1);
|
||||
moveBy(-(tile.getBaseWidth() - 1), -(tile.getBaseHeight() - 1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// Nenya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/nenya/
|
||||
//
|
||||
// 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.miso.client {
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
|
||||
import as3isolib.core.IsoDisplayObject;
|
||||
import as3isolib.display.IsoSprite;
|
||||
import as3isolib.display.primitive.IsoBox;
|
||||
import as3isolib.graphics.SolidColorFill;
|
||||
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.TileUtil;
|
||||
import com.threerings.util.Log;
|
||||
import com.threerings.miso.util.MisoSceneMetrics;
|
||||
|
||||
public class TileIsoSprite extends IsoDisplayObject
|
||||
{
|
||||
private static var log :Log = Log.getLog(TileIsoSprite);
|
||||
|
||||
public function TileIsoSprite (x :int, y :int, tileId :int, tile :Tile,
|
||||
metrics :MisoSceneMetrics)
|
||||
{
|
||||
_tileId = tileId;
|
||||
|
||||
_metrics = metrics;
|
||||
|
||||
moveTo(x, y, 0);
|
||||
|
||||
layout(x, y, tile);
|
||||
|
||||
if (tile.getImage() == null) {
|
||||
var box :IsoBox = new IsoBox();
|
||||
box.width = width;
|
||||
box.height = height;
|
||||
box.length = length;
|
||||
box.fill = new SolidColorFill(0x808080, 0.5);
|
||||
addChild(box);
|
||||
} else {
|
||||
addSprite(tile);
|
||||
}
|
||||
tile.notifyOnLoad(loaded);
|
||||
}
|
||||
|
||||
public function layout (x :int, y :int, tile :Tile) :void
|
||||
{
|
||||
moveTo(x, y, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Our tile was loaded, set ourselves up appropriately to use it.
|
||||
*/
|
||||
public function loaded (tile :Tile) :void
|
||||
{
|
||||
removeAllChildren();
|
||||
addSprite(tile);
|
||||
}
|
||||
|
||||
protected function addSprite (tile :Tile) :void
|
||||
{
|
||||
var sprite :IsoSprite = new IsoSprite();
|
||||
var image :DisplayObject = tile.getImage();
|
||||
if (image == null) {
|
||||
log.warning("TileIsoSprite tile image is null", "tileId", _tileId);
|
||||
return;
|
||||
}
|
||||
// as3isolib uses top instead of bottom.
|
||||
image.x = -tile.getOriginX() + _metrics.tilewid *
|
||||
((tile.getBaseWidth() - tile.getBaseHeight())/2);;
|
||||
image.y = -tile.getOriginY() + _metrics.tilehei *
|
||||
(1 + (tile.getBaseWidth() + tile.getBaseHeight())/2);
|
||||
sprite.sprites = [image];
|
||||
sprite.setSize(tile.getBaseWidth(), tile.getBaseHeight(), 1);
|
||||
addChild(sprite);
|
||||
render();
|
||||
}
|
||||
|
||||
protected var _tileId :int;
|
||||
|
||||
protected var _metrics :MisoSceneMetrics;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Nenya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/nenya/
|
||||
//
|
||||
// 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.miso.tile {
|
||||
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
/**
|
||||
* Extends the basic tile manager and provides support for automatically generating fringes in
|
||||
* between different types of base tiles in a scene.
|
||||
*/
|
||||
public class MisoTileManager extends TileManager
|
||||
{
|
||||
// TODO: Fringing.
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,18 @@
|
||||
|
||||
package com.threerings.miso.util {
|
||||
|
||||
import com.threerings.miso.tile.MisoTileManager;
|
||||
|
||||
/**
|
||||
* Provides Miso code with access to the managers that it needs to do its
|
||||
* thing. For now it is just a stub.
|
||||
*/
|
||||
public interface MisoContext
|
||||
{
|
||||
/**
|
||||
* Returns a reference to the tile manager. This reference is valid
|
||||
* for the lifetime of the application.
|
||||
*/
|
||||
function getTileManager () :MisoTileManager;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user