2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** tilemap-binding.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
2021-10-16 20:56:17 +00:00
|
|
|
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
|
2013-09-01 14:27:21 +00:00
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp 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 General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tilemap.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "bitmap.h"
|
|
|
|
#include "table.h"
|
|
|
|
|
|
|
|
#include "disposable-binding.h"
|
|
|
|
#include "binding-util.h"
|
|
|
|
#include "binding-types.h"
|
|
|
|
|
2014-08-29 11:52:10 +00:00
|
|
|
DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
RB_METHOD(tilemapAutotilesSet)
|
|
|
|
{
|
|
|
|
Tilemap::Autotiles *a = getPrivateData<Tilemap::Autotiles>(self);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
VALUE bitmapObj;
|
|
|
|
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
|
|
|
|
|
|
|
a->set(i, bitmap);
|
|
|
|
|
|
|
|
VALUE ary = rb_iv_get(self, "array");
|
|
|
|
rb_ary_store(ary, i, bitmapObj);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(tilemapAutotilesGet)
|
|
|
|
{
|
|
|
|
int i;
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args (argc, argv, "i", &i RB_ARG_END);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
if (i < 0 || i > 6)
|
|
|
|
return Qnil;
|
|
|
|
|
|
|
|
VALUE ary = rb_iv_get(self, "array");
|
|
|
|
|
|
|
|
return rb_ary_entry(ary, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TYPE(Tilemap);
|
|
|
|
|
|
|
|
RB_METHOD(tilemapInitialize)
|
|
|
|
{
|
|
|
|
Tilemap *t;
|
|
|
|
|
|
|
|
/* Get parameters */
|
|
|
|
VALUE viewportObj = Qnil;
|
|
|
|
Viewport *viewport = 0;
|
|
|
|
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-01-24 21:23:30 +00:00
|
|
|
if (!NIL_P(viewportObj))
|
2013-09-01 14:27:21 +00:00
|
|
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
|
|
|
|
|
|
|
/* Construct object */
|
|
|
|
t = new Tilemap(viewport);
|
|
|
|
|
2013-10-30 09:06:24 +00:00
|
|
|
setPrivateData(self, t);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
rb_iv_set(self, "viewport", viewportObj);
|
|
|
|
|
|
|
|
wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType);
|
|
|
|
|
|
|
|
VALUE autotilesObj = rb_iv_get(self, "autotiles");
|
|
|
|
|
|
|
|
VALUE ary = rb_ary_new2(7);
|
|
|
|
for (int i = 0; i < 7; ++i)
|
|
|
|
rb_ary_push(ary, Qnil);
|
|
|
|
|
|
|
|
rb_iv_set(autotilesObj, "array", ary);
|
|
|
|
|
2014-09-26 16:21:50 +00:00
|
|
|
/* Circular reference so both objects are always
|
|
|
|
* alive at the same time */
|
|
|
|
rb_iv_set(autotilesObj, "tilemap", self);
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(tilemapGetAutotiles)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
2014-09-23 19:12:58 +00:00
|
|
|
checkDisposed<Tilemap>(self);
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
return rb_iv_get(self, "autotiles");
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(tilemapUpdate)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
Tilemap *t = getPrivateData<Tilemap>(self);
|
|
|
|
|
|
|
|
t->update();
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2013-10-06 07:55:27 +00:00
|
|
|
RB_METHOD(tilemapGetViewport)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
2014-09-23 19:12:58 +00:00
|
|
|
checkDisposed<Tilemap>(self);
|
2013-10-06 07:55:27 +00:00
|
|
|
|
|
|
|
return rb_iv_get(self, "viewport");
|
|
|
|
}
|
|
|
|
|
2014-09-04 23:26:03 +00:00
|
|
|
DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset")
|
|
|
|
DEF_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data")
|
|
|
|
DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data")
|
|
|
|
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities")
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
DEF_PROP_B(Tilemap, Visible)
|
|
|
|
|
|
|
|
DEF_PROP_I(Tilemap, OX)
|
|
|
|
DEF_PROP_I(Tilemap, OY)
|
|
|
|
|
|
|
|
void
|
|
|
|
tilemapBindingInit()
|
|
|
|
{
|
|
|
|
VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject);
|
2013-10-30 09:06:24 +00:00
|
|
|
rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
_rb_define_method(klass, "[]=", tilemapAutotilesSet);
|
|
|
|
_rb_define_method(klass, "[]", tilemapAutotilesGet);
|
|
|
|
|
|
|
|
klass = rb_define_class("Tilemap", rb_cObject);
|
2013-10-30 09:06:24 +00:00
|
|
|
rb_define_alloc_func(klass, classAllocate<&TilemapType>);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
disposableBindingInit<Tilemap>(klass);
|
|
|
|
|
|
|
|
_rb_define_method(klass, "initialize", tilemapInitialize);
|
|
|
|
_rb_define_method(klass, "autotiles", tilemapGetAutotiles);
|
|
|
|
_rb_define_method(klass, "update", tilemapUpdate);
|
|
|
|
|
2013-10-06 07:55:27 +00:00
|
|
|
_rb_define_method(klass, "viewport", tilemapGetViewport);
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
|
|
|
|
INIT_PROP_BIND( Tilemap, MapData, "map_data" );
|
|
|
|
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );
|
|
|
|
INIT_PROP_BIND( Tilemap, Priorities, "priorities" );
|
|
|
|
INIT_PROP_BIND( Tilemap, Visible, "visible" );
|
|
|
|
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
|
|
|
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
|
|
|
}
|