Skip to content

Commit

Permalink
Adding Sample and Mirror Y feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kestrelm committed Apr 12, 2016
1 parent 5566302 commit 189b12c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 2 deletions.
37 changes: 35 additions & 2 deletions creaturegodot/creaturegodot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
#include "globals.h"
#include <string>
#include <iostream>
#include <fstream>

static std::map<std::string, std::shared_ptr<CreatureModule::CreatureAnimation> > global_animations;
static std::map<std::string, std::shared_ptr<CreatureModule::CreatureLoadDataPacket> > global_load_data_packets;

static bool is_file_exist(const char *fileName)
{
std::ifstream infile(fileName);
return infile.good();
}

static std::string GetAnimationToken(const std::string& filename_in, const std::string& name_in)
{
return filename_in + std::string("_") + name_in;
Expand All @@ -14,6 +21,11 @@ static std::string GetAnimationToken(const std::string& filename_in, const std::
static bool
LoadDataPacket(const std::string& filename_in)
{
if(!is_file_exist(filename_in.c_str()))
{
return false;
}

if (global_load_data_packets.count(filename_in) > 0)
{
// file already loaded, just return
Expand Down Expand Up @@ -234,8 +246,13 @@ void CreatureGodot::_notification(int p_what) {
{
return;
}

Vector<Color> colors;

if(manager)
{
manager->SetMirrorY(mirror_y);
}

Vector<Color> colors;
colors.push_back(color);
VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(),indices,points,colors,uvs,texture.is_valid()?texture->get_rid():RID());

Expand Down Expand Up @@ -285,6 +302,17 @@ Ref<Texture> CreatureGodot::get_texture() const{
return texture;
}

void CreatureGodot::set_mirror_y(bool flag_in)
{
mirror_y = flag_in;
update();
}

bool CreatureGodot::get_mirror_y() const
{
return mirror_y;
}

void CreatureGodot::_bind_methods() {

ObjectTypeDB::bind_method(_MD("set_color","color"),&CreatureGodot::set_color);
Expand All @@ -301,6 +329,9 @@ void CreatureGodot::_bind_methods() {

ObjectTypeDB::bind_method(_MD("set_offset","offset"),&CreatureGodot::set_offset);
ObjectTypeDB::bind_method(_MD("get_offset"),&CreatureGodot::get_offset);

ObjectTypeDB::bind_method(_MD("set_mirror_y","offset"),&CreatureGodot::set_mirror_y);
ObjectTypeDB::bind_method(_MD("get_mirror_y"),&CreatureGodot::get_mirror_y);

ObjectTypeDB::bind_method(_MD("load_json"),&CreatureGodot::load_json);
ObjectTypeDB::bind_method(_MD("update_animation"),&CreatureGodot::update_animation);
Expand All @@ -309,6 +340,7 @@ void CreatureGodot::_bind_methods() {

ADD_PROPERTY( PropertyInfo(Variant::REAL,"anim_speed"),_SCS("set_anim_speed"),_SCS("get_anim_speed"));
ADD_PROPERTY( PropertyInfo(Variant::STRING,"asset_filename"),_SCS("set_asset_filename"),_SCS("get_asset_filename"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"mirror_y"),_SCS("set_mirror_y"),_SCS("get_mirror_y"));
ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset"));
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
Expand All @@ -318,4 +350,5 @@ CreatureGodot::CreatureGodot() {
color=Color(1,1,1);
rect_cache_dirty=true;
anim_speed = 2.0f;
mirror_y = false;
}
4 changes: 4 additions & 0 deletions creaturegodot/creaturegodot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CreatureGodot : public Node2D {
Ref<Texture> texture;
String asset_filename;
float anim_speed;
bool mirror_y;

Vector2 offset;
mutable bool rect_cache_dirty;
Expand Down Expand Up @@ -55,6 +56,9 @@ class CreatureGodot : public Node2D {

void set_offset(const Vector2& p_offset);
Vector2 get_offset() const;

void set_mirror_y(bool flag_in);
bool get_mirror_y() const;

//editor stuff

Expand Down
5 changes: 5 additions & 0 deletions testPlugin/engine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[application]

name="testPlugin"
main_scene="res://new_scene.scn"
icon="res://icon.png"
Binary file added testPlugin/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions testPlugin/icon.png.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gen_mipmaps=false
17 changes: 17 additions & 0 deletions testPlugin/new_scene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

extends CreatureGodot

# member variables here, example:
# var a=2
# var b="textvar"

func _ready():
# Called every time the node is added to the scene.
# Initialization here
set_process(true)

pass

func _process(delta):
self.update_animation(delta)

Binary file added testPlugin/new_scene.scn
Binary file not shown.
Binary file added testPlugin/utahraptorExport_character_data.zip
Binary file not shown.
Binary file added testPlugin/utahraptorExport_character_img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 189b12c

Please sign in to comment.