live2d_api/rand_textures/index.php

36 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2018-03-03 01:39:22 +08:00
<?php
isset($_GET['id']) ? $id = $_GET['id'] : exit('error');
require '../tools/modelList.php';
require '../tools/modelTextures.php';
2019-02-09 15:17:15 +08:00
require '../tools/jsonCompatible.php';
2018-03-03 01:39:22 +08:00
$modelList = new modelList();
$modelTextures = new modelTextures();
2019-02-09 15:17:15 +08:00
$jsonCompatible = new jsonCompatible();
2018-03-03 01:39:22 +08:00
$id = explode('-', $id);
$modelId = (int)$id[0];
$modelTexturesId = isset($id[1]) ? (int)$id[1] : false;
$modelName = $modelList->id_to_name($modelId);
2019-02-09 15:17:15 +08:00
$modelTexturesList = is_array($modelName) ? array('textures' => $modelName) : $modelTextures->get_list($modelName);
2018-03-03 01:39:22 +08:00
if (count($modelTexturesList['textures']) <= 1) {
$modelTexturesNewId = 1;
} else {
$modelTexturesGenNewId = true;
if ($modelTexturesId == 0) $modelTexturesId = 1;
while ($modelTexturesGenNewId) {
$modelTexturesNewId = rand(0, count($modelTexturesList['textures'])-1)+1;
$modelTexturesGenNewId = $modelTexturesNewId == $modelTexturesId ? true : false;
}
}
header("Content-type: application/json");
2019-02-09 15:17:15 +08:00
echo $jsonCompatible->json_encode(array('textures' => array(
2018-03-03 01:39:22 +08:00
'id' => $modelTexturesNewId,
'name' => $modelTexturesList['textures'][$modelTexturesNewId-1],
'model' => is_array($modelName) ? $modelName[$modelTexturesNewId-1] : $modelName
2019-02-09 15:17:15 +08:00
)));