//
// Generated by dtk
// Translation Unit: f_pc_node.cpp
//

#include "f_pc/f_pc_node.h"
#include "f_pc/f_pc_layer_iter.h"

/* 8003EFC8-8003EFEC       .text fpcNd_DrawMethod__FP21nodedraw_method_classPv */
s32 fpcNd_DrawMethod(nodedraw_method_class* i_nodeMethods, void* i_data) {
    return fpcMtd_Method(i_nodeMethods->mpDrawFunc, i_data);
}

/* 8003EFEC-8003F058       .text fpcNd_Draw__FP18process_node_class */
s32 fpcNd_Draw(process_node_class* i_procNode) {
    s32 ret = 0;
    if (i_procNode->mUnk0 == 0) {
        layer_class* curLayer_p = fpcLy_CurrentLayer();
        fpcLy_SetCurrentLayer(&i_procNode->mLayer);
        ret = fpcNd_DrawMethod(i_procNode->mpNodeMtd, i_procNode);
        fpcLy_SetCurrentLayer(curLayer_p);
    }
    return ret;
}

/* 8003F058-8003F0B4       .text fpcNd_Execute__FP18process_node_class */
s32 fpcNd_Execute(process_node_class* i_procNode) {
    s32 ret;
    layer_class* curLayer_p = fpcLy_CurrentLayer();
    fpcLy_SetCurrentLayer(&i_procNode->mLayer);
    ret = fpcMtd_Execute(&i_procNode->mpNodeMtd->mBase, i_procNode);
    fpcLy_SetCurrentLayer(curLayer_p);
    return ret;
}

int g_fpcNd_type;

/* 8003F0B4-8003F134       .text fpcNd_IsCreatingFromUnder__FPv */
void* fpcNd_IsCreatingFromUnder(void* i_procNode) {
    layer_class* layer;
    process_node_class* pProcNode = static_cast<process_node_class*>(i_procNode);
    if (pProcNode != NULL && fpcBs_Is_JustOfType(g_fpcNd_type, pProcNode->mBase.mSubType) != FALSE) {
        layer = &pProcNode->mLayer;
        if (fpcLy_IsCreatingMesg(layer) == 0) {
            return (process_node_class*)fpcLyIt_Judge(
                layer, (fpcLyIt_JudgeFunc)fpcNd_IsCreatingFromUnder, NULL);
        } else {
            return pProcNode;
        }
    } else {
        return NULL;
    }
}

static s32 g_fpcNd_IsCheckOfDeleteTiming = 1;

/* 8003F134-8003F174       .text fpcNd_IsDeleteTiming__FP18process_node_class */
s32 fpcNd_IsDeleteTiming(process_node_class* i_procNode) {
    if (g_fpcNd_IsCheckOfDeleteTiming == 1 && fpcNd_IsCreatingFromUnder(i_procNode) != NULL) {
        return 0;
    } else {
        return 1;
    }
}

/* 8003F174-8003F19C       .text fpcNd_IsDelete__FP18process_node_class */
s32 fpcNd_IsDelete(process_node_class* i_procNode) {
    return fpcMtd_IsDelete(&i_procNode->mpNodeMtd->mBase, i_procNode);
}

/* 8003F19C-8003F200       .text fpcNd_Delete__FP18process_node_class */
s32 fpcNd_Delete(process_node_class* i_procNode) {
    if ((fpcLy_IsDeletingMesg(&i_procNode->mLayer) == 0) && fpcMtd_Delete(&i_procNode->mpNodeMtd->mBase, i_procNode) == 1) {
        i_procNode->mBase.mSubType = 0;
        return fpcLy_Delete(&i_procNode->mLayer);
    } else {
        return 0;
    }
}

/* 8003F200-8003F29C       .text fpcNd_Create__FP18process_node_class */
s32 fpcNd_Create(process_node_class* i_procNode) {
    // this cast looks like a fake match, but it doesn't match without the cast, naive approach
    // swaps r31 and r30 most likely it gets casted to another unknown struct
    process_node_class* pProcNode = (process_node_class*)i_procNode;
    layer_class* curLayer_p;
    s32 ret;
    if (pProcNode->mBase.mInitState == 0) {
        node_process_profile_definition* pProcProfileDef = (node_process_profile_definition*)pProcNode->mBase.mpProf;
        pProcNode->mBase.mSubType = fpcBs_MakeOfType(&g_fpcNd_type);
        pProcNode->mpNodeMtd = (nodedraw_method_class*)pProcProfileDef->mSubMtd;
        fpcLy_Create(&pProcNode->mLayer, pProcNode, pProcNode->mLayerNodeLists, 0x10);
        pProcNode->mUnk0 = 0;
    }
    curLayer_p = fpcLy_CurrentLayer();
    fpcLy_SetCurrentLayer(&pProcNode->mLayer);
    ret = fpcMtd_Create(&pProcNode->mpNodeMtd->mBase, pProcNode);
    fpcLy_SetCurrentLayer(curLayer_p);
    return ret;
}

nodedraw_method_class g_fpcNd_Method = {
    (process_method_func)fpcNd_Create,
    (process_method_func)fpcNd_Delete,
    (process_method_func)fpcNd_Execute,
    (process_method_func)fpcNd_IsDelete,
    (process_method_func)fpcNd_Draw
};
