From 5c0445d3ab8015ea913081096719727528c15ae3 Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 8 Sep 2025 21:17:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BE=9D=E8=B5=96=E5=A4=A7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20(#13908)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: status102 <102887808+status102@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci.yml | 159 +- .github/workflows/codeql-core.yml | 5 +- .github/workflows/release-nightly-ota.yml | 80 +- .github/workflows/res-update-game.yml | 4 +- .github/workflows/smoke-testing.yml | 69 +- .gitignore | 6 +- .nuke/build.schema.json | 3 +- 3rdparty/include/meojson/common/array.hpp | 223 ++- 3rdparty/include/meojson/common/object.hpp | 119 +- 3rdparty/include/meojson/common/utils.hpp | 282 +++- 3rdparty/include/meojson/common/value.hpp | 215 +-- 3rdparty/include/meojson/json.hpp | 1 - .../include/meojson/reflection/extensions.hpp | 656 ++++++++ .../meojson/reflection/jsonization.hpp | 279 ++- CMakeLists.txt | 193 +-- MAA.DotSettings | 15 - MAA.sln | 106 -- MAA.sln.DotSettings | 187 --- MaaDeps | 1 + build.cmd | 7 - build.ps1 | 69 - build.sh | 62 - cmake/config.cmake | 63 + cmake/modules/FindONNXRuntime.cmake | 41 + cmake/{ => modules}/adb-lite.cmake | 0 cmake/opencv.cmake | 54 - cmake/thrift-gen.cmake | 44 - cmake/utils.cmake | 82 +- cmake/version.cmake | 27 + docs/en-us/develop/development.md | 4 +- docs/en-us/develop/linux-tutorial.md | 7 +- docs/ja-jp/develop/development.md | 4 +- docs/ja-jp/develop/linux-tutorial.md | 7 +- docs/ja-jp/readme.md | 2 +- docs/ko-kr/develop/development.md | 3 +- docs/ko-kr/develop/linux-tutorial.md | 7 +- docs/zh-cn/develop/development.md | 16 +- docs/zh-cn/develop/linux-tutorial.md | 7 +- docs/zh-tw/develop/development.md | 3 +- docs/zh-tw/develop/linux-tutorial.md | 7 +- docs/zh-tw/readme.md | 2 +- include/interfaces/ThriftController.thrift | 71 - src/Cpp/MaaSample.slnf | 10 - src/Cpp/MaaSample.vcxproj | 283 ---- src/Cpp/MaaSample.vcxproj.filters | 14 - src/MaaCore/Assistant.cpp | 4 +- src/MaaCore/Common/AsstConf.h | 15 - .../Config/Miscellaneous/BattleDataConfig.cpp | 2 +- .../Config/Miscellaneous/ItemConfig.cpp | 6 +- .../Config/Miscellaneous/OcrConfig.cpp | 2 +- src/MaaCore/Config/Miscellaneous/OcrConfig.h | 2 +- src/MaaCore/Config/Miscellaneous/OcrPack.cpp | 19 +- .../Config/Miscellaneous/RecruitConfig.cpp | 2 +- .../Config/Miscellaneous/RecruitConfig.h | 14 +- .../Roguelike/RoguelikeCopilotConfig.cpp | 9 +- .../Roguelike/RoguelikeRecruitConfig.cpp | 3 +- src/MaaCore/Config/TaskData.cpp | 29 +- src/MaaCore/Config/TaskData.h | 10 +- .../Config/TaskData/TaskDataSymbolStream.cpp | 10 +- src/MaaCore/Controller/AdbController.cpp | 17 +- .../Controller/MaaThriftController.cpp | 592 ------- src/MaaCore/Controller/MaaThriftController.h | 115 -- src/MaaCore/Controller/Platform/Win32IO.cpp | 2 - src/MaaCore/Controller/Platform/Win32IO.h | 2 - .../Controller/PlayToolsController.cpp | 39 +- src/MaaCore/Controller/PlayToolsController.h | 8 +- src/MaaCore/Controller/adb-lite/client.cpp | 93 +- src/MaaCore/Controller/adb-lite/protocol.cpp | 22 +- src/MaaCore/Controller/adb-lite/protocol.hpp | 12 +- src/MaaCore/Directory.Build.props | 6 - src/MaaCore/Directory.Build.targets | 14 - src/MaaCore/MaaCore.vcxproj | 908 ---------- src/MaaCore/MaaCore.vcxproj.filters | 1495 ----------------- src/MaaCore/Task/AbstractTask.h | 2 +- src/MaaCore/Task/BattleHelper.cpp | 89 +- src/MaaCore/Task/BattleHelper.h | 5 - .../CombatRecordRecognitionTask.cpp | 15 +- .../Task/Fight/FightTimesTaskPlugin.cpp | 6 +- .../Task/Fight/MedicineCounterTaskPlugin.cpp | 10 +- .../Task/Fight/SideStoryReopenTask.cpp | 2 +- .../Task/Fight/StageDropsTaskPlugin.cpp | 6 +- .../Task/Fight/StageNavigationTask.cpp | 2 +- .../StageQueueMissionCompletedTaskPlugin.cpp | 8 +- .../Task/Infrast/InfrastAbstractTask.cpp | 28 +- .../Task/Infrast/InfrastOfficeTask.cpp | 2 +- src/MaaCore/Task/Infrast/InfrastPowerTask.cpp | 2 +- .../Task/Infrast/InfrastProcessingTask.cpp | 2 +- .../Task/Infrast/InfrastProductionTask.cpp | 19 +- .../Task/Infrast/InfrastReceptionTask.cpp | 7 +- .../Task/Infrast/InfrastTrainingTask.cpp | 2 +- src/MaaCore/Task/Interface/FightTask.cpp | 2 +- src/MaaCore/Task/Interface/InfrastTask.cpp | 2 +- .../Task/Miscellaneous/AccountSwitchTask.cpp | 2 +- .../Task/Miscellaneous/AutoRecruitTask.cpp | 36 +- .../Miscellaneous/BattleFormationTask.cpp | 37 +- .../Task/Miscellaneous/BattleProcessTask.cpp | 19 +- .../Task/Miscellaneous/CreditFightTask.cpp | 2 +- .../Task/Miscellaneous/CreditShoppingTask.cpp | 2 +- .../Miscellaneous/OperBoxRecognitionTask.cpp | 2 +- .../Miscellaneous/ParadoxRecognitionTask.cpp | 2 +- .../Miscellaneous/ScreenshotTaskPlugin.cpp | 6 +- .../UseSupportUnitTaskPlugin.cpp | 2 +- src/MaaCore/Task/ProcessTask.cpp | 10 +- .../Task/Roguelike/Map/RoguelikeMap.cpp | 10 +- .../Map/RoguelikeRoutingTaskPlugin.cpp | 12 +- .../Roguelike/RoguelikeBattleTaskPlugin.cpp | 27 +- .../RoguelikeFormationTaskPlugin.cpp | 26 +- .../Roguelike/RoguelikeInvestTaskPlugin.cpp | 2 +- .../Roguelike/RoguelikeRecruitTaskPlugin.cpp | 15 +- .../RoguelikeSettlementTaskPlugin.cpp | 7 +- .../Roguelike/RoguelikeShoppingTaskPlugin.cpp | 4 +- .../Sami/RoguelikeFoldartalUseTaskPlugin.cpp | 17 +- src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp | 30 +- .../Task/SSS/SSSDropRewardsTaskPlugin.cpp | 2 +- src/MaaCore/Utils/File.hpp | 4 +- src/MaaCore/Utils/Logger.hpp | 4 +- src/MaaCore/Utils/Platform/PlatformWin32.cpp | 2 - src/MaaCore/Utils/Ranges.hpp | 42 - src/MaaCore/Utils/StringMisc.hpp | 26 +- .../Vision/Battle/BattlefieldClassifier.cpp | 2 +- .../Vision/Battle/BattlefieldMatcher.cpp | 9 +- src/MaaCore/Vision/Config/MatcherConfig.cpp | 2 +- src/MaaCore/Vision/Config/OCRerConfig.cpp | 2 +- src/MaaCore/Vision/FeatureMatcher.cpp | 3 +- .../Infrast/InfrastFacilityImageAnalyzer.cpp | 2 +- .../Infrast/InfrastOperImageAnalyzer.cpp | 10 +- .../Miscellaneous/CreditShopImageAnalyzer.cpp | 8 +- .../Miscellaneous/DepotImageAnalyzer.cpp | 2 +- .../Miscellaneous/OperBoxImageAnalyzer.cpp | 6 +- .../Vision/Miscellaneous/PipelineAnalyzer.cpp | 2 +- .../Vision/Miscellaneous/PixelAnalyzer.cpp | 7 +- .../Miscellaneous/StageDropsImageAnalyzer.cpp | 6 +- src/MaaCore/Vision/MultiMatcher.cpp | 4 +- src/MaaCore/Vision/OCRer.cpp | 6 +- .../RoguelikeRecruitImageAnalyzer.cpp | 2 +- .../RoguelikeRecruitSupportAnalyzer.cpp | 2 +- src/MaaCore/Vision/VisionHelper.h | 12 +- src/MaaThriftController/CMakeLists.txt | 5 - src/MaaThriftController/Directory.Build.props | 6 - .../Directory.Build.targets | 14 - .../MaaThriftController.vcxproj | 305 ---- src/MaaWpfGui/Helper/DataHelper.cs | 7 +- src/MaaWpfGui/Helper/ItemListHelper.cs | 5 +- src/MaaWpfGui/MaaWpfGui.csproj | 2 +- src/MaaWpfGui/Main/AsstProxy.cs | 25 +- src/MaaWpfGui/Main/Bootstrapper.cs | 2 +- src/SyncRes/SyncRes.csproj | 2 +- .../DependencySetup_依赖库安装.bat | 0 tools/MaaBuilder.sln | 24 - tools/MaaBuilder/.editorconfig | 11 - tools/MaaBuilder/ActionConfiguration.cs | 23 - tools/MaaBuilder/Build.cs | 102 -- .../MaaBuilder/Builder/BuildConfiguration.cs | 15 - tools/MaaBuilder/Builder/BuildParameters.cs | 268 --- .../CI/Build.CI.GitHubActions.DevBuild.cs | 35 - .../CI/Build.CI.GitHubActions.ReleaseMaa.cs | 14 - .../Builder/Helper/Build.Helper.Bundler.cs | 126 -- .../Builder/Helper/Build.Helper.Github.cs | 102 -- .../Builder/Helper/Build.Helper.Logger.cs | 17 - .../Builder/Job/Build.Job.Bundle.cs | 52 - .../Builder/Job/Build.Job.Changelog.cs | 39 - .../MaaBuilder/Builder/Job/Build.Job.Clean.cs | 19 - .../Builder/Job/Build.Job.Compile.cs | 62 - .../Builder/Job/Build.Job.Publish.cs | 41 - .../Builder/Job/Build.Job.Version.cs | 76 - .../Builder/Job/Build.Job.Workflow.cs | 39 - tools/MaaBuilder/Directory.Build.props | 8 - tools/MaaBuilder/Directory.Build.targets | 8 - tools/MaaBuilder/MaaBuilder.csproj | 40 - .../MaaBuilder/MaaBuilder.csproj.DotSettings | 31 - tools/MaaBuilder/Models/Checksum.cs | 18 - tools/MaaBuilder/Models/Package.cs | 15 - .../MaaBuilder/Models/PackageConfiguration.cs | 16 - .../MaaBuilder/Properties/launchSettings.json | 7 - tools/MaaBuilder/README.md | 54 - tools/SmokeTesting/run_tests.ps1 | 10 +- tools/build_macos_universal.zsh | 2 +- .../maadeps-download.py | 7 +- tools/update_resource.sh | 15 - tools/update_version.sh | 5 - tools/version.sh | 12 - 182 files changed, 2290 insertions(+), 6997 deletions(-) create mode 100644 3rdparty/include/meojson/reflection/extensions.hpp delete mode 100644 MAA.DotSettings delete mode 100644 MAA.sln delete mode 100644 MAA.sln.DotSettings create mode 160000 MaaDeps delete mode 100644 build.cmd delete mode 100644 build.ps1 delete mode 100644 build.sh create mode 100644 cmake/config.cmake create mode 100644 cmake/modules/FindONNXRuntime.cmake rename cmake/{ => modules}/adb-lite.cmake (100%) delete mode 100644 cmake/opencv.cmake delete mode 100644 cmake/thrift-gen.cmake create mode 100644 cmake/version.cmake delete mode 100644 include/interfaces/ThriftController.thrift delete mode 100644 src/Cpp/MaaSample.slnf delete mode 100644 src/Cpp/MaaSample.vcxproj delete mode 100644 src/Cpp/MaaSample.vcxproj.filters delete mode 100644 src/MaaCore/Controller/MaaThriftController.cpp delete mode 100644 src/MaaCore/Controller/MaaThriftController.h delete mode 100644 src/MaaCore/Directory.Build.props delete mode 100644 src/MaaCore/Directory.Build.targets delete mode 100644 src/MaaCore/MaaCore.vcxproj delete mode 100644 src/MaaCore/MaaCore.vcxproj.filters delete mode 100644 src/MaaCore/Utils/Ranges.hpp delete mode 100644 src/MaaThriftController/CMakeLists.txt delete mode 100644 src/MaaThriftController/Directory.Build.props delete mode 100644 src/MaaThriftController/Directory.Build.targets delete mode 100644 src/MaaThriftController/MaaThriftController.vcxproj rename DependencySetup_依赖库安装.bat => tools/DependencySetup_依赖库安装.bat (100%) delete mode 100644 tools/MaaBuilder.sln delete mode 100644 tools/MaaBuilder/.editorconfig delete mode 100644 tools/MaaBuilder/ActionConfiguration.cs delete mode 100644 tools/MaaBuilder/Build.cs delete mode 100644 tools/MaaBuilder/Builder/BuildConfiguration.cs delete mode 100644 tools/MaaBuilder/Builder/BuildParameters.cs delete mode 100644 tools/MaaBuilder/Builder/CI/Build.CI.GitHubActions.DevBuild.cs delete mode 100644 tools/MaaBuilder/Builder/CI/Build.CI.GitHubActions.ReleaseMaa.cs delete mode 100644 tools/MaaBuilder/Builder/Helper/Build.Helper.Bundler.cs delete mode 100644 tools/MaaBuilder/Builder/Helper/Build.Helper.Github.cs delete mode 100644 tools/MaaBuilder/Builder/Helper/Build.Helper.Logger.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Bundle.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Changelog.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Clean.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Compile.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Publish.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Version.cs delete mode 100644 tools/MaaBuilder/Builder/Job/Build.Job.Workflow.cs delete mode 100644 tools/MaaBuilder/Directory.Build.props delete mode 100644 tools/MaaBuilder/Directory.Build.targets delete mode 100644 tools/MaaBuilder/MaaBuilder.csproj delete mode 100644 tools/MaaBuilder/MaaBuilder.csproj.DotSettings delete mode 100644 tools/MaaBuilder/Models/Checksum.cs delete mode 100644 tools/MaaBuilder/Models/Package.cs delete mode 100644 tools/MaaBuilder/Models/PackageConfiguration.cs delete mode 100644 tools/MaaBuilder/Properties/launchSettings.json delete mode 100644 tools/MaaBuilder/README.md rename maadeps-download.py => tools/maadeps-download.py (97%) delete mode 100644 tools/update_resource.sh delete mode 100644 tools/update_version.sh delete mode 100644 tools/version.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 75b96e9144..6682a09b89 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/devcontainers/features/sshd:1": {} }, - "postCreateCommand": "sudo sh -ce 'apt update && apt install g++-12 -y && echo export CC=gcc-12 CXX=g++-12 >> /etc/profile.d/set-compiler.sh'", + "postCreateCommand": "sudo sh -ce 'apt update && apt install g++-14 -y && echo export CC=gcc-14 CXX=g++-14 >> /etc/profile.d/set-compiler.sh'", "customizations": { "vscode": { "extensions": ["llvm-vs-code-extensions.vscode-clangd", "DavidAnson.vscode-markdownlint"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4127b02841..37535c51e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,9 @@ on: - "src/**" - "cmake/**" - "CMakeLists.txt" - - "MAA.sln" - ".github/workflows/ci.yml" - "!**/*.md" + - "tools/maadeps-download.py" pull_request: branches: - "dev" @@ -24,8 +24,8 @@ on: - "src/**" - "cmake/**" - "CMakeLists.txt" - - "MAA.sln" - "!**/*.md" + - "tools/maadeps-download.py" workflow_dispatch: concurrency: @@ -108,13 +108,8 @@ jobs: needs: meta strategy: matrix: - include: - - msbuild_target: x64 - lowercase_target: x64 - - msbuild_target: ARM64 - lowercase_target: arm64 - env: - MAABUILDER_TARGET_PLATFORM: ${{ matrix.msbuild_target }} + arch: [arm64, x64] + fail-fast: false runs-on: windows-latest steps: @@ -127,6 +122,35 @@ jobs: run: | git submodule update --init --depth 1 3rdparty/EmulatorExtras + - name: Cache MaaDeps + id: cache-maadeps + uses: actions/cache@v4 + with: + path: | + ./MaaDeps + key: ${{ runner.os }}-${{ matrix.arch }}-maadeps-${{ hashFiles('./tools/maadeps-download.py') }} + + - name: Bootstrap MaaDeps + if: steps.cache-maadeps.outputs.cache-hit != 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python3 tools/maadeps-download.py ${{ matrix.arch }}-windows + + - name: Config cmake + run: | + mkdir -p build + cmake -B build ${{ matrix.arch == 'arm64' && '-A ARM64' }} -DCMAKE_BUILD_TYPE=Release -DMAADEPS_TRIPLET='maa-${{ matrix.arch }}-windows' -DINSTALL_RESOURCE=ON -DINSTALL_PYTHON=ON -DMAA_VERSION='${{ needs.meta.outputs.tag }}' -DWITH_WPF_GUI=OFF + + - name: Build + run: | + cmake --build build --config Release + + - name: Install + run: | + mkdir -p install + cmake --install build --prefix install --config Release + - name: Cache .nuke/temp, ~/.nuget/packages id: cache-nuget uses: actions/cache@v4 @@ -134,38 +158,13 @@ jobs: path: | .nuke/temp ~/.nuget/packages - key: ${{ runner.os }}-${{ matrix.msbuild_target }}-${{ hashFiles('**/global.json', '**/*.csproj') }} + key: ${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('**/*.csproj') }} - name: Restore dependencies if: steps.cache-nuget.outputs.cache-hit != 'true' - run: dotnet restore + run: dotnet restore src/MaaWpfGui/MaaWpfGui.csproj - - name: Cache MaaDeps - id: cache-maadeps - uses: actions/cache@v4 - with: - path: | - ./MaaDeps - key: ${{ runner.os }}-${{ matrix.lowercase_target }}-maadeps-${{ hashFiles('./maadeps-download.py') }} - - - name: Bootstrap MaaDeps - if: steps.cache-maadeps.outputs.cache-hit != 'true' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - python3 maadeps-download.py ${{ matrix.lowercase_target }}-windows - - - name: Create fake event file - shell: bash - run: cp -v "$GITHUB_EVENT_PATH" ./event.json - - - name: Merge Event Data with Inputs - if: startsWith(github.ref, 'refs/tags/v') - shell: bash - run: | - cat "$GITHUB_EVENT_PATH" | jq '. + { "inputs": {"ReleaseSimulation": "${{ needs.meta.outputs.tag }}"} }' | tee ./event.json - - - name: Taggify Version + - name: Taggify Version for csproj run: | $csprojPath = "src/MaaWpfGui/MaaWpfGui.csproj" $csprojPath = Resolve-Path -Path $csprojPath @@ -182,29 +181,26 @@ jobs: $node.FileVersion = $match $node.AssemblyVersion = $match $csproj.Save($csprojPath) - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Build + - name: Publish WPF GUI + continue-on-error: true run: | - $env:GITHUB_WORKFLOW = 'dev-build-win' # pretend this is a dev-build-win workflow - $env:GITHUB_EVENT_PATH = "$pwd\\event.json" - $env:GITHUB_REF = "refs/heads/not_master" - $env:MAA_BUILDER_MAA_VERSION = '${{ needs.meta.outputs.tag }}' - ./build.cmd DevBuild - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + dotnet publish src/MaaWpfGui/MaaWpfGui.csproj -c Release -o install - - name: Cleanup checksum file - run: | - rm -vf ./artifacts/checksum.json + - name: Organize Install Files shell: bash + run: | + rm -rf install/*.pdb + rm -rf install/msvc-debug + rm -rf *.h + + cp tools/DependencySetup_依赖库安装.bat install - name: Upload MAA to Github uses: actions/upload-artifact@v4 with: - name: MAA-win-${{ matrix.lowercase_target }} - path: artifacts + name: MAA-win-${{ matrix.arch }} + path: install ubuntu: # Prevent duplicate runs on organization branches with PRs @@ -213,12 +209,11 @@ jobs: github.event.pull_request.base.repo.full_name needs: meta - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: arch: [aarch64, x86_64] - permissions: - actions: write + fail-fast: false steps: - name: Checkout code uses: actions/checkout@v4 @@ -234,36 +229,39 @@ jobs: if: ${{ matrix.arch != 'x86_64' }} run: | sudo apt-get update - sudo apt-get install g++-12-aarch64-linux-gnu g++-12-aarch64-linux-gnu + sudo apt-get install gcc-14-aarch64-linux-gnu g++-14-aarch64-linux-gnu # Caching not necessary on ubuntu runner - name: Bootstrap MaaDeps env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 maadeps-download.py ${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-linux + python3 tools/maadeps-download.py ${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-linux - - name: Build MAA + - name: Config cmake run: | mkdir -p build cmake -B build \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ + -DCMAKE_BUILD_TYPE=Release \ -DMAADEPS_TRIPLET='maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-linux' \ - -DINSTALL_THIRD_LIBS=ON \ -DINSTALL_RESOURCE=ON \ -DINSTALL_PYTHON=ON \ -DMAA_VERSION='${{ needs.meta.outputs.tag }}' - cmake --build build --parallel $(nproc --all) - - mkdir -p install - cmake --install build --prefix install env: - CC: ${{ matrix.arch == 'x86_64' && 'gcc-12' || 'aarch64-linux-gnu-gcc-12' }} - CXX: ${{ matrix.arch == 'x86_64' && 'g++-12' || 'aarch64-linux-gnu-g++-12' }} - CMAKE_COLOR_DIAGNOSTICS: ON + CC: ${{ matrix.arch == 'x86_64' && 'gcc-14' || 'aarch64-linux-gnu-gcc-14' }} + CXX: ${{ matrix.arch == 'x86_64' && 'g++-14' || 'aarch64-linux-gnu-g++-14' }} + + - name: Build + run: | + cmake --build build --config Release + env: CLICOLOR_FORCE: 1 - CXXFLAGS: | # workaround for gcc bugs - -Wno-error=restrict -Wno-error=array-bounds -Wno-error=stringop-overread -Wno-error=missing-field-initializers + + - name: Install + run: | + mkdir -p install + cmake --install build --prefix install --config Release + - name: Setup Cross Compile Toolchains for CLI uses: ./src/maa-cli/.github/actions/setup @@ -337,10 +335,11 @@ jobs: github.event.pull_request.base.repo.full_name needs: meta - runs-on: macos-14 + runs-on: macos-latest strategy: matrix: arch: [arm64, x86_64] + fail-fast: false steps: - name: Checkout code uses: actions/checkout@v4 @@ -355,18 +354,24 @@ jobs: - name: Bootstrap MaaDeps run: | [[ ${{ matrix.arch }} = "arm64" ]] && triplet="arm64-osx" || triplet="x64-osx" - python3 maadeps-download.py ${triplet} + python3 tools/maadeps-download.py ${triplet} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Configure MaaCore + - name: Config cmake run: | - cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES='${{ matrix.arch }}' -DMAA_VERSION='${{ needs.meta.outputs.tag }}' + cmake -B build -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_OSX_ARCHITECTURES='${{ matrix.arch }}' \ + -DMAA_VERSION='${{ needs.meta.outputs.tag }}' - - name: Build MaaCore + - name: Build run: | - cmake --build build - cmake --install build --prefix install + cmake --build build --config Release + + - name: Install + run: | + cmake --install build --prefix install --config Release - name: Upload MAA to Github uses: actions/upload-artifact@v4 @@ -381,7 +386,7 @@ jobs: github.event.pull_request.base.repo.full_name needs: [meta, macOS-Core] - runs-on: macos-14 + runs-on: macos-latest steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/codeql-core.yml b/.github/workflows/codeql-core.yml index f0fef18ac5..86ef075725 100644 --- a/.github/workflows/codeql-core.yml +++ b/.github/workflows/codeql-core.yml @@ -9,7 +9,6 @@ on: - "src/**" - "cmake/**" - "CMakeLists.txt" - - "MAA.sln" - ".github/workflows/codeql-core.yml" - "!**/*.md" - "!**/*.xaml" @@ -55,14 +54,14 @@ jobs: with: path: | ./MaaDeps - key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./maadeps-download.py') }} + key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./tools/maadeps-download.py') }} - name: Bootstrap MaaDeps if: steps.cache-maadeps.outputs.cache-hit != 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 maadeps-download.py x64-windows + python3 tools/maadeps-download.py x64-windows - name: Create fake event file shell: bash diff --git a/.github/workflows/release-nightly-ota.yml b/.github/workflows/release-nightly-ota.yml index 02147740f6..6f204116dd 100644 --- a/.github/workflows/release-nightly-ota.yml +++ b/.github/workflows/release-nightly-ota.yml @@ -30,10 +30,8 @@ jobs: runs-on: windows-latest strategy: matrix: - msbuild_target: [x64] + arch: [x64] fail-fast: false - env: - MAABUILDER_TARGET_PLATFORM: ${{ matrix.msbuild_target }} outputs: tag: ${{ steps.set_tag.outputs.tag }} pre_version: ${{ steps.set_tag.outputs.pre_version }} @@ -168,6 +166,35 @@ jobs: with: path: ./changelog_notag.md + - name: Cache MaaDeps + id: cache-maadeps + uses: actions/cache@v4 + with: + path: | + ./MaaDeps + key: ${{ runner.os }}-${{ matrix.arch }}-maadeps-${{ hashFiles('./tools/maadeps-download.py') }} + + - name: Bootstrap MaaDeps + if: steps.cache-maadeps.outputs.cache-hit != 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python3 tools/maadeps-download.py ${{ matrix.arch }}-windows + + - name: Config cmake + run: | + mkdir -p build + cmake -B build ${{ matrix.arch == 'arm64' && '-A ARM64' }} -DCMAKE_BUILD_TYPE=Release -DMAADEPS_TRIPLET='maa-${{ matrix.arch }}-windows' -DINSTALL_RESOURCE=ON -DINSTALL_PYTHON=ON -DMAA_VERSION='${{ needs.meta.outputs.tag }}' -DWITH_WPF_GUI=OFF + + - name: Build + run: | + cmake --build build --config Release + + - name: Install + run: | + mkdir -p install + cmake --install build --prefix install --config Release + - name: Cache .nuke/temp, ~/.nuget/packages id: cache-nuget uses: actions/cache@v4 @@ -175,28 +202,13 @@ jobs: path: | .nuke/temp ~/.nuget/packages - key: ${{ runner.os }}-${{ matrix.msbuild_target }}-${{ hashFiles('**/global.json', '**/*.csproj') }} + key: ${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('**/*.csproj') }} - name: Restore dependencies if: steps.cache-nuget.outputs.cache-hit != 'true' - run: dotnet restore + run: dotnet restore src/MaaWpfGui/MaaWpfGui.csproj - - name: Cache MaaDeps - id: cache-maadeps - uses: actions/cache@v4 - with: - path: | - ./MaaDeps - key: ${{ runner.os }}-${{ matrix.msbuild_target }}-maadeps-${{ hashFiles('./maadeps-download.py') }} - - - name: Bootstrap MaaDeps - if: steps.cache-maadeps.outputs.cache-hit != 'true' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - python3 maadeps-download.py ${{ matrix.msbuild_target }}-windows - - - name: Taggify Version + - name: Taggify Version for csproj run: | $csprojPath = "src/MaaWpfGui/MaaWpfGui.csproj" $csprojPath = Resolve-Path -Path $csprojPath @@ -206,8 +218,6 @@ jobs: } else { $match = "0.0.1" } - echo "Tag value: $tag" - echo "Version value: $match" [xml]$csproj = Get-Content -Path $csprojPath $node = $csproj.Project.PropertyGroup | where {$_.ApplicationVersion -ne $null} $node.InformationalVersion = $tag @@ -215,25 +225,25 @@ jobs: $node.FileVersion = $match $node.AssemblyVersion = $match $csproj.Save($csprojPath) - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run './build.cmd DevBuild' + - name: Publish WPF GUI + continue-on-error: true run: | - $env:GITHUB_WORKFLOW = 'dev-build-win' # pretend this is a dev-build-win workflow - $env:MAA_BUILDER_MAA_VERSION = "${{ steps.set_tag.outputs.tag }}" - echo "tag: " $env:MAA_BUILDER_MAA_VERSION + dotnet publish src/MaaWpfGui/MaaWpfGui.csproj -c Release -o install - ./build.cmd DevBuild - env: - Reason: "Build nightly version" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Organize Install Files + run: | + rm -rf install/*.pdb + rm -rf install/msvc-debug + rm -rf *.h + + cp tools/DependencySetup_依赖库安装.bat install - name: Upload MAA to Github uses: actions/upload-artifact@v4 with: - name: MAA-win-${{ matrix.msbuild_target }} - path: artifacts + name: MAA-win-${{ matrix.arch }} + path: install - name: Push tag to main repo id: push_main_tag diff --git a/.github/workflows/res-update-game.yml b/.github/workflows/res-update-game.yml index 35744ce48b..82487d8f8d 100644 --- a/.github/workflows/res-update-game.yml +++ b/.github/workflows/res-update-game.yml @@ -156,14 +156,14 @@ jobs: with: path: | ./MaaDeps - key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./maadeps-download.py') }} + key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./tools/maadeps-download.py') }} - name: Bootstrap MaaDeps if: steps.cache-resupd.outputs.cache-hit != 'true' && steps.cache-maadeps.outputs.cache-hit != 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 maadeps-download.py x64-windows + python3 tools/maadeps-download.py x64-windows - name: Add msbuild to PATH if: steps.cache-resupd.outputs.cache-hit != 'true' diff --git a/.github/workflows/smoke-testing.yml b/.github/workflows/smoke-testing.yml index 8196ecfa3b..b234a6fd1d 100644 --- a/.github/workflows/smoke-testing.yml +++ b/.github/workflows/smoke-testing.yml @@ -7,20 +7,22 @@ on: - "include/**" - "src/Cpp/**" - "src/MaaCore/**" - - "src/SyncRes/**" - - "MAA.sln" - "resource/**" - "!**/*.md" + - "cmake/**" + - "CMakeLists.txt" + - "tools/maadeps-download.py" pull_request: paths: - "3rdparty/include/**" - "include/**" - "src/Cpp/**" - "src/MaaCore/**" - - "src/SyncRes/**" - - "MAA.sln" - "resource/**" - "!**/*.md" + - "cmake/**" + - "CMakeLists.txt" + - "tools/maadeps-download.py" workflow_dispatch: concurrency: @@ -43,7 +45,7 @@ jobs: - name: Generate cache key id: cache_key run: | - Write-Output "key=Smoke-testing-${{ hashFiles('src/Cpp/**', 'src/MaaCore/**', 'src/SyncRes/**', '3rdparty/include/**', 'include/**', 'MAA.sln') }}" >> $env:GITHUB_OUTPUT + Write-Output "key=Smoke-testing-${{ hashFiles('src/Cpp/**', 'src/MaaCore/**', '3rdparty/include/**', 'include/**', 'cmake/**', 'CMakeLists.txt', 'tools/maadeps-download.py') }}" >> $env:GITHUB_OUTPUT - name: Restore cache smoke-testing id: cache-exe @@ -51,11 +53,11 @@ jobs: with: key: ${{ steps.cache_key.outputs.key }} path: | - ./x64/Debug/Sample.exe - ./x64/Debug/fastdeploy_ppocr.dll - ./x64/Debug/MaaCore.dll - ./x64/Debug/onnxruntime_maa.dll - ./x64/Debug/opencv_world4d_maa.dll + ./install/smoke_test.exe + ./install/fastdeploy_ppocr.dll + ./install/MaaCore.dll + ./install/onnxruntime_maa.dll + ./install/opencv_world4d_maa.dll - name: Fetch submodules if: steps.cache-exe.outputs.cache-hit != 'true' @@ -69,53 +71,48 @@ jobs: with: path: | ./MaaDeps - key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./maadeps-download.py') }} + key: ${{ runner.os }}-x64-maadeps-${{ hashFiles('./tools/maadeps-download.py') }} - name: Bootstrap MaaDeps if: steps.cache-exe.outputs.cache-hit != 'true' && steps.cache-maadeps.outputs.cache-hit != 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 maadeps-download.py x64-windows + python3 tools/maadeps-download.py x64-windows - - name: Add msbuild to PATH - if: steps.cache-exe.outputs.cache-hit != 'true' - uses: microsoft/setup-msbuild@v2 - with: - msbuild-architecture: x64 - - - name: Build MaaSample - if: steps.cache-exe.outputs.cache-hit != 'true' + - name: Config cmake run: | - MSBUILD src/Cpp/MaaSample.slnf -t:restore,build -p:Configuration="Debug" -p:Platform="x64" -m - - - name: Copy resource to build directory - if: steps.cache-exe.outputs.cache-hit == 'true' + mkdir -p build + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DMAADEPS_TRIPLET='maa-x64-windows' -DINSTALL_RESOURCE=ON -DBUILD_TEST=ON -DWITH_WPF_GUI=OFF + + - name: Build run: | - (robocopy "resource" "x64/Debug/resource" /E /XD "Arknights-Tile-Pos" /MT:4 > $null); - if ($LASTEXITCODE -lt 2) { $global:LASTEXITCODE = $null } - (robocopy "resource/Arknights-Tile-Pos" "x64/Debug/resource/Arknights-Tile-Pos" "overview.json" > $null); - if ($LASTEXITCODE -lt 2) { $global:LASTEXITCODE= $null } + cmake --build build --config Debug + + - name: Install + run: | + mkdir -p install + cmake --install build --prefix install --config Debug - name: Run tests run: | pwsh tools/SmokeTesting/run_tests.ps1 - - name: Save cache smoke-testing (only in dev) - if: steps.cache-exe.outputs.cache-hit != 'true' && github.ref == 'refs/heads/dev' + - name: Save cache smoke-testing + if: steps.cache-exe.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: key: ${{ steps.cache_key.outputs.key }} path: | - ./x64/Debug/Sample.exe - ./x64/Debug/fastdeploy_ppocr.dll - ./x64/Debug/MaaCore.dll - ./x64/Debug/onnxruntime_maa.dll - ./x64/Debug/opencv_world4d_maa.dll + ./install/smoke_test.exe + ./install/fastdeploy_ppocr.dll + ./install/MaaCore.dll + ./install/onnxruntime_maa.dll + ./install/opencv_world4d_maa.dll - name: Upload logs if: always() uses: actions/upload-artifact@v4 with: name: logs - path: ./x64/Debug/debug + path: ./install/debug diff --git a/.gitignore b/.gitignore index 1458e1bd3d..873c6f748b 100644 --- a/.gitignore +++ b/.gitignore @@ -471,6 +471,6 @@ Thumbs.db # MaaSupportExtension config /config/maa_pi_config.json -# MaaBuilder -.github/workflows/release-maa-win.yml -.github/workflows/dev-build-win.yml +# build & install +build +install \ No newline at end of file diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 6540f34e6c..b9b760c0ad 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -42,8 +42,7 @@ "UseRsVersion", "UseTagVersion", "WithCompileCoreRelease", - "WithCompileWpfRelease", - "WithSyncRes" + "WithCompileWpfRelease" ] }, "Verbosity": { diff --git a/3rdparty/include/meojson/common/array.hpp b/3rdparty/include/meojson/common/array.hpp index af6e2fbdc5..675e938332 100644 --- a/3rdparty/include/meojson/common/array.hpp +++ b/3rdparty/include/meojson/common/array.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "exception.hpp" @@ -40,50 +41,49 @@ public: // explicit basic_array(basic_value&& val); template < - typename collection_t, + typename jsonization_t, std::enable_if_t< - _utils::is_collection - && std::is_constructible_v>, + _utils::has_to_json_in_templ_spec::value + && !_utils::has_to_json_array_in_templ_spec::value, bool> = true> - basic_array(collection_t arr) - : _array_data(std::make_move_iterator(arr.begin()), std::make_move_iterator(arr.end())) - { - } - - template < - typename fixed_array_t, - std::enable_if_t<_utils::is_fixed_array, bool> = true> - basic_array(const fixed_array_t& arr) - : _array_data(arr.begin(), arr.end()) + basic_array(const jsonization_t& value) + : basic_array(ext::jsonization().to_json(value)) { } template < typename jsonization_t, - std::enable_if_t<_utils::has_to_json_in_member::value, bool> = true> + std::enable_if_t< + _utils::has_to_json_array_in_templ_spec::value, + bool> = true> basic_array(const jsonization_t& value) - : basic_array(value.to_json()) + : basic_array(ext::jsonization().to_json_array(value)) { } template < typename jsonization_t, - std::enable_if_t<_utils::has_to_json_in_templ_spec::value, bool> = true> - basic_array(const jsonization_t& value) - : basic_array(ext::jsonization().to_json(value)) + std::enable_if_t< + std::is_rvalue_reference_v + && _utils::has_move_to_json_in_templ_spec::value + && !_utils::has_move_to_json_array_in_templ_spec::value, + bool> = true> + basic_array(jsonization_t&& value) + : basic_array(ext::jsonization().move_to_json(std::move(value))) { } - template - basic_array(const std::tuple& tup) - { - foreach_tuple(tup, std::make_index_sequence>>()); - } - template - basic_array(std::pair pair) - : _array_data({ std::move(pair.first), std::move(pair.second) }) - { - } + //template < + // typename jsonization_t, + // std::enable_if_t< + // std::is_rvalue_reference_v + // && _utils::has_move_to_json_array_in_templ_spec::value, + // bool> = true> + //basic_array(jsonization_t&& value) + // : basic_array( + // ext::jsonization().move_to_json_array(std::move(value))) + //{ + //} ~basic_array() noexcept = default; @@ -120,6 +120,30 @@ public: template std::pair as_pair() const; + template < + typename value_t, + std::enable_if_t< + _utils::has_from_json_array_in_templ_spec::value, + bool> = true> + value_t as() const& + { + value_t res; + ext::jsonization().from_json_array(*this, res); + return res; + } + + template < + typename value_t, + std::enable_if_t< + _utils::has_move_from_json_array_in_templ_spec::value, + bool> = true> + value_t as() && + { + value_t res; + ext::jsonization().move_from_json_array(std::move(*this), res); + return res; + } + // Usage: get(key_1, key_2, ..., default_value); template auto get(key_then_default_value_t&&... keys_then_default_value) const; @@ -192,29 +216,19 @@ public: std::enable_if_t<_utils::is_fixed_array>, bool> = true> explicit operator fixed_array_t() const { - return as_fixed_array(); - } - - template - explicit operator std::tuple() const - { - return as_tuple(); - } - - template - explicit operator std::pair() const - { - return as_pair(); + return as>(); } template < typename jsonization_t, - std::enable_if_t<_utils::has_from_json_in_member::value, bool> = - true> - explicit operator jsonization_t() const + std::enable_if_t< + _utils::has_from_json_in_templ_spec::value + && !_utils::has_from_json_array_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() const& { jsonization_t dst {}; - if (!dst.from_json(*this)) { + if (!ext::jsonization().from_json(*this, dst)) { throw exception("Wrong JSON"); } return dst; @@ -223,12 +237,43 @@ public: template < typename jsonization_t, std::enable_if_t< - _utils::has_from_json_in_templ_spec::value, + _utils::has_from_json_array_in_templ_spec::value, bool> = true> - explicit operator jsonization_t() const + explicit operator jsonization_t() const& { jsonization_t dst {}; - if (!ext::jsonization().from_json(*this, dst)) { + if (!ext::jsonization().from_json_array(*this, dst)) { + throw exception("Wrong JSON"); + } + return dst; + } + + template < + typename jsonization_t, + std::enable_if_t< + _utils::has_move_from_json_in_templ_spec::value + && !_utils::has_move_from_json_array_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() && + { + jsonization_t dst {}; + if (!ext::jsonization().from_json(std::move(*this), dst)) { + throw exception("Wrong JSON"); + } + return dst; + } + + template < + typename jsonization_t, + std::enable_if_t< + _utils::has_move_from_json_array_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() && + { + jsonization_t dst {}; + if (!ext::jsonization().move_from_json_array( + std::move(*this), + dst)) { throw exception("Wrong JSON"); } return dst; @@ -244,17 +289,6 @@ private: template auto get_helper(const value_t& default_value, size_t pos) const; - template - tuple_t as_tuple_templ() const; - template - void set_tuple(tuple_t& tup) const; - - template - void foreach_tuple(const Tuple& t, std::index_sequence) - { - (_array_data.emplace_back(std::get(t)), ...); - } - string_t format(size_t indent, size_t indent_times) const; private: @@ -368,95 +402,32 @@ inline bool basic_array::all() const return true; } -namespace _as_collection_helper -{ -template -class has_emplace_back -{ - template - static auto test(int) -> decltype(std::declval().emplace_back(), std::true_type()); - - template - static std::false_type test(...); - -public: - static constexpr bool value = decltype(test(0))::value; -}; -} - template template typename collection_t> inline collection_t basic_array::as_collection() const { - collection_t result; - if constexpr (_as_collection_helper::has_emplace_back>::value) { - for (const auto& elem : _array_data) { - result.emplace_back(elem.template as()); - } - } - else { - for (const auto& elem : _array_data) { - result.emplace(elem.template as()); - } - } - return result; + return as>(); } template template typename fixed_array_t> inline fixed_array_t basic_array::as_fixed_array() const { - if (size() != Size) { - throw exception("Wrong array size"); - } - - fixed_array_t result; - for (size_t i = 0; i < Size; ++i) { - result.at(i) = _array_data.at(i).template as(); - } - return result; -} - -template -template -inline void basic_array::set_tuple(tuple_t& tup) const -{ - using elem_t = std::tuple_element_t; - - if constexpr (index > 0) { - set_tuple(tup); - } - - std::get(tup) = static_cast(at(index)); -} - -template -template -inline tuple_t basic_array::as_tuple_templ() const -{ - constexpr size_t tuple_size = std::tuple_size_v; - - if (size() != tuple_size) { - throw exception("Wrong array size"); - } - - tuple_t result; - set_tuple(result); - return result; + return as>(); } template template inline std::tuple basic_array::as_tuple() const { - return as_tuple_templ>(); + return as>(); } template template inline std::pair basic_array::as_pair() const { - return as_tuple_templ>(); + return as>(); } template diff --git a/3rdparty/include/meojson/common/object.hpp b/3rdparty/include/meojson/common/object.hpp index a2337ba031..161b4a5d0d 100644 --- a/3rdparty/include/meojson/common/object.hpp +++ b/3rdparty/include/meojson/common/object.hpp @@ -39,32 +39,50 @@ public: // explicit basic_object(basic_value&& val); template < - typename map_t, + typename jsonization_t, std::enable_if_t< - _utils::is_map - && std::is_constructible_v>, + _utils::has_to_json_in_templ_spec::value + && !_utils::has_to_json_object_in_templ_spec::value, bool> = true> - basic_object(map_t map) - : _object_data(std::make_move_iterator(map.begin()), std::make_move_iterator(map.end())) + basic_object(const jsonization_t& value) + : basic_object(ext::jsonization().to_json(value)) { } template < typename jsonization_t, - std::enable_if_t<_utils::has_to_json_in_member::value, bool> = true> + std::enable_if_t< + _utils::has_to_json_object_in_templ_spec::value, + bool> = true> basic_object(const jsonization_t& value) - : basic_object(value.to_json()) + : basic_object(ext::jsonization().to_json_object(value)) { } template < typename jsonization_t, - std::enable_if_t<_utils::has_to_json_in_templ_spec::value, bool> = true> - basic_object(const jsonization_t& value) - : basic_object(ext::jsonization().to_json(value)) + std::enable_if_t< + std::is_rvalue_reference_v + && _utils::has_move_to_json_in_templ_spec::value + && !_utils::has_move_to_json_object_in_templ_spec::value, + bool> = true> + basic_object(jsonization_t&& value) + : basic_object(ext::jsonization().move_to_json(std::move(value))) { } + //template < + // typename jsonization_t, + // std::enable_if_t< + // std::is_rvalue_reference_v + // && _utils::has_move_to_json_object_in_templ_spec::value, + // bool> = true> + //basic_object(jsonization_t&& value) + // : basic_object( + // ext::jsonization().move_to_json_object(std::move(value))) + //{ + //} + ~basic_object() = default; bool empty() const noexcept { return _object_data.empty(); } @@ -91,6 +109,30 @@ public: template typename map_t = std::map> map_t as_map() const; + template < + typename value_t, + std::enable_if_t< + _utils::has_from_json_object_in_templ_spec::value, + bool> = true> + value_t as() const& + { + value_t res; + ext::jsonization().from_json_object(*this, res); + return res; + } + + template < + typename value_t, + std::enable_if_t< + _utils::has_move_from_json_object_in_templ_spec::value, + bool> = true> + value_t as() && + { + value_t res; + ext::jsonization().move_from_json_object(std::move(*this), res); + return res; + } + // Usage: get(key_1, key_2, ..., default_value); template auto get(key_then_default_value_t&&... keys_then_default_value) const; @@ -151,12 +193,14 @@ public: template < typename jsonization_t, - std::enable_if_t<_utils::has_from_json_in_member::value, bool> = - true> - explicit operator jsonization_t() const + std::enable_if_t< + _utils::has_from_json_in_templ_spec::value + && !_utils::has_from_json_object_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() const& { jsonization_t dst {}; - if (!dst.from_json(*this)) { + if (!ext::jsonization().from_json(*this, dst)) { throw exception("Wrong JSON"); } return dst; @@ -165,12 +209,43 @@ public: template < typename jsonization_t, std::enable_if_t< - _utils::has_from_json_in_templ_spec::value, + _utils::has_from_json_object_in_templ_spec::value, bool> = true> - explicit operator jsonization_t() const + explicit operator jsonization_t() const& { jsonization_t dst {}; - if (!ext::jsonization().from_json(*this, dst)) { + if (!ext::jsonization().from_json_object(*this, dst)) { + throw exception("Wrong JSON"); + } + return dst; + } + + template < + typename jsonization_t, + std::enable_if_t< + _utils::has_move_from_json_in_templ_spec::value + && !_utils::has_move_from_json_object_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() && + { + jsonization_t dst {}; + if (!ext::jsonization().from_json(std::move(*this), dst)) { + throw exception("Wrong JSON"); + } + return dst; + } + + template < + typename jsonization_t, + std::enable_if_t< + _utils::has_move_from_json_object_in_templ_spec::value, + bool> = true> + explicit operator jsonization_t() && + { + jsonization_t dst {}; + if (!ext::jsonization().move_from_json_object( + std::move(*this), + dst)) { throw exception("Wrong JSON"); } return dst; @@ -195,8 +270,8 @@ private: template inline basic_object::basic_object(std::initializer_list init_list) : _object_data( - std::make_move_iterator(init_list.begin()), - std::make_move_iterator(init_list.end())) + std::make_move_iterator(init_list.begin()), + std::make_move_iterator(init_list.end())) { } @@ -309,11 +384,7 @@ template template typename map_t> inline map_t basic_object::as_map() const { - map_t result; - for (const auto& [key, val] : _object_data) { - result.emplace(key, val.template as()); - } - return result; + return as>(); } template diff --git a/3rdparty/include/meojson/common/utils.hpp b/3rdparty/include/meojson/common/utils.hpp index 12281b3dea..a416853e38 100644 --- a/3rdparty/include/meojson/common/utils.hpp +++ b/3rdparty/include/meojson/common/utils.hpp @@ -32,7 +32,7 @@ using wobject = basic_object; namespace json::ext { -template +template class jsonization { public: @@ -101,11 +101,19 @@ constexpr bool is_pair = false; template constexpr bool is_pair> = true; +template +constexpr bool is_tuple_like = false; +template