static void duk_push_rayqueryresult(duk_context* ctx, const RayQueryResult& result)
{
    duk_push_object(ctx);

    duk_push_new_vector3(ctx, result.position_);
    duk_put_prop_string(ctx, -2, "position");

    duk_push_new_vector3(ctx, result.normal_);
    duk_put_prop_string(ctx, -2, "normal");

    duk_push_new_vector2(ctx, result.textureUV_);
    duk_put_prop_string(ctx, -2, "textureUV");

    duk_push_number(ctx, result.distance_);
    duk_put_prop_string(ctx, -2, "distance");

    js_push_class_object_instance(ctx, result.drawable_, "Drawable");
    duk_put_prop_string(ctx, -2, "drawable");

    js_push_class_object_instance(ctx, result.node_, "Node");
    duk_put_prop_string(ctx, -2, "node");

    duk_push_number(ctx, (duk_double_t) result.subObject_);
    duk_put_prop_string(ctx, -2, "subObject");

}
Ejemplo n.º 2
0
void jsapi_init_toolcore(JSVM* vm)
{
    duk_context* ctx = vm->GetJSContext();

    jsb_package_toolcore_init(vm);

    duk_get_global_string(ctx, "ToolCore");

    duk_push_c_function(ctx, js_atomic_GetToolEnvironment, 0);
    duk_put_prop_string(ctx, -2, "getToolEnvironment");

    js_push_class_object_instance(ctx, vm->GetSubsystem<ToolEnvironment>(), "ToolEnvironment");
    duk_put_prop_string(ctx, -2, "toolEnvironment");

    duk_push_c_function(ctx, js_atomic_GetToolSystem, 0);
    duk_put_prop_string(ctx, -2, "getToolSystem");

    js_push_class_object_instance(ctx, vm->GetSubsystem<ToolSystem>(), "ToolSystem");
    duk_put_prop_string(ctx, -2, "toolSystem");

    js_push_class_object_instance(ctx, vm->GetSubsystem<BuildSystem>(), "BuildSystem");
    duk_put_prop_string(ctx, -2, "buildSystem");

    duk_push_c_function(ctx, js_atomic_GetLicenseSystem, 0);
    duk_put_prop_string(ctx, -2, "getLicenseSystem");

    js_push_class_object_instance(ctx, vm->GetSubsystem<LicenseSystem>(), "LicenseSystem");
    duk_put_prop_string(ctx, -2, "licenseSystem");

    duk_push_c_function(ctx, js_atomic_GetAssetDatabase, 0);
    duk_put_prop_string(ctx, -2, "getAssetDatabase");

    js_push_class_object_instance(ctx, vm->GetSubsystem<AssetDatabase>(), "AssetDatabase");
    duk_put_prop_string(ctx, -2, "assetDatabase");

    duk_pop(ctx);

    js_class_get_prototype(ctx, "ToolCore", "AssetDatabase");
    duk_push_c_function(ctx, AssetDatabase_GetFolderAssets, 1);
    duk_put_prop_string(ctx, -2, "getFolderAssets");
    duk_push_c_function(ctx, AssetDatabase_GetAssetsByImporterType, 2);
    duk_put_prop_string(ctx, -2, "getAssetsByImporterType");
    duk_pop(ctx);

    js_class_get_prototype(ctx, "ToolCore", "ModelImporter");
    duk_push_c_function(ctx, ModelImporter_GetAnimations, 0);
    duk_put_prop_string(ctx, -2, "getAnimations");
    duk_pop(ctx);
}
Ejemplo n.º 3
0
static int AssetDatabase_GetAssetsByImporterType(duk_context* ctx)
{
    JSVM* vm = JSVM::GetJSVM(ctx);
    ToolSystem* ts = vm->GetSubsystem<ToolSystem>();
    AssetDatabase* db = vm->GetSubsystem<AssetDatabase>();
    Project* project = ts->GetProject();

    StringHash type = duk_require_string(ctx, 0);
    String resourceType = duk_require_string(ctx, 1);

    duk_push_array(ctx);

    if (!project)
        return 1;

    PODVector<Asset*> assets;
    db->GetAssetsByImporterType(type, resourceType, assets);

    for(unsigned i = 0; i < assets.Size(); i++)
    {
        js_push_class_object_instance(ctx, assets[i], 0);
        duk_put_prop_index(ctx, -2, i);
    }

    return 1;
}
Ejemplo n.º 4
0
void jsapi_init_editor(JSVM* vm)
{
    duk_context* ctx = vm->GetJSContext();

    jsb_package_editor_init(vm);

    duk_get_global_string(ctx, "Atomic");

    if (vm->GetContext()->GetEditorContext()) {
        js_push_class_object_instance(ctx, vm->GetSubsystem<EditorMode>(), "EditorMode");
        duk_put_prop_string(ctx, -2, "editorMode");
    }

    duk_pop(ctx);

}
Ejemplo n.º 5
0
static int ModelImporter_GetAnimations(duk_context* ctx)
{
    duk_push_this(ctx);
    ModelImporter* importer = js_to_class_instance<ModelImporter>(ctx, -1, 0);

    PODVector<Animation*> animations;
    importer->GetAnimations(animations);

    duk_push_array(ctx);

    for(unsigned i = 0; i < animations.Size(); i++)
    {
        js_push_class_object_instance(ctx, animations[i], 0);
        duk_put_prop_index(ctx, -2, i);
    }

    return 1;
}
Ejemplo n.º 6
0
static int js_atomic_GetAssetDatabase(duk_context* ctx)
{
    JSVM* vm = JSVM::GetJSVM(ctx);
    js_push_class_object_instance(ctx, vm->GetSubsystem<AssetDatabase>());
    return 1;
}
Ejemplo n.º 7
0
static int js_atomic_GetLicenseSystem(duk_context* ctx)
{
    JSVM* vm = JSVM::GetJSVM(ctx);
    js_push_class_object_instance(ctx, vm->GetSubsystem<LicenseSystem>());
    return 1;
}
Ejemplo n.º 8
0
static int js_atomic_GetToolEnvironment(duk_context* ctx)
{
    JSVM* vm = JSVM::GetJSVM(ctx);
    js_push_class_object_instance(ctx, vm->GetSubsystem<ToolEnvironment>());
    return 1;
}
void JSEventHelper::HandleEvent(StringHash eventType, VariantMap& eventData)
{
    if (object_.Null())
        return;

    JSVM* vm = JSVM::GetJSVM(0);
    duk_context* ctx = vm->GetJSContext();

    duk_idx_t top = duk_get_top(ctx);

    js_push_class_object_instance(ctx, this);

    duk_get_prop_string(ctx, -1, "__eventHelperFunctions");

    assert(duk_is_object(ctx, -1));

    duk_get_prop_string(ctx, -1, eventType.ToString().CString());

    if (duk_is_function(ctx, -1))
    {
        // look in the variant map cache
        duk_push_global_stash(ctx);
        duk_get_prop_index(ctx, -1, JS_GLOBALSTASH_VARIANTMAP_CACHE);
        duk_push_pointer(ctx, (void*) &eventData);
        duk_get_prop(ctx, -2);

        if (!duk_is_object(ctx, -1))
        {
            // pop result
            duk_pop(ctx);

            // we need to push a new variant map and store to cache
            // the cache object will be cleared at the send end in  the
            // global listener above
            js_push_variantmap(ctx, eventData);
            duk_push_pointer(ctx, (void*) &eventData);
            duk_dup(ctx, -2);
            duk_put_prop(ctx, -4);

        }

        duk_remove(ctx, -2); // vmap cache
        duk_remove(ctx, -2); // global stash

        if (duk_pcall(ctx, 1) != 0)
        {
            vm->SendJSErrorEvent();
        }
        else
        {
            // For widget events, need to check return value
            // and set whether handled
            if (eventType == E_WIDGETEVENT)
            {
                if (duk_is_boolean(ctx, -1))
                {
                    if (duk_to_boolean(ctx, -1))
                    {
                        eventData[WidgetEvent::P_HANDLED] = true;
                    }
                }
            }
        }
    }

    duk_set_top(ctx, top);

}