Esempio n. 1
0
function avatar_guest_get_configuration($user_id = NULL)
{
    //  return "[{'tipe':'gender','element':'male_base'},{'tipe':'Face','element':'male_head','material':'','eye_brows':'brows_01_01','eyes':'eyes_a_01_01','lip':'lips_a_01_01'},{'tipe':'Hair','element':'male_hair_04','material':'male_hair_04_1'},{'tipe':'Body','element':'male_hoodie_medium','material':'male_hoodie_01_1'},{'tipe':'Pants','element':'male_pants_medium','material':'male_pants_4'},{'tipe':'Shoes','element':'male_shoes_01','material':'male_shoes_01_2'},{'tipe':'Hand','element':'male_body_hand','material':'male_body'}, {'tipe':'Skin','color':'1'}]";
    //  return "[{'tipe':'gender','element':'female_base'},{'tipe':'Face','element':'female_head','material':'','eye_brows':'brows_01_01','eyes':'eyes_a_01_01','lip':'lips_a_01_01'},{'tipe':'Hair','element':'male_hair_04','material':'male_hair_04_1'},{'tipe':'Body','element':'male_hoodie_medium','material':'male_hoodie_01_1'},{'tipe':'Pants','element':'female_pants_medium','material':'female_pants_01'},{'tipe':'Shoes','element':'female_shoes_01','material':'female_shoes_01_2'},{'tipe':'Hand','element':'female_body_hand','material':'female_body'}, {'tipe':'Skin','color':'1'}]";
    if (!isset($user_id)) {
        $user_id = func_arg(0);
    }
    // if(!isset($user_id)){
    // $user_id = $_SESSION['user_id'];
    // }
    $lilo_mongo = new LiloMongo();
    $lilo_mongo->selectDB('Users');
    if (!isset($user_id)) {
        // jika dipanggil dari unity, parameter yg digunakan adalah session_id
        $session_id = func_arg(0);
        if (isset($session_id) && trim($session_id) != '') {
            $lilo_mongo->selectCollection('Session');
            $session_data = $lilo_mongo->findOne(array('session_id' => $session_id));
            $user_id = $session_data['user_id'];
        }
    }
    $lilo_mongo->selectCollection('Avatar');
    $conf = $lilo_mongo->findOne(array('user_id' => $user_id));
    // write_log(array('log_text' => "UserID: $user_id \n\n" . print_r($conf, true)));
    if (!$conf || !is_array($conf) || !count($conf)) {
        // berikan konfigurasi default
        $sex = avatar_user_get_gender();
        $lilo_mongo->selectDB('Assets');
        $lilo_mongo->selectCollection('DefaultAvatar');
        $default_avatar = $lilo_mongo->findOne(array('gender' => $sex, 'size' => 'medium'));
        return $default_avatar['configuration'];
    }
    $config = str_replace("'", '"', $conf['configuration']);
    $config_array = json_decode($config);
    //	return print_r($config_array, true);
    for ($idx = 0; $idx < count($config_array); $idx++) {
        if ($config_array[$idx]->element2 == 'undefined') {
            $config_array[$idx]->element2 = '';
        }
        if ($config_array[$idx]->material2 == 'undefined') {
            $config_array[$idx]->material2 = '';
        }
    }
    return str_replace('"', "'", json_encode($config_array));
    //	return print_r($conf['configuration'], true);
}
Esempio n. 2
0
function avatar_user_get_animation($user_id = NULL, $option = NULL)
{
    // dummy
    //	$anim_array = array('item_pants', 'walkin', 'idle1', 'walk');
    //
    //	if($option == 'json'){
    //		return json_encode($anim_array);
    //	}
    //
    //	return str_replace('"', "'", json_encode($anim_array));
    // dummy
    // revisi 111011: animation disesuaikan dgn gender yg dipilih user di avatar editor
    //	atau...
    //	saat ubah gender di avatar editor, langsung ubah Users.Animation?
    if (!isset($user_id)) {
        $user_id = func_arg(0);
    }
    if (!isset($user_id)) {
        $session_id = $_SESSION['session_id'];
        $user_id = avatar_user_session_to_user_id($session_id);
    }
    // berdasar $user_id, dapatkan gender. defaultnya 'male'
    $gender = avatar_user_get_gender($user_id);
    // dapatkan konfigurasi animation utk current user
    $lilo_mongo = new LiloMongo();
    $lilo_mongo->selectDB('Users');
    $lilo_mongo->selectCollection('Animation');
    $conf = $lilo_mongo->findOne(array('user_id' => $user_id));
    if (is_array($conf)) {
        $config = array();
        $log = '';
        // cek dulu, apakah $conf['configuration'] sesuai gender di avatar dan sesuai asset di bundles/animations/
        for ($idx = 0; $idx < count($conf['configuration']); $idx++) {
            // format: [gender] [@] [animation_name]
            $anim_expl = explode('@', $conf['configuration'][$idx]);
            $conf['configuration'][$idx] = $gender . '@' . $anim_expl[1];
            $anim_file_exists = file_exists($_SESSION['basedir'] . '/bundles/animations/' . $conf['configuration'][$idx] . '.unity3d');
            $log .= '<br />' . $conf['configuration'][$idx] . '.unity3d' . ($anim_file_exists ? ' ada' : ' <b>ga</b> ada');
            if ($anim_file_exists) {
                $config[] = $conf['configuration'][$idx];
            }
        }
        return json_encode($config);
    } else {
        $config = array($gender . '@bye', $gender . '@happy', $gender . '@idle1', $gender . '@idle2', $gender . '@jump', $gender . '@pickup', $gender . '@run', $gender . '@walk');
        return json_encode($config);
    }
    //	if($option == 'json'){
    //return json_encode($conf['configuration']);
    //	}
    //	return print_r($conf['configuration'], true);
}