GameConfigController.php 5.8 KB

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