Beispiel #1
0
bool bind_Transforms(Handle<Object> parent)
{
    ScriptingManager* pManager = ScriptingManager::getSingletonPtr();

    Handle<FunctionTemplate> transforms = pManager->getClassTemplate("Athena.Entities.Transforms");

    if (transforms.IsEmpty())
    {
        assert(!pManager->getClassTemplate("Athena.Entities.Component").IsEmpty());

        // Declaration of the class
        transforms = FunctionTemplate::New(Transforms_New);
        transforms->InstanceTemplate()->SetInternalFieldCount(1);
        transforms->Inherit(pManager->getClassTemplate("Athena.Entities.Component"));

        // Attributes
        AddAttribute(transforms, "position",           Transforms_GetPosition,           Transforms_SetPosition);
        AddAttribute(transforms, "worldPosition",      Transforms_GetWorldPosition,      0);
        AddAttribute(transforms, "orientation",        Transforms_GetOrientation,        Transforms_SetOrientation);
        AddAttribute(transforms, "worldOrientation",   Transforms_GetWorldOrientation,   0);
        AddAttribute(transforms, "inheritOrientation", Transforms_GetInheritOrientation, Transforms_SetInheritOrientation);
        AddAttribute(transforms, "scale",              Transforms_GetScale,              Transforms_SetScale);
        AddAttribute(transforms, "worldScale",         Transforms_GetWorldScale,         0);
        AddAttribute(transforms, "inheritScale",       Transforms_GetInheritScale,       Transforms_SetInheritScale);

        // Methods
        AddMethod(transforms, "translate",        Transforms_Translate);
        AddMethod(transforms, "setDirection",     Transforms_SetDirection);
        AddMethod(transforms, "lookAt",           Transforms_LookAt);
        AddMethod(transforms, "roll",             Transforms_Roll);
        AddMethod(transforms, "pitch",            Transforms_Pitch);
        AddMethod(transforms, "yaw",              Transforms_Yaw);
        AddMethod(transforms, "rotate",           Transforms_Rotate);
        AddMethod(transforms, "resetOrientation", Transforms_ResetOrientation);
        AddMethod(transforms, "rescale",          Transforms_Rescale);

        pManager->declareClassTemplate("Athena.Entities.Transforms", transforms);

        parent->Set(String::New("Transforms_TYPE"), String::New(Athena::Entities::Transforms::TYPE.c_str()));

        parent->Set(String::New("TS_LOCAL"),  Uint32::New(Transforms::TS_LOCAL));
        parent->Set(String::New("TS_PARENT"), Uint32::New(Transforms::TS_PARENT));
        parent->Set(String::New("TS_WORLD"),  Uint32::New(Transforms::TS_WORLD));
    }

    // Add the class to the parent
    return parent->Set(String::New("Transforms"), transforms->GetFunction());
}
Handle<FunctionTemplate> MetadataNode::GetConstructorFunctionTemplate(Isolate *isolate, MetadataTreeNode *treeNode)
{
	SET_PROFILER_FRAME();

	Handle<FunctionTemplate> ctorFuncTemplate;
	auto itFound = s_ctorFuncCache.find(treeNode);
	if (itFound != s_ctorFuncCache.end())
	{
		ctorFuncTemplate = Local<FunctionTemplate>::New(isolate, *itFound->second);
		return ctorFuncTemplate;
	}

	auto node = GetOrCreateInternal(treeNode);
	auto ctorCallbackData = External::New(isolate, node);
	auto isInterface = s_metadataReader.IsNodeTypeInterface(treeNode->type);
	auto funcCallback = isInterface ? InterfaceConstructorCallback : ClassConstructorCallback;
	ctorFuncTemplate = FunctionTemplate::New(isolate, funcCallback, ctorCallbackData);

	auto baseClass = s_metadataReader.GetBaseClassNode(treeNode);
	Handle<Function> baseCtorFunc;
	if ((baseClass != treeNode) && (baseClass != nullptr) && (baseClass->offsetValue > 0))
	{
		auto baseFuncTemplate = GetConstructorFunctionTemplate(isolate, baseClass);
		if (!baseFuncTemplate.IsEmpty())
		{
			ctorFuncTemplate->Inherit(baseFuncTemplate);
			baseCtorFunc = baseFuncTemplate->GetFunction();
		}
	}

	auto prototypeTemplate = ctorFuncTemplate->PrototypeTemplate();

	auto ctorFunc = node->SetMembers(isolate, ctorFuncTemplate, prototypeTemplate, treeNode);
	if (!baseCtorFunc.IsEmpty())
	{
		ctorFunc->SetPrototype(baseCtorFunc);
	}

	auto pft = new Persistent<FunctionTemplate>(isolate, ctorFuncTemplate);
	s_ctorFuncCache.insert(make_pair(treeNode, pft));

	SetInnnerTypes(isolate, ctorFunc, treeNode);

	SetTypeMetadata(isolate, ctorFunc, new TypeMetadata(s_metadataReader.ReadTypeName(treeNode)));

	return ctorFuncTemplate;
}
   v8::Handle<v8::Object> WrapElementDocument(v8::Handle<v8::Context> context, Rocket::Core::ElementDocument* v)
   {
      
      v8::HandleScope handle_scope;

      Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_elementDocumentWrapper);
      if(templt.IsEmpty())
      {

        templt = FunctionTemplate::New();
        templt->Inherit(GetElementTemplate());
        templt->SetClassName(String::New("ElementDocument"));
        templt->InstanceTemplate()->SetInternalFieldCount(1);
		  templt->InstanceTemplate()->SetNamedPropertyHandler(
           ELNamedPropertyGetter,
           ELNamedPropertySetter,
           ELNamedPropertyQuery,
           ELNamedPropertyDeleter,
           ELNamedPropertyEnumerator
        );

        Handle<ObjectTemplate> proto = templt->PrototypeTemplate();

		  proto->Set("hide", FunctionTemplate::New(EDHide));
        proto->Set("toString", FunctionTemplate::New(EDToString));
        proto->Set("show", FunctionTemplate::New(EDShow));
        proto->Set("hide", FunctionTemplate::New(EDHide));
        proto->Set("close", FunctionTemplate::New(EDClose));

        GetScriptSystem()->SetTemplateBySID(s_elementDocumentWrapper, templt);

      }
      Local<Object> instance = templt->GetFunction()->NewInstance();
      instance->SetInternalField(0, External::New(v));
      return handle_scope.Close(instance);

   }