GameConfigController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace App\Module\Game\AdminControllers;
  3. use App\Module\Game\DCache\ChestJsonConfig;
  4. use App\Module\Game\DCache\FarmHouseJsonConfig;
  5. use App\Module\Game\DCache\ItemJsonConfig;
  6. use App\Module\Game\DCache\PetJsonConfig;
  7. use App\Module\GameItems\AdminControllers\Tools\RefreshCheckTool;
  8. use App\Module\GameItems\AdminControllers\Tools\SyncChetsJsonTool;
  9. use App\Module\GameItems\AdminControllers\Tools\SyncItemsJsonTool;
  10. use Carbon\Carbon;
  11. use Dcat\Admin\Layout\Content;
  12. use Dcat\Admin\Layout\Row;
  13. use Dcat\Admin\Widgets\Card;
  14. use Dcat\Admin\Widgets\Table;
  15. use Dcat\Admin\Http\Controllers\AdminController;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Support\Facades\Artisan;
  18. use Spatie\RouteAttributes\Attributes\Resource;
  19. use Spatie\RouteAttributes\Attributes\Get;
  20. use Spatie\RouteAttributes\Attributes\Post;
  21. use UCore\Helper\Datetime;
  22. /**
  23. * 游戏配置表管理控制器
  24. *
  25. * 用于显示和管理游戏中的各种配置表
  26. */
  27. #[Resource('game-jsonconfigs', names: 'dcat.admin.game-jsonconfigs')]
  28. class GameConfigController extends AdminController
  29. {
  30. /**
  31. * 页面标题
  32. *
  33. * @var string
  34. */
  35. protected $title = '游戏配置表管理';
  36. /**
  37. * 页面描述
  38. *
  39. * @var string
  40. */
  41. protected $description = '查看和刷新游戏中的各种配置表';
  42. /**
  43. * 配置表首页
  44. *
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function index(Content $content)
  49. {
  50. return $content
  51. ->title($this->title)
  52. ->description($this->description)
  53. ->body(function (Row $row) {
  54. // 物品配置表卡片
  55. $row->column(6, $this->createConfigCard(
  56. '物品配置表',
  57. 'items.json',
  58. 'gameitems:generate-json',
  59. SyncItemsJsonTool::make(),
  60. $this->getItemConfigInfo()
  61. ));
  62. // 宝箱配置表卡片
  63. $row->column(6, $this->createConfigCard(
  64. '宝箱配置表',
  65. 'chest.json',
  66. 'gameitems:generate-chest-json',
  67. SyncChetsJsonTool::make(),
  68. $this->getChestConfigInfo()
  69. ));
  70. })
  71. ->body(function (Row $row) {
  72. // 宠物配置表卡片
  73. $row->column(6, $this->createConfigCard(
  74. '宠物配置表',
  75. 'pet_config.json, pet_level_config.json, pet_skill_config.json',
  76. 'pet:generate-json',
  77. 'game-jsonconfigs/refresh-pets',
  78. $this->getPetConfigInfo()
  79. ));
  80. // 农场房屋配置表卡片
  81. $row->column(6, $this->createConfigCard(
  82. '农场房屋配置表',
  83. 'farm_house.json',
  84. 'farm:generate-house-json',
  85. 'game-jsonconfigs/refresh-farm-house',
  86. $this->getFarmHouseConfigInfo()
  87. ));
  88. });
  89. }
  90. /**
  91. * 创建配置表信息卡片
  92. *
  93. * @param string $title 卡片标题
  94. * @param string $filename 文件名
  95. * @param string $command 生成命令
  96. * @param string $refreshUrl 刷新URL
  97. * @param array $info 配置信息
  98. * @return Card
  99. */
  100. protected function createConfigCard($title, $filename, $command, $refresh, $info)
  101. {
  102. $headers = [ '属性', '值' ];
  103. $rows = [];
  104. foreach ($info as $key => $value) {
  105. $rows[] = [ $key, $value ];
  106. }
  107. $card = new Card($title, Table::make($headers, $rows));
  108. $card->tool($refresh);
  109. $card->footer("<code>文件: {$filename}</code><br><code>命令: php artisan {$command}</code>");
  110. return $card;
  111. }
  112. /**
  113. * 获取物品配置表信息
  114. *
  115. * @return array
  116. */
  117. protected function getItemConfigInfo()
  118. {
  119. $data = ItemJsonConfig::getData();
  120. $info = [
  121. '生成时间' => Datetime::ts2string($data['generated_ts']),
  122. '物品数量' => isset($data['items']) ? count($data['items']) : 0,
  123. ];
  124. return $info;
  125. }
  126. /**
  127. * 获取宝箱配置表信息
  128. *
  129. * @return array
  130. */
  131. protected function getChestConfigInfo()
  132. {
  133. $data = ChestJsonConfig::getData();
  134. $info = [
  135. '生成时间' => Datetime::ts2string($data['generated_ts']),
  136. '宝箱数量' => isset($data['chest']) ? count($data['chest']) : 0,
  137. ];
  138. return $info;
  139. }
  140. /**
  141. * 获取宠物配置表信息
  142. *
  143. * @return array
  144. */
  145. protected function getPetConfigInfo()
  146. {
  147. $data = PetJsonConfig::getData();
  148. $petConfig = $data['pet_config'] ?? [];
  149. $petLevelConfig = $data['pet_level_config'] ?? [];
  150. $petSkillConfig = $data['pet_skill_config'] ?? [];
  151. $info = [
  152. '生成时间' => Datetime::ts2string($data['generated_ts']),
  153. '宠物数量' => isset($petConfig['pets']) ? count($petConfig['pets']) : 0,
  154. '等级配置数量' => isset($petLevelConfig['pet_levels']) ? count($petLevelConfig['pet_levels']) : 0,
  155. '技能配置数量' => isset($petSkillConfig['pet_skills']) ? count($petSkillConfig['pet_skills']) : 0,
  156. ];
  157. return $info;
  158. }
  159. /**
  160. * 获取农场房屋配置表信息
  161. *
  162. * @return array
  163. */
  164. protected function getFarmHouseConfigInfo()
  165. {
  166. $data = FarmHouseJsonConfig::getData();
  167. $info = [
  168. '生成时间' => Datetime::ts2string($data['generated_ts']),
  169. '房屋配置数量' => isset($data['house_configs']) ? count($data['house_configs']) : 0,
  170. ];
  171. return $info;
  172. }
  173. }