mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 23:12:40 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf8981f6d6 |
@@ -1,19 +0,0 @@
|
||||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
|
||||
#
|
||||
version: 2
|
||||
jobs:
|
||||
test:
|
||||
docker:
|
||||
- image: circleci/node:12.13
|
||||
steps:
|
||||
- checkout
|
||||
- run: sudo npm install -g gulp
|
||||
- run: npm install
|
||||
- run: gulp build-debug-infos
|
||||
- run: npm test
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
test:
|
||||
jobs:
|
||||
- test
|
||||
@@ -1,12 +0,0 @@
|
||||
# This file is for unifying the coding style for different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
@@ -1,3 +0,0 @@
|
||||
*.jsb.ts
|
||||
**/*.ems.ts
|
||||
cocos/webgpu/**/*
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
root: true
|
||||
|
||||
parser: '@typescript-eslint/parser'
|
||||
|
||||
parserOptions:
|
||||
project:
|
||||
- ./tsconfig.json
|
||||
|
||||
extends:
|
||||
- eslint:recommended
|
||||
- airbnb-base
|
||||
- plugin:@typescript-eslint/recommended
|
||||
- plugin:@typescript-eslint/recommended-requiring-type-checking
|
||||
|
||||
plugins: ["@typescript-eslint"]
|
||||
|
||||
settings:
|
||||
import/resolver:
|
||||
node:
|
||||
extensions:
|
||||
- .js
|
||||
- .jsx
|
||||
- .ts
|
||||
- .tsx
|
||||
- .d.ts
|
||||
|
||||
env:
|
||||
browser: true
|
||||
node: true
|
||||
es6: true
|
||||
jest: true
|
||||
|
||||
globals:
|
||||
cc: false
|
||||
wx: false
|
||||
Editor: false
|
||||
_Scene: false
|
||||
_ccsg: false
|
||||
|
||||
rules:
|
||||
|
||||
# https://eslint.org/docs/rules/
|
||||
# https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
|
||||
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
# BEFORE ADDING ANY RULES
|
||||
# PLEASE EXPLAIN THE REASON IN THE COMMENT.
|
||||
|
||||
##### RECOMMENDED RULE OVERRIDES #####
|
||||
|
||||
camelcase: off # underscores may come in handy in some cases
|
||||
eqeqeq: warn # important check missing from recommended
|
||||
keyword-spacing: warn # we require this explicitly
|
||||
no-multi-spaces: off # useful for manually align some expression across lines
|
||||
prefer-rest-params: off # we need ES5 to be fast too
|
||||
prefer-spread: off # we need ES5 to be fast too
|
||||
space-before-function-paren: [warn, always] # we require this explicitly
|
||||
radix: off # we sometimes do not need to pass a second parameter
|
||||
# allow underscores, we still widely use pre-dangle naming in our naming convention
|
||||
# e.g. private properties, private functions, module scope shared variables etc.
|
||||
no-underscore-dangle: off
|
||||
quotes: [warn, single, { allowTemplateLiterals: true }] # force single, but allow template literal
|
||||
no-else-return: off # else-return is a common pattern which clearly expresses the control flow
|
||||
no-unused-expressions: off # taken over by '@typescript-eslint/no-unused-expressions'
|
||||
no-empty-function: off # taken over by '@typescript-eslint/no-empty-function'
|
||||
|
||||
##### AIRBNB-SPECIFIC RULE OVERRIDES #####
|
||||
|
||||
class-methods-use-this: off # so empty functions could work
|
||||
guard-for-in: off # for-in is a efficient choice for plain objects
|
||||
import/export: off # so export declare namespace could work
|
||||
import/extensions: off # typescript doesn't support this
|
||||
import/no-unresolved: off # TODO: fix internal modules
|
||||
import/prefer-default-export: off # prefer named exports
|
||||
indent: [error, 4, {
|
||||
SwitchCase: 0,
|
||||
ignoredNodes: [ # https://stackoverflow.com/a/72897089
|
||||
"FunctionExpression > .params[decorators.length > 0]",
|
||||
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
|
||||
"ClassBody.body > PropertyDefinition[decorators.length > 0] > .key",
|
||||
]
|
||||
}]
|
||||
|
||||
lines-between-class-members: off # be more lenient on member declarations
|
||||
max-classes-per-file: off # helper classes are common
|
||||
max-len: [warn, 150] # more lenient on max length per line
|
||||
no-console: error # prefer the uniform logging methods
|
||||
no-plusplus: off # allow increment/decrement operators
|
||||
no-continue: off # allow unlabeled continues
|
||||
no-mixed-operators: off # this is just cumbersome
|
||||
no-multi-assign: off # it is handy sometimes
|
||||
no-nested-ternary: off # it is handy sometimes
|
||||
no-param-reassign: off # the output object is passed as parameters all the time
|
||||
no-restricted-syntax: off # for-in is a efficient choice for plain objects
|
||||
no-return-assign: off # it is handy sometimes
|
||||
no-shadow: off # TODO: this throws false-positives?
|
||||
no-sequences: off # it is handy sometimes
|
||||
no-bitwise: off # we use this extensively
|
||||
no-use-before-define: off # just too much work
|
||||
no-useless-constructor: off # gives false-positives for empty constructor with parameter properties
|
||||
object-curly-newline: off # we want manual control over this
|
||||
one-var-declaration-per-line: off # auto-fix has order issues with `one-var`
|
||||
prefer-destructuring: off # auto-fix is not smart enough to merge different instances
|
||||
linebreak-style: off # we don't enforce this on everyone's dev environment for now
|
||||
spaced-comment: off # for license declarations
|
||||
default-case-last: off # Place default case clause to first make it more clear that this switch statement has handled all cases
|
||||
|
||||
##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####
|
||||
|
||||
'@typescript-eslint/ban-ts-comment': [error, {
|
||||
'ts-expect-error': true,
|
||||
'ts-ignore': true,
|
||||
'ts-nocheck': true,
|
||||
'ts-check': false,
|
||||
}]
|
||||
'@typescript-eslint/no-unused-expressions': warn
|
||||
|
||||
# TODO: this is just too much work
|
||||
'@typescript-eslint/explicit-module-boundary-types': off
|
||||
|
||||
# NOTE: We don't want to rely on TS automatic type inference
|
||||
'@typescript-eslint/no-inferrable-types': off
|
||||
|
||||
# TODO: sadly we still rely heavily on legacyCC
|
||||
'@typescript-eslint/no-unsafe-assignment': off
|
||||
'@typescript-eslint/no-unsafe-call': off
|
||||
'@typescript-eslint/no-unsafe-member-access': off
|
||||
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': off
|
||||
|
||||
'@typescript-eslint/unbound-method': off # we exploit prototype methods sometimes to acheive better performace
|
||||
'@typescript-eslint/no-explicit-any': off # still relevant for some heavily templated usages
|
||||
|
||||
'@typescript-eslint/no-empty-function': off # may become useful in some parent classes
|
||||
|
||||
'@typescript-eslint/no-unused-vars': off # may become useful in some parent classes
|
||||
'@typescript-eslint/no-non-null-assertion': off # sometimes we just know better than the compiler
|
||||
'@typescript-eslint/no-namespace': [warn, { # we need to declare static properties
|
||||
allowDeclarations: true,
|
||||
allowDefinitionFiles: true
|
||||
}]
|
||||
'@typescript-eslint/restrict-template-expressions': [warn, { # concatenations of different types are common, e.g. hash calculations
|
||||
allowNumber: true,
|
||||
allowBoolean: true
|
||||
}]
|
||||
|
||||
'@typescript-eslint/type-annotation-spacing': warn
|
||||
|
||||
# We choose to use style `... as foo` since it's more common.
|
||||
# In the other hand, angle bracket style can be ambiguous with j/tsx syntax.
|
||||
# For example, https://babeljs.io/docs/en/babel-plugin-transform-typescript#istsx
|
||||
# forbids angle bracket style if `isTSX` is enabled.
|
||||
'@typescript-eslint/consistent-type-assertions': [error, {
|
||||
assertionStyle: 'as'
|
||||
}]
|
||||
|
||||
# Prefer the interface style.
|
||||
'@typescript-eslint/consistent-type-definitions': [error, interface]
|
||||
'@typescript-eslint/explicit-function-return-type': [error, {
|
||||
allowIIFEs: true, # IIFEs are widely used, writing their signature twice is painful
|
||||
}]
|
||||
|
||||
'@typescript-eslint/no-this-alias': off
|
||||
@@ -1,77 +0,0 @@
|
||||
name: Bug report
|
||||
description: Create a report to help us improve
|
||||
labels: ["Needs Triage","Bug"]
|
||||
body:
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Please write a descriptive issue title above.
|
||||
|
||||
**Before You Start:**
|
||||
- Search [open](https://github.com/cocos/cocos4/issues) and [closed](https://github.com/cocos/cocos4/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported.
|
||||
- Verify that your issue is reproducible in the latest stable version of [Cocos Creator](https://www.cocos.com/creator).
|
||||
|
||||
**For usage questions, please use the following resources:**
|
||||
- Read our [Docs](https://docs.cocos.com/creator/manual/en/)
|
||||
- Check our [API](https://docs.cocos.com/creator/api/en/#/)
|
||||
- Watch our [Video Tutorials](https://www.youtube.com/cocosengine)
|
||||
- Ask on our [forum](https://discuss.cocos2d-x.org/)
|
||||
|
||||
**Thanks for taking the time to fill out this form!**
|
||||
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Cocos Creator version
|
||||
description: >
|
||||
Specify the official build version of engine.
|
||||
If you use a custom build, please test if your issue is reproducible in the official builds too.
|
||||
placeholder: 3.4.2, 3.5.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: System information
|
||||
description: |
|
||||
Specify the OS version, and when relevant hardware information.
|
||||
For graphics-related issues, specify the GPU model, driver version, and the rendering backend (GLES2, GLES3, Vulkan).
|
||||
For issues regarding to smart phones, specify the OS and phone model
|
||||
placeholder: Windows 10 Editor, iOS 15.4 build on iPhone 13
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Issue description
|
||||
description: |
|
||||
Describe your issue briefly. What doesn't work, and how do you expect it to work instead?
|
||||
You can include images or videos with drag and drop, and format code blocks or logs with <code>```</code> tags.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Relevant error log output
|
||||
description: |
|
||||
Error output and stack trace.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: |
|
||||
List of steps or sample code that reproduces the issue. If you include a minimal reproduction project below, you can detail how to use it here. Clear and concise reproduction instructions are important for us to be able to triage your issue in a timely manner.
|
||||
|
||||
Note that you can use [Markdown](https://guides.github.com/features/mastering-markdown/) to format lists and code.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Minimal reproduction project
|
||||
description: |
|
||||
A small Cocos Creator project which reproduces the issue. Highly recommended to speed up troubleshooting.
|
||||
Drag and drop a ZIP archive to upload it.
|
||||
@@ -1,11 +0,0 @@
|
||||
blank_issues_enabled: true
|
||||
|
||||
contact_links:
|
||||
|
||||
- name: Documentation issue
|
||||
url: https://github.com/cocos/cocos-docs
|
||||
about: Please report issues with documentation on the documentation repository, not here
|
||||
|
||||
- name: General discussions and questions
|
||||
url: https://discuss.cocos2d-x.org/
|
||||
about: Please post on the forum if you want to ask questions, make suggestions and feature requests. Or you can visit the Chinese forum at https://forum.cocos.org
|
||||
@@ -1,60 +0,0 @@
|
||||
name: Feature request
|
||||
description: Suggest an idea for Cocos
|
||||
labels: ["Needs Triage","Feature Request"]
|
||||
body:
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Please write a descriptive proposal title above.
|
||||
- Search [open](https://github.com/cocos/cocos4/issues) and [closed](https://github.com/cocos/cocos4/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been suggested.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Use Case
|
||||
description: Explain your use case, context, and rationale behind this feature request. More importantly, what is the project you are trying to build that led to the need for this feature? This is important to know the **context** in which the feature is being proposed.
|
||||
placeholder: Example - "I am working on a MOBA game that ... With heavy use of navigation..."
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Problem Description
|
||||
description: Please add a clear and concise description of the problem or limitation you are having in your project.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Proposed Solution
|
||||
description: Describe the desired workflow or API set to satisfy the need in a clear and concise manner.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: How it works
|
||||
description: Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams. If the API needs to be changed, please describe what does the proposed API look like and provide code samples. Note that you can use Markdown to format your code blocks.
|
||||
placeholder: Example - "When the user presses ..., select all nodes that have the group..."
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Alternatives Considered
|
||||
description: A clear and concise description of any alternative solutions or features you've considered.
|
||||
placeholder: Example - "It would be possible to do it with ... But ..."
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: Add any other context about the problem here.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this form!
|
||||
@@ -1,37 +0,0 @@
|
||||
Re: #
|
||||
|
||||
### Changelog
|
||||
|
||||
*
|
||||
|
||||
-------
|
||||
|
||||
### Continuous Integration
|
||||
|
||||
This pull request:
|
||||
|
||||
* [ ] needs automatic test cases check.
|
||||
> Manual trigger with `@cocos-robot run test cases` afterward.
|
||||
* [ ] does not change any runtime related code or build configuration
|
||||
> If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.
|
||||
|
||||
-------
|
||||
|
||||
### Compatibility Check
|
||||
|
||||
This pull request:
|
||||
|
||||
* [ ] changes public API, and have ensured backward compatibility with [deprecated features](https://github.com/cocos/cocos-engine/blob/v3.5.0/docs/contribution/deprecated-features.md).
|
||||
* [ ] affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
|
||||
* [ ] affects file structure of the build package or build configuration which requires user project upgrade.
|
||||
* [ ] **introduces breaking changes**, please list all changes, affected features and the scope of violation.
|
||||
|
||||
<!-- Note: Makes sure these boxes are checked before submitting your PR - thank you!
|
||||
- [ ] Your pull request title is using English, it's precise and appropriate.
|
||||
- [ ] If your pull request has gone "stale", you should **rebase** your work on top of the latest version of the upstream branch.
|
||||
- [ ] If your commit history is full of small, unimportant commits (such as "fix pep8" or "update tests"), **squash** your commits down to a few, or one, discreet changesets before submitting a pull request.
|
||||
- [ ] Document new code with comments in source code based on API docs
|
||||
- [ ] Make sure any runtime log information in `log` , `error` or `new Error('')` has been moved into `EngineErrorMap.md` with an ID, and use `logID(id)` or `new Error(getError(id))` instead.
|
||||
- To official teams:
|
||||
- [ ] Check that your PR is following our [guides](https://github.com/cocos/3d-tasks/blob/master/workflows/readme.md)
|
||||
-->
|
||||
@@ -1,34 +0,0 @@
|
||||
name: automation-labels
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
automate-labels:
|
||||
concurrency:
|
||||
group: ${{ github.head_ref }}
|
||||
cancel-in-progress: true
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check organization
|
||||
id: get_check_code
|
||||
env:
|
||||
user: ${{ github.event.pull_request.user.login }}
|
||||
run: |
|
||||
http_code=`curl -s --head -I -H "Authorization: token ${{ secrets.LABEl_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/orgs/cocos/members/$user | awk '/HTTP/{print $2}'`
|
||||
echo "::set-output name=http_code::${http_code}"
|
||||
- name: Add contribution label
|
||||
if: |
|
||||
steps.get_check_code.outputs.http_code == 404
|
||||
uses: OperationsYU/labeler@master
|
||||
with:
|
||||
add-labels: "contribution"
|
||||
|
||||
- name: assignment
|
||||
if: |
|
||||
steps.get_check_code.outputs.http_code == 404
|
||||
uses: OperationsYU/auto-assignment@v1
|
||||
with:
|
||||
token: ${{ secrets.LABEl_TOKEN }}
|
||||
users: '["minggo"]'
|
||||
@@ -1,14 +0,0 @@
|
||||
// https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md
|
||||
{
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "<Web> build",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^Circular dependency: (.*)$",
|
||||
"message": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
const { join, normalize } = require('path');
|
||||
const { ensureDir, emptyDir } = require('fs-extra');
|
||||
|
||||
const { buildEngine, StatsQuery } = require('@cocos/ccbuild');
|
||||
|
||||
const args = process.argv;
|
||||
|
||||
if (args.length < 3) {
|
||||
console.error(`==> exclude modules were not passed in!`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const spineVersion = args[2];
|
||||
|
||||
function excludeFeatures(features, exclude) {
|
||||
return features.filter((feature) => !exclude.includes(feature));
|
||||
}
|
||||
|
||||
(async function exec () {
|
||||
const engineDir = normalize(join(__dirname, '..', '..'));
|
||||
const engineOutput = join(engineDir, 'bin', 'native-preview');
|
||||
|
||||
console.log(`==> engineDir: ${engineDir}`);
|
||||
console.log(`==> engineOutput: ${engineOutput}`);
|
||||
|
||||
await ensureDir(engineOutput);
|
||||
await emptyDir(engineOutput);
|
||||
|
||||
const buildMode = 'PREVIEW';
|
||||
const buildPlatform = 'NATIVE';
|
||||
|
||||
const statsQuery = await StatsQuery.create(engineDir);
|
||||
|
||||
allFeatures = excludeFeatures(statsQuery.getFeatures(), ['gfx-webgpu', 'vendor-google']);
|
||||
allFeatures = allFeatures.filter((feature) => !feature.startsWith('spine-'))
|
||||
|
||||
allFeatures.push(spineVersion);
|
||||
|
||||
console.log(`-----------------------------------------------`);
|
||||
console.log(`==> features: ${allFeatures.join(', \n')}`);
|
||||
console.log(`-----------------------------------------------`);
|
||||
|
||||
const buildOptions = {
|
||||
engine: engineDir,
|
||||
out: engineOutput,
|
||||
moduleFormat: 'system',
|
||||
compress: false,
|
||||
targets: 'chrome 80',
|
||||
split: true,
|
||||
nativeCodeBundleMode: 'wasm',
|
||||
platform: buildPlatform,
|
||||
mode: buildMode,
|
||||
features: allFeatures,
|
||||
flags: {
|
||||
DEBUG: true,
|
||||
SERVER_MODE: false,
|
||||
},
|
||||
};
|
||||
await buildEngine(buildOptions);
|
||||
|
||||
}());
|
||||
@@ -1,144 +0,0 @@
|
||||
name: Build wasm/asmjs libraryies
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: "Select a library"
|
||||
required: true
|
||||
default: "Spine"
|
||||
type: choice
|
||||
options:
|
||||
- Spine
|
||||
|
||||
jobs:
|
||||
build_spine_wasm_asmjs:
|
||||
name: "Build spine wasm/asmjs libs"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 3.1.41
|
||||
|
||||
- name: Verify
|
||||
run: |
|
||||
which emcc
|
||||
emcc -v
|
||||
|
||||
- name: Install ninja
|
||||
run: |
|
||||
if ! command -v ninja &> /dev/null; then
|
||||
echo "Ninja not found, installing..."
|
||||
# sudo apt update
|
||||
sudo apt install ninja-build
|
||||
else
|
||||
echo "Ninja is already installed."
|
||||
fi
|
||||
which ninja
|
||||
|
||||
- name: Apply emscripten patches
|
||||
run: |
|
||||
echo "--------------------------------- Save bind.cpp ---------------------------------"
|
||||
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
|
||||
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
|
||||
cp -f .github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
|
||||
echo "--------------------------------- Apply patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
|
||||
- name: Build Spine 3.8 WASM
|
||||
run: |
|
||||
cd native/cocos/editor-support/spine-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 3.8 ASMJS
|
||||
run: |
|
||||
cd native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 3.8 files to external directory
|
||||
run: |
|
||||
DIST_PATH="dist/3.8"
|
||||
rm -rf $DIST_PATH
|
||||
mkdir -p $DIST_PATH
|
||||
cp native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH
|
||||
cp native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
mkdir -p native/external/emscripten/spine/3.8
|
||||
ls -l native/external/emscripten/spine/3.8
|
||||
cp -f ./$DIST_PATH/* native/external/emscripten/spine/3.8
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l native/external/emscripten/spine/3.8
|
||||
echo "-----------------------------------------------"
|
||||
cd native/external
|
||||
git status
|
||||
|
||||
- name: Build Spine 4.2 WASM
|
||||
run: |
|
||||
cd native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
rm -rf build-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 4.2 ASMJS
|
||||
run: |
|
||||
cd native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
rm -rf build-asmjs
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 4.2 files to external directory
|
||||
run: |
|
||||
DIST_PATH="dist/4.2"
|
||||
rm -rf $DIST_PATH
|
||||
mkdir -p $DIST_PATH
|
||||
cp native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH
|
||||
cp native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
mkdir -p native/external/emscripten/spine/4.2/
|
||||
ls -l native/external/emscripten/spine/4.2/
|
||||
cp -f ./$DIST_PATH/* native/external/emscripten/spine/4.2/
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l native/external/emscripten/spine/4.2/
|
||||
echo "-----------------------------------------------"
|
||||
cd native/external
|
||||
git status
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: spine-emscripten
|
||||
path: dist
|
||||
|
||||
- name: Restore patches
|
||||
run: |
|
||||
echo "-------------------------- Restore patches ---------------------------------"
|
||||
rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
echo "-------------------------- Restore patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
@@ -1,205 +0,0 @@
|
||||
// Copyright 2012 The Emscripten Authors. All rights reserved.
|
||||
// Emscripten is available under two separate licenses, the MIT license and the
|
||||
// University of Illinois/NCSA Open Source License. Both these licenses can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
#ifdef USE_CXA_DEMANGLE
|
||||
#include <../lib/libcxxabi/include/cxxabi.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/wire.h>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
using namespace emscripten;
|
||||
using namespace internal;
|
||||
|
||||
static char* pointerToHexString(const void* ptr) {
|
||||
static const char hexDigits[] = "0123456789abcdef";
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
|
||||
char str[20] = "0x"; // Includes the "0x" prefix
|
||||
int index = 2;
|
||||
bool leadingZero = true; // Used to skip leading zeros
|
||||
|
||||
// Convert the address to a hexadecimal string
|
||||
for (int i = (sizeof(address) * 2) - 1; i >= 0; --i) {
|
||||
char hexChar = hexDigits[(address >> (i * 4)) & 0xF];
|
||||
if (hexChar != '0' || !leadingZero || i == 0) { // Ensures at least one zero in the final character
|
||||
str[index++] = hexChar;
|
||||
leadingZero = false;
|
||||
}
|
||||
}
|
||||
str[index] = '\0';
|
||||
|
||||
return strdup(str);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
const char* EMSCRIPTEN_KEEPALIVE __getTypeName(const std::type_info* ti) {
|
||||
if (has_unbound_type_names) {
|
||||
#ifdef USE_CXA_DEMANGLE
|
||||
int stat;
|
||||
char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
|
||||
if (stat == 0 && demangled) {
|
||||
return demangled;
|
||||
}
|
||||
|
||||
switch (stat) {
|
||||
case -1:
|
||||
return strdup("<allocation failure>");
|
||||
case -2:
|
||||
return strdup("<invalid C++ symbol>");
|
||||
case -3:
|
||||
return strdup("<invalid argument>");
|
||||
default:
|
||||
return strdup("<unknown error>");
|
||||
}
|
||||
#else
|
||||
return strdup(ti->name());
|
||||
#endif
|
||||
} else {
|
||||
//cjh char str[80];
|
||||
// sprintf(str, "%p", reinterpret_cast<const void*>(ti));
|
||||
// return strdup(str);
|
||||
return pointerToHexString(reinterpret_cast<const void*>(ti));
|
||||
}
|
||||
}
|
||||
|
||||
static InitFunc* init_funcs = nullptr;
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings() {
|
||||
for (auto* f = init_funcs; f; f = f->next) {
|
||||
f->init_func();
|
||||
}
|
||||
}
|
||||
|
||||
void _embind_register_bindings(InitFunc* f) {
|
||||
f->next = init_funcs;
|
||||
init_funcs = f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T> static void register_integer(const char* name) {
|
||||
using namespace internal;
|
||||
_embind_register_integer(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
|
||||
std::numeric_limits<T>::max());
|
||||
}
|
||||
|
||||
template <typename T> static void register_bigint(const char* name) {
|
||||
using namespace internal;
|
||||
_embind_register_bigint(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
|
||||
std::numeric_limits<T>::max());
|
||||
}
|
||||
|
||||
template <typename T> static void register_float(const char* name) {
|
||||
using namespace internal;
|
||||
_embind_register_float(TypeID<T>::get(), name, sizeof(T));
|
||||
}
|
||||
|
||||
// matches typeMapping in embind.js
|
||||
enum TypedArrayIndex {
|
||||
Int8Array,
|
||||
Uint8Array,
|
||||
Int16Array,
|
||||
Uint16Array,
|
||||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
// Only available if WASM_BIGINT
|
||||
Int64Array,
|
||||
Uint64Array,
|
||||
};
|
||||
|
||||
template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
|
||||
static_assert(internal::typeSupportsMemoryView<T>(), "type does not map to a typed array");
|
||||
return std::is_floating_point<T>::value
|
||||
? (sizeof(T) == 4 ? Float32Array : Float64Array)
|
||||
: (sizeof(T) == 1
|
||||
? (std::is_signed<T>::value ? Int8Array : Uint8Array)
|
||||
: (sizeof(T) == 2 ? (std::is_signed<T>::value ? Int16Array : Uint16Array)
|
||||
: (sizeof(T) == 4 ? (std::is_signed<T>::value ? Int32Array : Uint32Array)
|
||||
: (std::is_signed<T>::value ? Int64Array : Uint64Array))));
|
||||
}
|
||||
|
||||
template <typename T> static void register_memory_view(const char* name) {
|
||||
using namespace internal;
|
||||
_embind_register_memory_view(TypeID<memory_view<T>>::get(), getTypedArrayIndex<T>(), name);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
EMSCRIPTEN_BINDINGS(builtin) {
|
||||
using namespace emscripten::internal;
|
||||
|
||||
_embind_register_void(TypeID<void>::get(), "void");
|
||||
|
||||
_embind_register_bool(TypeID<bool>::get(), "bool", sizeof(bool), true, false);
|
||||
|
||||
register_integer<char>("char");
|
||||
register_integer<signed char>("signed char");
|
||||
register_integer<unsigned char>("unsigned char");
|
||||
register_integer<signed short>("short");
|
||||
register_integer<unsigned short>("unsigned short");
|
||||
register_integer<signed int>("int");
|
||||
register_integer<unsigned int>("unsigned int");
|
||||
#if __wasm64__
|
||||
register_bigint<signed long>("long");
|
||||
register_bigint<unsigned long>("unsigned long");
|
||||
#else
|
||||
register_integer<signed long>("long");
|
||||
register_integer<unsigned long>("unsigned long");
|
||||
#endif
|
||||
|
||||
register_bigint<int64_t>("int64_t");
|
||||
register_bigint<uint64_t>("uint64_t");
|
||||
|
||||
register_float<float>("float");
|
||||
register_float<double>("double");
|
||||
|
||||
/*cjh
|
||||
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
|
||||
_embind_register_std_string(
|
||||
TypeID<std::basic_string<unsigned char>>::get(), "std::basic_string<unsigned char>");
|
||||
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
|
||||
_embind_register_std_wstring(TypeID<std::u16string>::get(), sizeof(char16_t), "std::u16string");
|
||||
_embind_register_std_wstring(TypeID<std::u32string>::get(), sizeof(char32_t), "std::u32string");
|
||||
*/
|
||||
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
|
||||
/*cjh
|
||||
// Some of these types are aliases for each other. Luckily,
|
||||
// embind.js's _embind_register_memory_view ignores duplicate
|
||||
// registrations rather than asserting, so the first
|
||||
// register_memory_view call for a particular type will take
|
||||
// precedence.
|
||||
|
||||
register_memory_view<char>("emscripten::memory_view<char>");
|
||||
register_memory_view<signed char>("emscripten::memory_view<signed char>");
|
||||
register_memory_view<unsigned char>("emscripten::memory_view<unsigned char>");
|
||||
|
||||
register_memory_view<short>("emscripten::memory_view<short>");
|
||||
register_memory_view<unsigned short>("emscripten::memory_view<unsigned short>");
|
||||
register_memory_view<int>("emscripten::memory_view<int>");
|
||||
register_memory_view<unsigned int>("emscripten::memory_view<unsigned int>");
|
||||
register_memory_view<long>("emscripten::memory_view<long>");
|
||||
register_memory_view<unsigned long>("emscripten::memory_view<unsigned long>");
|
||||
|
||||
register_memory_view<int8_t>("emscripten::memory_view<int8_t>");
|
||||
register_memory_view<uint8_t>("emscripten::memory_view<uint8_t>");
|
||||
register_memory_view<int16_t>("emscripten::memory_view<int16_t>");
|
||||
register_memory_view<uint16_t>("emscripten::memory_view<uint16_t>");
|
||||
register_memory_view<int32_t>("emscripten::memory_view<int32_t>");
|
||||
register_memory_view<uint32_t>("emscripten::memory_view<uint32_t>");
|
||||
register_memory_view<int64_t>("emscripten::memory_view<int64_t>");
|
||||
register_memory_view<uint64_t>("emscripten::memory_view<uint64_t>");
|
||||
|
||||
register_memory_view<float>("emscripten::memory_view<float>");
|
||||
register_memory_view<double>("emscripten::memory_view<double>");
|
||||
*/
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#Requires -Version "6.1"
|
||||
|
||||
Write-Host @"
|
||||
Current working directory: $(Get-Location)
|
||||
Environment vars
|
||||
-------
|
||||
GITHUB_SHA: $env:GITHUB_SHA
|
||||
GITHUB_BASE_REF: $env:GITHUB_BASE_REF
|
||||
GITHUB_EVENT_PATH: $env:GITHUB_EVENT_PATH
|
||||
"@
|
||||
|
||||
$diffFilter = "d" # Exclude deleted diff
|
||||
|
||||
# https://github.community/t/check-pushed-file-changes-with-git-diff-tree-in-github-actions/17220/10
|
||||
if ($env:GITHUB_BASE_REF) {
|
||||
# Pull Request
|
||||
git fetch origin $env:GITHUB_BASE_REF --depth=1
|
||||
$diffFiles = git diff --name-only --diff-filter=$diffFilter origin/$env:GITHUB_BASE_REF $env:GITHUB_SHA
|
||||
} else {
|
||||
# Push
|
||||
$gitHubEvent = Get-Content $env:GITHUB_EVENT_PATH | ConvertFrom-Json
|
||||
Write-Host "GitHub event: $gitHubEvent"
|
||||
$beforeSha = $gitHubEvent.before
|
||||
# On tag creation or initial push, before is all zeros - skip diff in that case
|
||||
if ($beforeSha -match '^0+$') {
|
||||
Write-Host "No previous commit (tag creation or initial push). Skipping diff."
|
||||
return
|
||||
}
|
||||
git fetch origin $beforeSha --depth=1
|
||||
$diffFiles = git diff --name-only --diff-filter=$diffFilter $beforeSha $env:GITHUB_SHA
|
||||
}
|
||||
|
||||
Write-Host "Diff files: $diffFiles"
|
||||
if (-not $diffFiles) {
|
||||
#Write-Error "Seems like we got zero diffs?"
|
||||
return
|
||||
}
|
||||
|
||||
foreach ($file in $diffFiles.Split('\n')) {
|
||||
$extension = Split-Path -Extension -Path $file
|
||||
$cont = ($extension -eq ".ts" )
|
||||
if (-not $cont -or -not ($file -match "^(cocos|exports|pal)")) {
|
||||
Write-Host "Skip $file"
|
||||
continue
|
||||
}
|
||||
Write-Host "ESLint check $file"
|
||||
npx eslint $file
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const ARGS = process.argv.slice(2);
|
||||
|
||||
const excludes = [
|
||||
'cocos/renderer/gfx-vulkan/volk',
|
||||
'cocos/bindings/auto',
|
||||
];
|
||||
|
||||
let result = [];
|
||||
|
||||
const cdbFile = path.join(__dirname, '../../native/build/compile_commands.json');
|
||||
//IMPORTANT!!!!: console.log is the stdout of this script.
|
||||
if (fs.existsSync(cdbFile)) {
|
||||
const db = JSON.parse(fs.readFileSync(cdbFile, { encoding: 'utf8' }));
|
||||
|
||||
for (let f of ARGS) {
|
||||
const name = f.endsWith('.h') ? f.slice(0, -2) : f; // ignore .h extension name
|
||||
if (excludes.some((e) => name.includes(e))) continue;
|
||||
if (db.some((info) => info.file.includes(name))) {
|
||||
result.push(f);
|
||||
}
|
||||
}
|
||||
console.log(result.join(' '));
|
||||
} else {
|
||||
console.log(ARGS.join(' '));
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/// generate jsb decorators
|
||||
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
|
||||
const contentLines = [];
|
||||
process.on('message', (msg) => {
|
||||
if (msg.event === 'write-decorator') {
|
||||
contentLines.push({ className: msg.className, lines: msg.lines });
|
||||
}
|
||||
});
|
||||
|
||||
const engineDir = path.resolve(__dirname, '../..');
|
||||
const tmpDir = os.tmpdir();
|
||||
|
||||
const BUILD_CONFIG = {
|
||||
options: {
|
||||
engine: engineDir,
|
||||
platform: 'HTML5',
|
||||
moduleFormat: 'system',
|
||||
compress: false,
|
||||
split: false,
|
||||
nativeCodeBundleMode: 'both',
|
||||
assetURLFormat: 'runtime-resolved',
|
||||
noDeprecatedFeatures: false,
|
||||
engineName: 'cocos-js',
|
||||
sourceMap: false,
|
||||
features: [
|
||||
'2d', '3d',
|
||||
'animation', 'audio',
|
||||
'base', 'dragon-bones',
|
||||
'gfx-webgl', 'gfx-webgl2',
|
||||
'intersection-2d', 'light-probe',
|
||||
'marionette', 'particle',
|
||||
'particle-2d', 'physics-2d-box2d',
|
||||
'physics-ammo', 'primitive',
|
||||
'profiler', 'skeletal-animation',
|
||||
'spine', 'terrain',
|
||||
'tiled-map', 'tween',
|
||||
'ui', 'video',
|
||||
'websocket', 'webview',
|
||||
'legacy-pipeline',
|
||||
],
|
||||
loose: true,
|
||||
mode: 'BUILD',
|
||||
flags: { DEBUG: false, UI_GPU_DRIVEN: false },
|
||||
name: 'cocos-js',
|
||||
// incremental: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\CocosCreator\\3.7.2\\builder\\engine\\8e98547c3502329ef2d27ebed2ca0eac.watch-files.json',
|
||||
//out: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\CocosCreator\\3.7.2\\builder\\engine\\8e98547c3502329ef2d27ebed2ca0eac',
|
||||
out: tmpDir,
|
||||
buildTimeConstants: {
|
||||
HTML5: true,
|
||||
NATIVE: false,
|
||||
WECHAT: false,
|
||||
BAIDU: false,
|
||||
XIAOMI: false,
|
||||
ALIPAY: false,
|
||||
TAOBAO: false,
|
||||
BYTEDANCE: false,
|
||||
OPPO: false,
|
||||
VIVO: false,
|
||||
HUAWEI: false,
|
||||
COCOSPLAY: false,
|
||||
QTT: false,
|
||||
LINKSURE: false,
|
||||
EDITOR: false,
|
||||
PREVIEW: false,
|
||||
BUILD: true,
|
||||
TEST: false,
|
||||
DEBUG: true,
|
||||
SERVER_MODE: false,
|
||||
DEV: false,
|
||||
MINIGAME: false,
|
||||
RUNTIME_BASED: false,
|
||||
SUPPORT_JIT: true,
|
||||
JSB: false,
|
||||
NOT_PACK_PHYSX_LIBS: false,
|
||||
NET_MODE: 0,
|
||||
WEBGPU: false,
|
||||
},
|
||||
generateDecoratorsForJSB: true,
|
||||
// metaFile: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\CocosCreator\\3.7.2\\builder\\engine\\8e98547c3502329ef2d27ebed2ca0eac.meta\\meta.json'
|
||||
},
|
||||
};
|
||||
|
||||
process.env.ENGINE_PATH = engineDir;
|
||||
|
||||
const { buildEngine } = require('@cocos/ccbuild');
|
||||
|
||||
buildEngine(BUILD_CONFIG.options).then((result) => {
|
||||
console.log('done!!!');
|
||||
|
||||
console.log(result);
|
||||
const sortedLines = contentLines.sort((a, b) => a.className.localeCompare(b.className)).map((x) => x.lines.join('\n')).join('\n');
|
||||
const destFile = path.join(engineDir, 'cocos/native-binding/decorators.ts');
|
||||
fs.writeFileSync(destFile, `${sortedLines}\n`, 'utf8');
|
||||
process.exit(0);
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(-1);
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
name: <Native> Generate Android NDK Cache
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
android_ndk_sdk_version:
|
||||
description: 'Android NDK Version'
|
||||
type: string
|
||||
default: 'r21e'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
generate_android_ndk_cache:
|
||||
name: "Generate Android NDK Cache"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup Android NDK
|
||||
uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
with:
|
||||
ndk-version: ${{ github.event.inputs.android_ndk_sdk_version }}
|
||||
local-cache: true
|
||||
|
||||
- name: Verify
|
||||
env:
|
||||
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
run: |
|
||||
cd ${ANDROID_NDK_HOME}
|
||||
cat source.properties
|
||||
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
./toolchains/llvm/prebuilt/${platform}-x86_64/bin/clang -v
|
||||
@@ -1,142 +0,0 @@
|
||||
name: Generate API docs JSON
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '**'
|
||||
branches-ignore:
|
||||
- '**'
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
target_tag:
|
||||
description: 'The ref (branch or tag) to build API docs'
|
||||
type: string
|
||||
default: 'v3.8.4'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
build-api-doc:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Generate API docs JSON"
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Get ref
|
||||
id: step-id-get-ref
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = 'workflow_dispatch' ]; then
|
||||
echo "Get ref from workflow_dispatch"
|
||||
echo "ENGINE_REF=${{ github.event.inputs.target_tag }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Get ref from push"
|
||||
echo "ENGINE_REF=${{ github.ref }}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Show ref
|
||||
run: |
|
||||
echo "ref: ${{ steps.step-id-get-ref.outputs.ENGINE_REF }}"
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.step-id-get-ref.outputs.ENGINE_REF }}
|
||||
|
||||
- name: Checkout the tool
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: cocos/creator-api-doc
|
||||
path: creator-api-doc
|
||||
ref: main
|
||||
|
||||
- name: Install the tool
|
||||
run: |
|
||||
cd creator-api-doc
|
||||
npm i
|
||||
# apply the url patch for typedoc@0.22.13
|
||||
npm run apply-patch
|
||||
npm run build
|
||||
|
||||
- name: Try to switch to Node v14
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
cd creator-api-doc/scripts
|
||||
eval $(./is-smaller-version.sh ${{ steps.step-id-get-ref.outputs.ENGINE_REF }} "3.8.0")
|
||||
|
||||
if [[ "$IS_LESS" == "1" ]]; then
|
||||
echo "Version less than 3.8.0"
|
||||
|
||||
export NVM_DIR="$HOME/mynvm"
|
||||
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
|
||||
pushd "$NVM_DIR"
|
||||
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
|
||||
popd
|
||||
chmod +x "$NVM_DIR/nvm.sh"
|
||||
. "$NVM_DIR/nvm.sh" --no-use
|
||||
|
||||
nvm install 14
|
||||
nvm use 14
|
||||
nvm alias default 14
|
||||
|
||||
echo "SETUP_NODE_NVM_NVM: $NVM_DIR/nvm.sh"
|
||||
echo "SETUP_NODE_NVM_NODE: $(which node)"
|
||||
echo "SETUP_NODE_NVM_NPM: $(which npm)"
|
||||
else
|
||||
echo "No need to switch to Node v14"
|
||||
fi
|
||||
|
||||
- name: Patch taobao npm mirror
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
ENGINE_ROOT=$(pwd)
|
||||
cd creator-api-doc/scripts
|
||||
eval $(./is-smaller-version.sh ${{ steps.step-id-get-ref.outputs.ENGINE_REF }} "3.8.4")
|
||||
|
||||
if [[ "$IS_LESS" == "1" ]]; then
|
||||
echo "Version less than 3.8.4"
|
||||
node ./replace-taobao.js $ENGINE_ROOT
|
||||
sed -i 's/nlark/npmmirror/g' $ENGINE_ROOT/package-lock.json
|
||||
else
|
||||
echo "No need to patch taobao npm mirror"
|
||||
fi
|
||||
|
||||
- name: Download external libraries
|
||||
run: |
|
||||
EXT_VERSION=`grep checkout native/external-config.json | awk -F'"' '{print $4}'`
|
||||
echo "EXT_VERSION: ${EXT_VERSION}"
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- name: Install Cocos Engine
|
||||
run: |
|
||||
export NVM_DIR="$HOME/mynvm"
|
||||
if [ -d "$NVM_DIR" ]; then
|
||||
echo "Found NVM_DIR"
|
||||
. "$NVM_DIR/nvm.sh" --no-use
|
||||
nvm use 14
|
||||
nvm alias default 14
|
||||
fi
|
||||
|
||||
echo "NODE: $(which node)"
|
||||
echo "NPM: $(which npm)"
|
||||
npm i
|
||||
|
||||
- name: Generate
|
||||
run: |
|
||||
which node
|
||||
node --version
|
||||
pwd
|
||||
ls -l
|
||||
ENGINE_ROOT=$(pwd)
|
||||
echo "ENGINE_ROOT: ${ENGINE_ROOT}"
|
||||
cd creator-api-doc
|
||||
node ./lib/cli.js -p $ENGINE_ROOT -o $ENGINE_ROOT/Cocos-Creator-API.json
|
||||
ls -l ..
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Cocos-Creator-API
|
||||
path: Cocos-Creator-API.json
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
name: <Native> Generate Emsdk Cache
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
emsdk_version:
|
||||
description: 'Emsdk version'
|
||||
type: string
|
||||
default: '3.1.45'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
generate_emsdk_cache:
|
||||
name: "Generate Emsdk cache"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: ${{ github.event.inputs.emsdk_version }}
|
||||
|
||||
- name: Verify
|
||||
run: |
|
||||
which emcc
|
||||
emcc -v
|
||||
@@ -1,45 +0,0 @@
|
||||
name: <Native> Generate OH SDK Cache
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
generate_oh_sdk_cache:
|
||||
name: "Generate OH SDK cache"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get oh sdk cache directory path
|
||||
id: oh-sdk-cache-dir-path
|
||||
run: |
|
||||
echo "cache dir: "
|
||||
echo "dir=$HOME/openharmony" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Output cache dir
|
||||
run: |
|
||||
echo "Output cache dir: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}"
|
||||
|
||||
- name: Cache OH SDK
|
||||
id: cache-oh-sdk
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: cache-oh-sdk-21
|
||||
with:
|
||||
path: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}
|
||||
|
||||
- if: ${{ steps.cache-oh-sdk.outputs.cache-hit != 'true' }}
|
||||
name: No Cache found, install oh sdk
|
||||
continue-on-error: false
|
||||
run: |
|
||||
if [ ! -d "$HOME/openharmony" ]; then
|
||||
mkdir -p $HOME/openharmony
|
||||
echo "Download commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
7z x commandline-tools-linux-x64-6.0.1.246.zip.001 -o$HOME/openharmony > /dev/null
|
||||
cd $HOME/openharmony
|
||||
ls -l
|
||||
cd command-line-tools
|
||||
ls -l
|
||||
fi
|
||||
@@ -1,22 +0,0 @@
|
||||
name: <Native> Generate Vulkan SDK Cache
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
vulkan_sdk_version:
|
||||
description: 'Vulkan SDK version'
|
||||
type: string
|
||||
default: '1.3.243.0'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
generate_vulkan_sdk_cache:
|
||||
name: "Generate Vulkan SDK cache"
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Setup Vulkan SDK
|
||||
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
|
||||
with:
|
||||
vulkan-query-version: ${{ github.event.inputs.vulkan_sdk_version }}
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader
|
||||
vulkan-use-cache: true
|
||||
@@ -1,8 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const configJsonPath = path.join(__dirname, '../../native/external-config.json');
|
||||
const configData = fs.readFileSync(configJsonPath);
|
||||
const config = JSON.parse(configData);
|
||||
const externalVersion = config.from.checkout;
|
||||
console.log(externalVersion);
|
||||
@@ -1,20 +0,0 @@
|
||||
const ps = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const interfaceDiffPath = ps.join(__dirname, '../../interface-diff.txt');
|
||||
let reportContent = fs.readFileSync(interfaceDiffPath, 'utf8');
|
||||
|
||||
if (reportContent.includes('@')) {
|
||||
reportContent = reportContent.split('\n').slice(3).join('\n');
|
||||
reportContent = `## Interface Check Report
|
||||
\`\`\`diff
|
||||
! WARNING this pull request has changed these public interfaces:
|
||||
|
||||
${reportContent}
|
||||
\`\`\`
|
||||
`;
|
||||
} else {
|
||||
reportContent = `## Interface Check Report
|
||||
This pull request does not change any public interfaces !`;
|
||||
}
|
||||
fs.writeFileSync(interfaceDiffPath, reportContent, 'utf8');
|
||||
@@ -1,50 +0,0 @@
|
||||
const fs = require('fs');
|
||||
|
||||
// read json from stdin
|
||||
|
||||
let buffer = Buffer.alloc(0);
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
function getAttrByPath(object, pathText) {
|
||||
const parts = pathText.split('.');
|
||||
let curr = object;
|
||||
const REG1 = /\["(\w+)"\]/;
|
||||
const REG2 = /\[(\w+)\]/;
|
||||
const REG3 = /"(\w+)"/;
|
||||
const REG4 = /(\w+)/;
|
||||
const regList = [REG1, REG2, REG3, REG4];
|
||||
for (const p of parts) {
|
||||
let mat;
|
||||
let field = null;
|
||||
for (let r of regList) {
|
||||
mat = p.match(r);
|
||||
if (mat) {
|
||||
field = mat[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!field) {
|
||||
console.error(`path component "${p}" is invalidate from ${pathText}`);
|
||||
process.exit(1);
|
||||
}
|
||||
curr = curr[field];
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
|
||||
process.stdin.resume();
|
||||
|
||||
process.stdin.on('data', data => {
|
||||
buffer = Buffer.concat([buffer, data]);
|
||||
}).on('end', () => {
|
||||
const data = JSON.parse(buffer.toString('utf8'))
|
||||
let value = getAttrByPath(data, args[0]);
|
||||
if(args.length >= 2) {
|
||||
const mat = value.match(new RegExp(args[1]));
|
||||
if(mat) {
|
||||
value = mat[args[2]];
|
||||
}
|
||||
}
|
||||
console.log(value);
|
||||
});
|
||||
@@ -1,186 +0,0 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
################################################################################
|
||||
#
|
||||
# This script will install the llvm toolchain on the different
|
||||
# Debian and Ubuntu versions
|
||||
|
||||
set -eux
|
||||
|
||||
usage() {
|
||||
set +x
|
||||
echo "Usage: $0 [llvm_major_version] [all] [OPTIONS]" 1>&2
|
||||
echo -e "all\t\t\tInstall all packages." 1>&2
|
||||
echo -e "-n=code_name\t\tSpecifies the distro codename, for example bionic" 1>&2
|
||||
echo -e "-h\t\t\tPrints this help." 1>&2
|
||||
echo -e "-m=repo_base_url\tSpecifies the base URL from which to download." 1>&2
|
||||
exit 1;
|
||||
}
|
||||
|
||||
CURRENT_LLVM_STABLE=18
|
||||
BASE_URL="http://apt.llvm.org"
|
||||
|
||||
# Check for required tools
|
||||
needed_binaries=(lsb_release wget add-apt-repository gpg)
|
||||
missing_binaries=()
|
||||
for binary in "${needed_binaries[@]}"; do
|
||||
if ! which $binary &>/dev/null ; then
|
||||
missing_binaries+=($binary)
|
||||
fi
|
||||
done
|
||||
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
|
||||
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
|
||||
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Set default values for commandline arguments
|
||||
# We default to the current stable branch of LLVM
|
||||
LLVM_VERSION=$CURRENT_LLVM_STABLE
|
||||
ALL=0
|
||||
DISTRO=$(lsb_release -is)
|
||||
VERSION=$(lsb_release -sr)
|
||||
UBUNTU_CODENAME=""
|
||||
CODENAME_FROM_ARGUMENTS=""
|
||||
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
|
||||
source /etc/os-release
|
||||
UBUNTU_CODENAME="focal"
|
||||
DISTRO=${DISTRO,,}
|
||||
case ${DISTRO} in
|
||||
debian)
|
||||
# Debian Trixie has a workaround because of
|
||||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
|
||||
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
|
||||
CODENAME=unstable
|
||||
LINKNAME=
|
||||
else
|
||||
# "stable" Debian release
|
||||
CODENAME=${VERSION_CODENAME}
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# ubuntu and its derivatives
|
||||
if [[ -n "${UBUNTU_CODENAME}" ]]; then
|
||||
CODENAME=${UBUNTU_CODENAME}
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# read optional command line arguments
|
||||
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
|
||||
if [ "$1" != "all" ]; then
|
||||
LLVM_VERSION=$1
|
||||
else
|
||||
# special case for ./llvm.sh all
|
||||
ALL=1
|
||||
fi
|
||||
OPTIND=2
|
||||
if [ "$#" -ge 2 ]; then
|
||||
if [ "$2" == "all" ]; then
|
||||
# Install all packages
|
||||
ALL=1
|
||||
OPTIND=3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
while getopts ":hm:n:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
m)
|
||||
BASE_URL=${OPTARG}
|
||||
;;
|
||||
n)
|
||||
CODENAME=${OPTARG}
|
||||
if [[ "${CODENAME}" == "unstable" ]]; then
|
||||
# link name does not apply to unstable repository
|
||||
LINKNAME=
|
||||
else
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
CODENAME_FROM_ARGUMENTS="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare -A LLVM_VERSION_PATTERNS
|
||||
LLVM_VERSION_PATTERNS[9]="-9"
|
||||
LLVM_VERSION_PATTERNS[10]="-10"
|
||||
LLVM_VERSION_PATTERNS[11]="-11"
|
||||
LLVM_VERSION_PATTERNS[12]="-12"
|
||||
LLVM_VERSION_PATTERNS[13]="-13"
|
||||
LLVM_VERSION_PATTERNS[14]="-14"
|
||||
LLVM_VERSION_PATTERNS[15]="-15"
|
||||
LLVM_VERSION_PATTERNS[16]="-16"
|
||||
LLVM_VERSION_PATTERNS[17]="-17"
|
||||
LLVM_VERSION_PATTERNS[18]="-18"
|
||||
LLVM_VERSION_PATTERNS[19]="-19"
|
||||
LLVM_VERSION_PATTERNS[20]="-20"
|
||||
LLVM_VERSION_PATTERNS[21]=""
|
||||
|
||||
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
|
||||
echo "This script does not support LLVM version $LLVM_VERSION"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
|
||||
|
||||
# join the repository name
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
|
||||
|
||||
# check if the repository exists for the distro and version
|
||||
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
|
||||
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
|
||||
echo "Specified codename '${CODENAME}' is not supported by this script."
|
||||
else
|
||||
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
|
||||
fi
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# install everything
|
||||
|
||||
if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then
|
||||
# download GPG key once
|
||||
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||
fi
|
||||
|
||||
if [[ -z "`apt-key list 2> /dev/null | grep -i llvm`" ]]; then
|
||||
# Delete the key in the old format
|
||||
apt-key del AF4F7421 || true
|
||||
fi
|
||||
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
|
||||
# add it twice to workaround:
|
||||
# https://github.com/llvm/llvm-project/issues/62475
|
||||
add-apt-repository -y "${REPO_NAME}"
|
||||
fi
|
||||
|
||||
add-apt-repository -y "${REPO_NAME}"
|
||||
apt-get update
|
||||
PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION"
|
||||
if [[ $ALL -eq 1 ]]; then
|
||||
# same as in test-install.sh
|
||||
# No worries if we have dups
|
||||
PKG="$PKG clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION llvm-$LLVM_VERSION-dev lld-$LLVM_VERSION lldb-$LLVM_VERSION llvm-$LLVM_VERSION-tools libomp-$LLVM_VERSION-dev libc++-$LLVM_VERSION-dev libc++abi-$LLVM_VERSION-dev libclang-common-$LLVM_VERSION-dev libclang-$LLVM_VERSION-dev libclang-cpp$LLVM_VERSION-dev libunwind-$LLVM_VERSION-dev"
|
||||
if test $LLVM_VERSION -gt 14; then
|
||||
PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev"
|
||||
fi
|
||||
fi
|
||||
apt-get install -y $PKG
|
||||
@@ -1,88 +0,0 @@
|
||||
name: <Native> Generate Code
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [closed]
|
||||
|
||||
jobs:
|
||||
autogen-code:
|
||||
# if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install CMake & Clang Tidy
|
||||
run: |
|
||||
sudo apt update --fix-missing
|
||||
sudo apt install -y ninja-build
|
||||
- name: Download external
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
with:
|
||||
ndk-version: r21e
|
||||
add-to-path: false
|
||||
local-cache: true
|
||||
- name: Generate decorators
|
||||
env:
|
||||
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
run: |
|
||||
cd native
|
||||
echo "Generate compile_commands.json & ninja target"
|
||||
bash ./utils/generate_compile_commands_android.sh
|
||||
echo "Generate binding code ..."
|
||||
ninja -C build genbindings
|
||||
cd ..
|
||||
npm install
|
||||
echo " parsing ..."
|
||||
node .github/workflows/gen_decorators.js
|
||||
echo " generate done!"
|
||||
git checkout HEAD package.json package-lock.json
|
||||
|
||||
- name: Update auto-gen source files
|
||||
run: |
|
||||
cd native
|
||||
echo "Generating DebugInfos ... "
|
||||
node cmake/scripts/gen_debugInfos.js \
|
||||
../EngineErrorMap.md \
|
||||
cocos/core/builtin/DebugInfos.cpp.in \
|
||||
cocos/core/builtin/DebugInfos.cpp
|
||||
echo "Generating cocos-version.h ... "
|
||||
node ./cmake/scripts/engine-version.js
|
||||
|
||||
- name: Create Pull Request
|
||||
uses: fish9167/create-pull-request@v3
|
||||
if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
|
||||
with:
|
||||
title: '[ci skip][AUTO]: Automated PR to generate code'
|
||||
body: |
|
||||
Automated PR to genbindings & built resources
|
||||
[X] does not change any runtime related code or build configuration
|
||||
committer: cocos-robot <cocos-robot@cocos.com>
|
||||
author: cocos-robot <cocos-robot@cocos.com>
|
||||
commit-message: "[ci skip][AUTO]: Automated code generating update: ${{ github.event.pull_request.head.sha }} (#${{ github.event.number }})"
|
||||
token: ${{ secrets.PR_TOKEN }}
|
||||
push-to-fork: cocos-robot/cocos4
|
||||
branch: t/bot/genbindings
|
||||
branch-suffix: short-commit-hash
|
||||
delete-branch: true
|
||||
|
||||
- name: Notify PR author on error
|
||||
if: ${{ failure() }}
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const issue_number = context.payload.pull_request.number;
|
||||
const pr_author = context.payload.pull_request.user.login;
|
||||
const error_comment = `@${pr_author} :exclamation: There was an error during the execution of the tasks. Please check the logs for more details.`;
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
body: error_comment,
|
||||
});
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,51 +0,0 @@
|
||||
name: <Native> Apply clang format
|
||||
|
||||
#on: [push, pull_request]
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [closed]
|
||||
paths:
|
||||
- 'templates/**'
|
||||
- 'native/**'
|
||||
|
||||
jobs:
|
||||
Clang-Format:
|
||||
if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ github.token }}
|
||||
ref: ${{ github.head_sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- id: get_change_files
|
||||
uses: fish9167/file-changes-action@v1.2.3
|
||||
with:
|
||||
output: ' '
|
||||
fileOutput: ' '
|
||||
|
||||
- uses: DoozyX/clang-format-lint-action@v0.18
|
||||
with:
|
||||
source: ./native
|
||||
exclude: ./native/cocos/bindings/auto ./native/cocos/base/std ./native/cocos/editor-support/spine-wasm ./native/cocos/editor-support/spine ./native/cocos/gi/light-probe/predicates.cpp ./native/cocos/gi/light-probe/tetgen.cpp ./native/cocos/gi/light-probe/tetgen.h ./native/cocos/platform/openharmony/napi ./native/tools ./native/vendor ./native/cocos/cocos-version.h
|
||||
extensions: 'c,h,hpp,cpp,cxx'
|
||||
style: file
|
||||
inplace: true
|
||||
clangFormatVersion: 12
|
||||
|
||||
- name: Create Pull Request
|
||||
uses: fish9167/create-pull-request@v3
|
||||
with:
|
||||
title: '[ci skip][AUTO]: Automated PR to fix formatting'
|
||||
body: |
|
||||
Automated PR to fix formatting
|
||||
committer: cocos-robot <cocos-robot@cocos.com>
|
||||
author: cocos-robot <cocos-robot@cocos.com>
|
||||
commit-message: "[ci skip][AUTO]: Automated clang-format update: ${{ github.event.pull_request.head.sha }} (#${{ github.event.number }})"
|
||||
token: ${{ secrets.PR_TOKEN }}
|
||||
push-to-fork: cocos-robot/cocos4
|
||||
branch: t/bot/fix-format
|
||||
branch-suffix: short-commit-hash
|
||||
delete-branch: true
|
||||
@@ -1,56 +0,0 @@
|
||||
name: <Native> Linux
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '.github/workflows/native-compile-linux.yml'
|
||||
- 'templates/**'
|
||||
- 'native/**'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
compile_linux:
|
||||
name: "Linux-Ubuntu"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt install libx11-dev -y
|
||||
sudo apt install libsndio-dev -y
|
||||
sudo apt install ninja-build -y
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
echo "Compiling Linux ... "
|
||||
cd $GITHUB_WORKSPACE/templates/linux
|
||||
mkdir -p build-linux/proj
|
||||
touch build-linux/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN OFF)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 OFF)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 ON)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(CC_USE_METAL OFF)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX OFF)" >> build-linux/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-linux/proj/cfg.cmake
|
||||
mkdir build-linux/assets
|
||||
|
||||
RES_DIR=$GITHUB_WORKSPACE/templates/linux/build-linux
|
||||
cd build-linux
|
||||
cmake ../ -GNinja -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$NATIVE_ROOT
|
||||
set +e
|
||||
cmake --build .
|
||||
@@ -1,552 +0,0 @@
|
||||
name: <Native> Compile
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'templates/**'
|
||||
- 'native/**'
|
||||
- '.github/workflows/native-compile-platforms.yml'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
compile_windows:
|
||||
name: "Windows"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { buildtype: Debug }
|
||||
- { buildtype: Release }
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- name: Install deps
|
||||
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
|
||||
with:
|
||||
vulkan-query-version: 1.3.243.0
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader
|
||||
vulkan-use-cache: false
|
||||
- name: Compile win64
|
||||
shell: bash
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/templates/windows
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> Post-Sample.cmake
|
||||
mkdir -p build-win64/proj
|
||||
touch build-win64/proj/cfg.cmake
|
||||
echo "set(USE_BOX2D_JSB ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-win64/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-win64/proj/cfg.cmake
|
||||
mkdir build-win64/assets
|
||||
cd build-win64
|
||||
RES_DIR=${GITHUB_WORKSPACE//\\//}/templates/windows/build-win64
|
||||
COCOS_X_PATH=${GITHUB_WORKSPACE//\\//}/native
|
||||
cmake ../ -G"Visual Studio 17 2022" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS_X_PATH -Ax64
|
||||
cmake --build . --config ${{ matrix.config.buildtype }}
|
||||
echo "Compile Win64 ${{ matrix.config.buildtype }} Done!"
|
||||
|
||||
compile_android_minimal:
|
||||
name: "Android Minimal"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
with:
|
||||
ndk-version: r28b
|
||||
add-to-path: false
|
||||
local-cache: true
|
||||
- uses: actions/setup-java@v4
|
||||
id: setup-jdk
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '17'
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
NDK_VERSION=${{ steps.setup-ndk.outputs.ndk-full-version }}
|
||||
NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template
|
||||
echo "Compiling Android ... "
|
||||
cd $GITHUB_WORKSPACE/templates/
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> android/template/Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> android/template/Post-Sample.cmake
|
||||
if [ ! -d android-template ]; then
|
||||
cp -r android/template android-template
|
||||
fi
|
||||
cd $GITHUB_WORKSPACE/templates/android/build
|
||||
mkdir -p build-android/proj
|
||||
touch build-android/proj/cfg.cmake
|
||||
echo "set(CI_FORCE_MINIMAL_FEATURES ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(COCOS_X_PATH $NATIVE_ROOT)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-android/proj/cfg.cmake
|
||||
|
||||
mkdir -p build-android/proj/res/values
|
||||
cat << EOF > build-android/proj/res/values/strings.xml
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">CocosGame</string>
|
||||
</resources>
|
||||
EOF
|
||||
|
||||
mkdir -p build-android/assets
|
||||
|
||||
ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/
|
||||
|
||||
sed -i "s@^PROP_NDK_VERSION.*@PROP_NDK_VERSION=$NDK_VERSION@g" gradle.properties
|
||||
sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties
|
||||
sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties
|
||||
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties
|
||||
sed -i "s@^NATIVE_DIR.*@NATIVE_DIR=$NATIVE_DIR@g" gradle.properties
|
||||
|
||||
# To speedup CI, compile x86 only
|
||||
# sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties
|
||||
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=x86@g" gradle.properties
|
||||
|
||||
echo "Compile Android - cmake ..."
|
||||
echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
|
||||
# ./gradlew :CocosGame:assembleDebug --quiet
|
||||
./gradlew :CocosGame:assembleRelease --quiet
|
||||
echo "Compile Android Debug Done!"
|
||||
|
||||
compile_android:
|
||||
name: "Android"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { arch: armeabi-v7a }
|
||||
- { arch: arm64-v8a }
|
||||
- { arch: x86 }
|
||||
- { arch: x86_64 }
|
||||
|
||||
steps:
|
||||
- name: Before free space
|
||||
run: |
|
||||
df -h
|
||||
|
||||
- name: Free Disk Space (Ubuntu)
|
||||
uses: jlumbroso/free-disk-space@d5af243ce7bacb67384aa6c5b1fc5f169e30903e
|
||||
with:
|
||||
tool-cache: true
|
||||
android: false
|
||||
dotnet: true
|
||||
haskell: true
|
||||
large-packages: true
|
||||
docker-images: true
|
||||
swap-storage: true
|
||||
|
||||
- name: After free space
|
||||
run: |
|
||||
df -h
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
with:
|
||||
ndk-version: r28b
|
||||
add-to-path: false
|
||||
local-cache: true
|
||||
- uses: actions/setup-java@v4
|
||||
id: setup-jdk
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '17'
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
NDK_VERSION=${{ steps.setup-ndk.outputs.ndk-full-version }}
|
||||
NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template
|
||||
echo "Compiling Android ... "
|
||||
cd $GITHUB_WORKSPACE/templates/
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> android/template/Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> android/template/Post-Sample.cmake
|
||||
if [ ! -d android-template ]; then
|
||||
cp -r android/template android-template
|
||||
fi
|
||||
cd $GITHUB_WORKSPACE/templates/android/build
|
||||
mkdir -p build-android/proj
|
||||
touch build-android/proj/cfg.cmake
|
||||
echo "set(USE_GOOGLE_BILLING ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_GOOGLE_PLAY_GAMES ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_BOX2D_JSB ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_SPINE_3_8 OFF)" >> build-android/proj/cfg.cmake
|
||||
echo "set(USE_SPINE_4_2 ON)" >> build-android/proj/cfg.cmake
|
||||
echo "set(COCOS_X_PATH $NATIVE_ROOT)" >> build-android/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-android/proj/cfg.cmake
|
||||
|
||||
mkdir -p build-android/proj/res/values
|
||||
cat << EOF > build-android/proj/res/values/strings.xml
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">CocosGame</string>
|
||||
</resources>
|
||||
EOF
|
||||
|
||||
mkdir -p build-android/assets
|
||||
|
||||
ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/
|
||||
|
||||
sed -i "s@^PROP_NDK_VERSION.*@PROP_NDK_VERSION=$NDK_VERSION@g" gradle.properties
|
||||
sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties
|
||||
sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties
|
||||
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties
|
||||
sed -i "s@^NATIVE_DIR.*@NATIVE_DIR=$NATIVE_DIR@g" gradle.properties
|
||||
|
||||
# To speedup CI, compile arm64-v8a only
|
||||
# sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties
|
||||
df -h
|
||||
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=${{ matrix.config.arch }}@g" gradle.properties
|
||||
|
||||
echo "Compile Android - cmake ..."
|
||||
echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
|
||||
./gradlew :CocosGame:assembleDebug # --quiet
|
||||
df -h
|
||||
# ./gradlew clean
|
||||
# sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a@g" gradle.properties
|
||||
# ./gradlew :CocosGame:assembleDebug --quiet
|
||||
# df -h
|
||||
echo "Compile Android Debug Done!"
|
||||
|
||||
compile_openharmony:
|
||||
name: "Openharmony"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { arch: arm64-v8a, jsEngine: V8 }
|
||||
- { arch: arm64-v8a, jsEngine: ARK }
|
||||
- { arch: arm64-v8a, jsEngine: JSVM }
|
||||
|
||||
steps:
|
||||
- name: Show PATH env
|
||||
run: |
|
||||
echo "PATH=$PATH"
|
||||
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
|
||||
echo "ldconfig"
|
||||
ldconfig -v 2>/dev/null | awk '{print $1}' | grep -E '^/'
|
||||
echo "/etc/ld.so.conf"
|
||||
cat /etc/ld.so.conf
|
||||
cat /etc/ld.so.conf.d/*
|
||||
|
||||
- name: Before free space
|
||||
run: |
|
||||
df -h
|
||||
|
||||
- name: Free Disk Space (Ubuntu)
|
||||
uses: jlumbroso/free-disk-space@d5af243ce7bacb67384aa6c5b1fc5f169e30903e
|
||||
with:
|
||||
tool-cache: true
|
||||
android: true
|
||||
dotnet: true
|
||||
haskell: true
|
||||
large-packages: true
|
||||
docker-images: true
|
||||
swap-storage: true
|
||||
|
||||
- name: After free space
|
||||
run: |
|
||||
df -h
|
||||
|
||||
- name: Install libgl1
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libgl1
|
||||
|
||||
- name: Checking libGL.so.1
|
||||
run: |
|
||||
echo "Checking libGL.so.1 since sdk/default/hms/toolchains/lib/libimage_transcoder_shared.so needs it"
|
||||
ls -l /usr/lib/x86_64-linux-gnu/*.so*
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- uses: actions/setup-java@v4
|
||||
id: setup-jdk
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '17'
|
||||
- name: Get oh sdk cache directory path
|
||||
id: oh-sdk-cache-dir-path
|
||||
run: |
|
||||
echo "cache dir: "
|
||||
echo "dir=$HOME/openharmony" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Output cache dir
|
||||
run: |
|
||||
echo "Output cache dir: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}"
|
||||
|
||||
- name: Cache OH SDK
|
||||
id: cache-oh-sdk
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: cache-oh-sdk-21
|
||||
with:
|
||||
path: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}
|
||||
|
||||
# - name: Add package.json
|
||||
# run: |
|
||||
# echo "{}" > package.json
|
||||
# echo "{\"name\": \"tests\",\"lockfileVersion\": 3,\"requires\": true,\"packages\": {}}" > package-lock.json
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 14
|
||||
|
||||
- if: ${{ steps.cache-oh-sdk.outputs.cache-hit != 'true' }}
|
||||
name: No Cache found, install oh sdk
|
||||
continue-on-error: false
|
||||
run: |
|
||||
if [ ! -d "$HOME/openharmony" ]; then
|
||||
mkdir -p $HOME/openharmony
|
||||
echo "Download commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
7z x commandline-tools-linux-x64-6.0.1.246.zip.001 -o$HOME/openharmony > /dev/null
|
||||
cd $HOME/openharmony
|
||||
ls -l
|
||||
cd command-line-tools
|
||||
ls -l
|
||||
fi
|
||||
|
||||
- name: Compile for Openharmony
|
||||
run: |
|
||||
which node
|
||||
which npm
|
||||
which java
|
||||
node -v
|
||||
npm -v
|
||||
java --version
|
||||
echo "=============== list files in oh sdk ($HOME/openharmony) ==============="
|
||||
pushd $HOME/openharmony/command-line-tools
|
||||
ls -l
|
||||
popd
|
||||
|
||||
export PATH=$PATH:$HOME/openharmony/command-line-tools/bin
|
||||
echo "PATH=$PATH"
|
||||
echo "hvigorw path:"
|
||||
which hvigorw
|
||||
echo "ohpm path:"
|
||||
which ohpm
|
||||
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
echo "Compiling Openharmony ... "
|
||||
|
||||
cd $GITHUB_WORKSPACE/templates/harmonyos-next
|
||||
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> Post-Sample.cmake
|
||||
|
||||
mkdir -p build-oh/proj
|
||||
touch build-oh/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(COCOS_X_PATH $NATIVE_ROOT)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-oh/proj/cfg.cmake
|
||||
if [ "${{ matrix.config.jsEngine }}" = "V8" ]; then
|
||||
echo "=============== JsEngine: V8 ==============="
|
||||
echo "set(USE_SE_V8 ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_NAPI OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_JSVM OFF)" >> build-oh/proj/cfg.cmake
|
||||
elif [ "${{ matrix.config.jsEngine }}" = "JSVM" ]; then
|
||||
echo "=============== JsEngine: JSVM ==============="
|
||||
echo "set(USE_SE_V8 OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_NAPI OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_JSVM ON)" >> build-oh/proj/cfg.cmake
|
||||
else
|
||||
echo "=============== JsEngine: ARK ==============="
|
||||
echo "set(USE_SE_V8 OFF)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_NAPI ON)" >> build-oh/proj/cfg.cmake
|
||||
echo "set(USE_SE_JSVM OFF)" >> build-oh/proj/cfg.cmake
|
||||
fi
|
||||
|
||||
echo "=============== cat build-oh/proj/cfg.cmake ==============="
|
||||
cat build-oh/proj/cfg.cmake
|
||||
|
||||
mkdir -p build-oh/assets
|
||||
|
||||
ASSET_DIR=$GITHUB_WORKSPACE/templates/harmonyos-next/build-oh
|
||||
|
||||
echo "=============== HACK ./entry/build-profile.json5 ==============="
|
||||
sed -i "s@[^-]DRES_DIR[^=]@$ASSET_DIR@g" ./entry/build-profile.json5
|
||||
sed -i "s@[^-]DCOMMON_DIR[^=]@$GITHUB_WORKSPACE/templates/common@g" ./entry/build-profile.json5
|
||||
# To speedup CI, compile arm64-v8a only
|
||||
sed -i "s@arm64-v8a@${{ matrix.config.arch }}@g" ./entry/build-profile.json5
|
||||
|
||||
echo "entry/build-profile.json5: "
|
||||
cat ./entry/build-profile.json5
|
||||
|
||||
# echo "=============== UPDATE ./hvigor/hvigor-config.json5 ==============="
|
||||
# echo "{\"hvigorVersion\":\"3.0.2\",\"dependencies\":{\"@ohos/hvigor-ohos-plugin\":\"3.0.2\"}}" > ./hvigor/hvigor-config.json5
|
||||
|
||||
echo "=============== Do not import game.ts for cocos_worker.ets ==============="
|
||||
sed -i '/<% if(!useV8) { %>/,/<% } %>/d' ./entry/src/main/ets/workers/cocos_worker.ets
|
||||
sed -i '/<% if(useV8) { %>/,/<% } %>/d' ./entry/src/main/ets/workers/cocos_worker.ets
|
||||
ls -l ./entry/src/main/ets/workers/cocos_worker.ets
|
||||
|
||||
echo "=============== EXECUTE hvigorw ==============="
|
||||
ohpm install
|
||||
hvigorw clean -i
|
||||
hvigorw --stop-daemon -i
|
||||
hvigorw --mode module -p product=default assembleHap --parallel --incremental debuggable=true --no-daemon -d
|
||||
#./hvigorw default@ProcessLibs -p debuggable=true --no-daemon -d
|
||||
echo "=============== EXECUTE hvigorw DONE ==============="
|
||||
|
||||
compile_mac:
|
||||
name: "MacOS"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { arch: x86_64 }
|
||||
- { arch: arm64 }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
NUM_OF_CORES=`getconf _NPROCESSORS_ONLN`
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
echo "Compiling MacOSX ... "
|
||||
cd $GITHUB_WORKSPACE/templates/mac
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> Post-Sample.cmake
|
||||
mkdir -p build-mac/proj
|
||||
touch build-mac/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX ON)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN OFF)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 OFF)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 OFF)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CC_USE_METAL ON)" >> build-mac/proj/cfg.cmake
|
||||
# Test JSVM v8 backend on macOS.
|
||||
echo "set(USE_SE_V8 ON)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(USE_SE_JSVM OFF)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-mac/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-mac/proj/cfg.cmake
|
||||
mkdir build-mac/assets
|
||||
|
||||
RES_DIR=$GITHUB_WORKSPACE/templates/mac/build-mac
|
||||
cd build-mac
|
||||
cmake ../ -GXcode -DCMAKE_OSX_ARCHITECTURES=${{ matrix.config.arch }} -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$NATIVE_ROOT
|
||||
cmake --build . --config Release -- -jobs $NUM_OF_CORES -arch ${{ matrix.config.arch }}
|
||||
echo "Compile MacOSX Release Done!"
|
||||
|
||||
compile_iOS:
|
||||
name: "iOS"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { sdk: iphoneos, arch: arm64 }
|
||||
- { sdk: iphonesimulator, arch: x86_64 }
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
set -x
|
||||
NUM_OF_CORES=`getconf _NPROCESSORS_ONLN`
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
echo "Compiling iOS ... "
|
||||
cd $GITHUB_WORKSPACE/templates/ios
|
||||
echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake
|
||||
echo "message(STATUS \"hook after \${CC_TARGET_NAME}\")" >> Post-Sample.cmake
|
||||
mkdir -p build-ios/proj
|
||||
touch build-ios/proj/cfg.cmake
|
||||
echo "set(USE_PHYSICS_PHYSX ON)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES3 OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CC_USE_VULKAN OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CC_USE_GLES2 OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CC_USE_METAL ON)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(TARGET_IOS_VERSION 13.0)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(USE_DRAGONBONES OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CMAKE_CXX_STANDARD_REQUIRED OFF)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(MACOSX_BUNDLE_GUI_IDENTIFIER com.cocos.demo.ios)" >> build-ios/proj/cfg.cmake
|
||||
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-ios/proj/cfg.cmake
|
||||
mkdir build-ios/assets
|
||||
cd build-ios
|
||||
RES_DIR=$GITHUB_WORKSPACE/templates/ios/build-ios
|
||||
cmake ../ -GXcode -DCMAKE_SYSTEM_NAME=iOS \
|
||||
-DCMAKE_OSX_SYSROOT=${{ matrix.config.sdk }} \
|
||||
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.config.arch }} \
|
||||
-DRES_DIR=$RES_DIR \
|
||||
-DCOCOS_X_PATH=$NATIVE_ROOT
|
||||
#cmake --build . --config Debug -- -quiet -jobs $NUM_OF_CORES -allowProvisioningUpdates CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
|
||||
cmake --build . --config Debug -- -jobs $NUM_OF_CORES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
|
||||
echo "Compile iOS Done!"
|
||||
@@ -1,50 +0,0 @@
|
||||
name: <Native> Assign Generated PR
|
||||
|
||||
# on:
|
||||
# pull_request_target:
|
||||
# types: [opened]
|
||||
# paths:
|
||||
# - 'native/cocos/bindings/auto/**'
|
||||
|
||||
on: pull_request_target
|
||||
|
||||
jobs:
|
||||
auto-assign:
|
||||
if:
|
||||
(contains(github.event.pull_request.body, 'Automated PR to genbindings'))
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Update assignees
|
||||
id: merger
|
||||
env:
|
||||
PR_NUMBER: ${{github.event.number}}
|
||||
# REPO_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
# REPO_TOKEN: ${{secrets.PR_TOKEN}}
|
||||
REPO_TOKEN: ${{secrets.LABEL_TOKEN}}
|
||||
run: |
|
||||
SRC_PR=`curl ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits | \
|
||||
sh -c 'node ./.github/workflows/jsonr.js [0].commit.message "\(#(\w+)\)" 1'`
|
||||
echo "Source PR: ${SRC_PR}"
|
||||
SRC_MERGER=`curl -H "Accept: application/vnd.github+json" ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${SRC_PR} | \
|
||||
sh -c 'node ./.github/workflows/jsonr.js merged_by.login'`
|
||||
echo "Source PR merger: ${SRC_MERGER}"
|
||||
echo "Token Length: ${#REPO_TOKEN}"
|
||||
echo ::set-output name=SRC_MERGER::${SRC_MERGER}
|
||||
# curl -X POST -H "Accept: application/vnd.github+json" \
|
||||
# -H "Authorization: token $REPO_TOKEN" \
|
||||
# ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/assignees \
|
||||
# -d "{\"assignees\":[\"${SRC_MERGER}\"]}"
|
||||
# exit 0
|
||||
# - name: Assignment
|
||||
# uses: OperationsYU/auto-assignment@v1
|
||||
# with:
|
||||
# token: ${{ secrets.LABEL_TOKEN }}
|
||||
# users: '["${{steps.merger.outputs.SRC_MERGER}}"]'
|
||||
- name: Notify the merger of previous commit
|
||||
uses: mshick/add-pr-comment@v2
|
||||
with:
|
||||
message: |
|
||||
@${{steps.merger.outputs.SRC_MERGER}} please review
|
||||
@@ -1,122 +0,0 @@
|
||||
name: <Native> Linter
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'templates/**'
|
||||
- 'native/**'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# Set the job key. The key is displayed as the job name
|
||||
# when a job name is not provided
|
||||
super-lint:
|
||||
# Name the Job
|
||||
name: ClangTidy Android
|
||||
# Set the type of machine to run on
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
# Checks out a copy of your repository on the ubuntu-latest machine
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Python3.8
|
||||
run: |
|
||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
||||
sudo apt update
|
||||
sudo apt remove python
|
||||
sudo apt install python3.8
|
||||
echo "python version: $(python --version)"
|
||||
echo "python path: $(which python)"
|
||||
|
||||
- name: Install libffi7 which clang-tidy-11 depends on
|
||||
run: |
|
||||
echo "install libffi7"
|
||||
wget http://ftp.ubuntu.com/ubuntu/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb
|
||||
sudo dpkg -i libffi7_3.3-5ubuntu1_amd64.deb
|
||||
|
||||
|
||||
- name: Install CMake & Clang Tidy
|
||||
run: |
|
||||
cd .github/workflows
|
||||
chmod +x ./llvm.sh
|
||||
sudo ./llvm.sh 11
|
||||
sudo apt update --fix-missing
|
||||
sudo apt install -y cmake llvm clang-tidy-11 ninja-build
|
||||
- name: Download external
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
with:
|
||||
ndk-version: r21e
|
||||
add-to-path: false
|
||||
local-cache: true
|
||||
- name: Get changed files
|
||||
uses: PatriceJiang/paths-filter@master
|
||||
id: listchanged
|
||||
with:
|
||||
list-files: shell
|
||||
filters: |
|
||||
source:
|
||||
- added|modified: '**/*.cpp'
|
||||
- added|modified: '**/*.h'
|
||||
- added|modified: '**/*.hpp'
|
||||
- added|modified: '**/*.m'
|
||||
- added|modified: '**/*.mm'
|
||||
- added|modified: '**/*.c'
|
||||
- exclude: 'native/cocos/editor-support/**'
|
||||
- exclude: 'native/cocos/base/etc1.*'
|
||||
- exclude: 'native/cocos/base/etc2.*'
|
||||
- exclude: 'native/cocos/bindings/manual/jsb_global.cpp'
|
||||
- exclude: 'native/cocos/bindings/manual/jsb_dragonbones_manual.cpp'
|
||||
- exclude: 'native/cocos/bindings/manual/jsb_spine_manual.cpp'
|
||||
- exclude: 'native/cocos/bindings/manual/jsb_socketio.cpp'
|
||||
- exclude: 'native/cocos/bindings/manual/jsb_conversions.*'
|
||||
- exclude: 'native/cocos/bindings/jswrapper/v8/debugger/**'
|
||||
- exclude: 'native/cocos/audio/android/audio_utils/**'
|
||||
- exclude: 'native/cocos/audio/android/AudioMixer.cpp'
|
||||
- exclude: 'native/cocos/audio/android/AudioResampler.cpp'
|
||||
- exclude: 'native/cocos/audio/common/utils/**'
|
||||
allChanges:
|
||||
- added|modified|deleted: '**'
|
||||
skipedDebug:
|
||||
- added|modified|deleted: '**'
|
||||
- exclude: 'native/cocos/editor-support/**'
|
||||
|
||||
- name: Generate Compile database
|
||||
shell: bash
|
||||
env:
|
||||
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
run: |
|
||||
cd native
|
||||
./utils/generate_compile_commands_android.sh
|
||||
ninja -C build -t targets |grep -E ".*jsb_.*auto.*" |awk -F": " '{print $1}' |xargs ninja -C build
|
||||
|
||||
- name: Generate clang-fix.yaml
|
||||
shell: bash
|
||||
if: ${{ steps.listchanged.outputs.source == 'true' }}
|
||||
run: |
|
||||
CPP="${{ steps.listchanged.outputs.source_files }}"
|
||||
FILTERED=`node .github/workflows/filter_by_cdb.js $CPP`
|
||||
if [[ "$FILTERED-xxx" == "-xxx" ]]; then
|
||||
echo "no source files match"
|
||||
else
|
||||
clang-tidy-11 --format-style=file --export-fixes=clang-fixes.yaml $FILTERED
|
||||
fi
|
||||
- name: clang-tidy-action
|
||||
uses: PatriceJiang/clang-tidy-action@master
|
||||
if: hashFiles('clang-fixes.yaml') != ''
|
||||
with:
|
||||
fixesFile: clang-fixes.yaml
|
||||
noFailOnIssue: false
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
error-limit: 200
|
||||
@@ -1,188 +0,0 @@
|
||||
name: Gen Simulator
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build_simulator_ts:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { spine: spine-3.8 }
|
||||
- { spine: spine-4.2 }
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
run: |
|
||||
EXT_VERSION=`node .github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- run: npm install
|
||||
|
||||
- name: Build Simulator TS files to JS
|
||||
run: |
|
||||
rm -rf bin
|
||||
mkdir bin
|
||||
cd .github/workflows
|
||||
node build-simulator-ts.js ${{ matrix.config.spine }}
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: native-preview-${{ matrix.config.spine }}
|
||||
path: bin
|
||||
|
||||
win_gen_simulator:
|
||||
runs-on: windows-2019
|
||||
name: Windows
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { spine: 3.8 }
|
||||
- { spine: 4.2 }
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: npm install
|
||||
run: |
|
||||
cd native
|
||||
npm install
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node .github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- name: Install deps
|
||||
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
|
||||
with:
|
||||
vulkan-query-version: 1.3.243.0
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader
|
||||
vulkan-use-cache: false
|
||||
- name: gen simulator
|
||||
shell: bash
|
||||
run: |
|
||||
cd native
|
||||
SPINE_VERSION=${{ matrix.config.spine }} npx gulp gen-simulator-release
|
||||
|
||||
- name: check result and make dist
|
||||
shell: bash
|
||||
run: |
|
||||
ls -l ./native/simulator/Release
|
||||
mkdir dist
|
||||
cp -r ./native/simulator/Release dist/
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: SimulatorApp-Win32-spine-${{ matrix.config.spine }}
|
||||
path: dist
|
||||
|
||||
mac_gen_simulator:
|
||||
runs-on: macos-latest
|
||||
name: MacOS
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { spine: 3.8 }
|
||||
- { spine: 4.2 }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: npm install
|
||||
run: |
|
||||
cd native
|
||||
npm install
|
||||
|
||||
- name: Download external libraries
|
||||
run: |
|
||||
EXT_VERSION=`node .github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- name: gen simulator
|
||||
run: |
|
||||
cd native
|
||||
SPINE_VERSION=${{ matrix.config.spine }} npx gulp gen-simulator-release
|
||||
|
||||
- name: check result and make dist
|
||||
run: |
|
||||
cd native
|
||||
ls -l ./simulator/Release
|
||||
rm -rf ./simulator/Release/*.a
|
||||
find ./ -name SimulatorApp-Mac
|
||||
echo "==> Show lipo info: "
|
||||
lipo -info simulator/Release/SimulatorApp-Mac.app/Contents/MacOS/SimulatorApp-Mac
|
||||
|
||||
cd ..
|
||||
mkdir dist
|
||||
cp -r ./native/simulator/Release dist/
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: SimulatorApp-Mac-spine-${{ matrix.config.spine }}
|
||||
path: dist
|
||||
|
||||
release_package:
|
||||
if: github.event_name == 'release'
|
||||
name: "Release packages"
|
||||
runs-on: macOS-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { spine: 3.8 }
|
||||
- { spine: 4.2 }
|
||||
permissions:
|
||||
contents: write
|
||||
needs: [build_simulator_ts, win_gen_simulator, mac_gen_simulator]
|
||||
steps:
|
||||
- name: Download native-preview-spine-${{ matrix.config.spine }}
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: native-preview-spine-${{ matrix.config.spine }}
|
||||
path: artifacts/native-preview-spine-${{ matrix.config.spine }}
|
||||
|
||||
- name: Download SimulatorApp-Win32-spine-${{ matrix.config.spine }}
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: SimulatorApp-Win32-spine-${{ matrix.config.spine }}
|
||||
path: artifacts/SimulatorApp-Win32-spine-${{ matrix.config.spine }}
|
||||
|
||||
- name: Download SimulatorApp-Mac-spine-${{ matrix.config.spine }}
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: SimulatorApp-Mac-spine-${{ matrix.config.spine }}
|
||||
path: artifacts/SimulatorApp-Mac-spine-${{ matrix.config.spine }}
|
||||
|
||||
- name: Show exe permission
|
||||
run: |
|
||||
echo "Before modify exe permission"
|
||||
ls -l artifacts/SimulatorApp-Mac-spine-${{ matrix.config.spine }}/Release/SimulatorApp-Mac.app/Contents/MacOS
|
||||
chmod +x artifacts/SimulatorApp-Mac-spine-${{ matrix.config.spine }}/Release/SimulatorApp-Mac.app/Contents/MacOS/SimulatorApp-Mac
|
||||
echo "After modify exe permission"
|
||||
ls -l artifacts/SimulatorApp-Mac-spine-${{ matrix.config.spine }}/Release/SimulatorApp-Mac.app/Contents/MacOS
|
||||
|
||||
- name: Pack dist files
|
||||
if: github.event_name == 'release'
|
||||
uses: thedoctor0/zip-release@main
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'artifacts'
|
||||
path: '.'
|
||||
filename: 'cocos-creator-simulator-${{ github.event.release.tag_name }}-spine-${{ matrix.config.spine }}.zip'
|
||||
|
||||
- name: Upload to Release
|
||||
if: github.event_name == 'release'
|
||||
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: artifacts/cocos-creator-simulator-${{ github.event.release.tag_name }}-spine-${{ matrix.config.spine }}.zip
|
||||
asset_name: cocos-creator-simulator-${{ github.event.release.tag_name }}-spine-${{ matrix.config.spine }}.zip
|
||||
tag: ${{ github.ref }}
|
||||
@@ -1,81 +0,0 @@
|
||||
name: <Native> Simulator
|
||||
|
||||
#on: [pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'native/**'
|
||||
- '.github\workflows\native-simulator.yml'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
win_gen_simulator:
|
||||
runs-on: windows-2022
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
name: Windows
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{github.workspace}}/native
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: npm install
|
||||
run: |
|
||||
npm install
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ../.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external
|
||||
|
||||
- name: Install deps
|
||||
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
|
||||
with:
|
||||
vulkan-query-version: 1.3.243.0
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader
|
||||
vulkan-use-cache: false
|
||||
- name: gen simulator
|
||||
run: |
|
||||
npx gulp gen-simulator
|
||||
- name: check result
|
||||
run: |
|
||||
Get-ChildItem ./simulator/Release -Name SimulatorApp-Win32.exe
|
||||
if(Test-Path ./simulator/Release/SimulatorApp-Win32.exe) {exit 0} else {exit 1}
|
||||
|
||||
mac_gen_simulator:
|
||||
runs-on: macos-latest
|
||||
name: MacOS
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { arch: x86_64 }
|
||||
- { arch: arm64 }
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{github.workspace}}/native
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: npm install
|
||||
run: |
|
||||
npm install
|
||||
npm install gulp -g
|
||||
- name: Download external libraries
|
||||
run: |
|
||||
EXT_VERSION=`node ../.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external
|
||||
|
||||
- name: gen simulator
|
||||
run: |
|
||||
ARCH=${{ matrix.config.arch }} npx gulp gen-simulator-release
|
||||
- name: check result
|
||||
run: |
|
||||
find ./ -name SimulatorApp-Mac
|
||||
echo "==> Show lipo info: "
|
||||
lipo -info simulator/Release/SimulatorApp-Mac.app/Contents/MacOS/SimulatorApp-Mac
|
||||
[ -f ./simulator/Release/SimulatorApp-Mac.app/Contents/MacOS/SimulatorApp-Mac ] && exit 0 || exit 1
|
||||
@@ -1,45 +0,0 @@
|
||||
name: <Native> Template Validation
|
||||
|
||||
#on: [pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'templates/common/**'
|
||||
- 'templates/android/**'
|
||||
- 'templates/windows/**'
|
||||
- 'templates/ios/**'
|
||||
- 'templates/mac/**'
|
||||
- 'templates/qnx/**'
|
||||
- 'templates/linux/**'
|
||||
- 'templates/ohos/**'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
compile_linux:
|
||||
name: "Linux-Ubuntu"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- id: files
|
||||
continue-on-error: true
|
||||
name: compatibility-info.json need update
|
||||
uses: jitterbit/get-changed-files@v1
|
||||
- run: |
|
||||
subfile="templates/compatibility-info.json"
|
||||
for changed_file in ${{ steps.files.outputs.all }}; do
|
||||
echo "Do something with this ${changed_file}."
|
||||
if [[ "$changed_file" =~ .*"$subfile" ]]; then
|
||||
echo "compatibility-info.json updated!"
|
||||
exit 0
|
||||
else
|
||||
echo "Test file $changed_file"
|
||||
fi
|
||||
done
|
||||
echo "native templates is modified, pls consider if 'templates/compatibility-info.json' needs to be updated."
|
||||
exit 1
|
||||
@@ -1,38 +0,0 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: <Native> build-native-ts
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci --ignore-scripts
|
||||
- run: node scripts/spread-pal.cjs
|
||||
- run: npm run build:debug-infos
|
||||
- name: Download external
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
- run: node ./scripts/compile-native-ts.js
|
||||
#- run: echo "::remove-matcher owner=circular-reference-check::"
|
||||
@@ -1,144 +0,0 @@
|
||||
name: <Native> Run Unit Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'templates/**'
|
||||
- 'native/**'
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
unit-test-with-cmake:
|
||||
name: "Run on macOS"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: macos-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{github.workspace}}/native
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: 3.28.3
|
||||
useLocalCache: false
|
||||
useCloudCache: false
|
||||
|
||||
- name: Check cmake version
|
||||
run: |
|
||||
echo "CMake version: "
|
||||
cmake --version
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ../.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external
|
||||
|
||||
- name: Run Unit Tests
|
||||
shell: bash
|
||||
run: |
|
||||
cpus=$(sysctl hw.ncpu | awk '{print $2}')
|
||||
echo "cpus: ${cpus}"
|
||||
which cmake
|
||||
cmake --version
|
||||
cmake -B tests/unit-test/build -S tests/unit-test -GXcode
|
||||
cd tests/unit-test/build
|
||||
# cmake --build tests/unit-test/build --config Release -j${cpus}
|
||||
ls -l
|
||||
xcodebuild -project CocosTest.xcodeproj -scheme "CocosTest" -jobs ${cpus} -arch arm64 -configuration Release build CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
|
||||
./src/Release/CocosTest
|
||||
|
||||
#### TODO(PatriceJiang): model split
|
||||
# - name: Run Module Tests
|
||||
# shell: bash
|
||||
# run: |
|
||||
# cd tests/module-tests
|
||||
# bash run-test-windows.sh
|
||||
sebind-with-windows:
|
||||
name: "sebind tests"
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{github.workspace}}/native
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
EXT_VERSION=`node ../.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external
|
||||
|
||||
- name: Generate bindings
|
||||
run: |
|
||||
cd ./tools/swig-config
|
||||
echo "Create auto-generated jsbinding glue codes."
|
||||
node genbindings.js
|
||||
git status
|
||||
- name: Run Sebind Tests
|
||||
shell: bash
|
||||
run: |
|
||||
cd ${GITHUB_WORKSPACE}/native
|
||||
cp -r ../templates/windows tests/sebind-tests/win64
|
||||
cd tests/sebind-tests
|
||||
mkdir -p proj
|
||||
cp cfg.cmake proj/
|
||||
GW="${GITHUB_WORKSPACE//\\/\/}"
|
||||
cmake -B proj -S win64 -DRES_DIR="${GW}/native/tests/sebind-tests" -DCOCOS_X_PATH="${GW}/native" -DAPP_NAME=sebind
|
||||
cmake --build proj -j2
|
||||
# cd proj/Debug
|
||||
## can not boot on this machine
|
||||
# ./sebind.exe || true
|
||||
# if [[ -f "result.txt" ]];
|
||||
# then
|
||||
# echo "success!"
|
||||
# else
|
||||
# echo "Run sebind-tests fail!"
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# sebind-run-on-linux:
|
||||
# name: "Test sebind on Ubuntu"
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Download external libraries
|
||||
# shell: bash
|
||||
# run: |
|
||||
# EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
# git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
# - name: Generate bindings
|
||||
# run: |
|
||||
# cd ./native/tools/swig-config
|
||||
# node genbindings.js
|
||||
# git status
|
||||
# - name: Install dependencies
|
||||
# run: |
|
||||
# sudo apt install libx11-dev -y
|
||||
# sudo apt install libsndio-dev -y
|
||||
# sudo apt install ninja-build -y
|
||||
# - name: Run Sebind Tests
|
||||
# shell: bash
|
||||
# run: |
|
||||
# cd ${GITHUB_WORKSPACE}/native
|
||||
# cp -r ../templates/linux tests/sebind-tests/linux
|
||||
# cd tests/sebind-tests
|
||||
# mkdir -p proj
|
||||
# cp cfg.cmake proj
|
||||
# cmake -G Ninja -B proj -S linux -DRES_DIR=${GITHUB_WORKSPACE}/native/tests/sebind-tests/ -DCOCOS_X_PATH=${GITHUB_WORKSPACE}/native -DAPP_NAME=sebind
|
||||
# cmake --build proj
|
||||
# cd proj
|
||||
# ./sebind || true
|
||||
# if [[ -f "result.txt" ]];
|
||||
# then
|
||||
# echo "success!"
|
||||
# else
|
||||
# echo "Run sebind-tests fail!" > /dev/stderr
|
||||
# fi
|
||||
@@ -1,177 +0,0 @@
|
||||
const fs = require('fs-extra');
|
||||
const ps = require('path');
|
||||
const { buildEngine, StatsQuery } = require('@cocos/ccbuild');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length == 0) {
|
||||
console.error('Please specify the engine root path');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const engineRoot = args[0];
|
||||
console.log(`Engine root: ${engineRoot}`);
|
||||
|
||||
const features2DCommon = [
|
||||
"2d",
|
||||
"affine-transform",
|
||||
"animation",
|
||||
"audio",
|
||||
"base",
|
||||
"dragon-bones",
|
||||
"gfx-webgl",
|
||||
"gfx-webgl2",
|
||||
"graphics",
|
||||
"intersection-2d",
|
||||
"mask",
|
||||
"particle-2d",
|
||||
"physics-2d-framework",
|
||||
"physics-2d-builtin",
|
||||
"physics-2d-box2d",
|
||||
"physics-2d-box2d-wasm",
|
||||
"profiler",
|
||||
"rich-text",
|
||||
"spine", // Old version uses 'spine' feature
|
||||
"spine-3.8", // New version uses 'spine-xxx' feature
|
||||
"tiled-map",
|
||||
"tween",
|
||||
"ui",
|
||||
"ui-skew",
|
||||
"video",
|
||||
"webview",
|
||||
];
|
||||
|
||||
const features2DEmptyLegacyPipeline = [
|
||||
"2d",
|
||||
"audio",
|
||||
"base",
|
||||
"gfx-webgl2",
|
||||
"legacy-pipeline",
|
||||
];
|
||||
|
||||
const features2DLegacyPipeline = [...features2DCommon, "legacy-pipeline"];
|
||||
const features2DNewPipeline = [...features2DCommon, "custom-pipeline", "custom-pipeline-builtin-scripts"];
|
||||
|
||||
console.log(`2d features: [ ${features2DLegacyPipeline.join(', ')} ]`);
|
||||
|
||||
async function buildEngineForFeatures(options) {
|
||||
console.log(`>>> ==============================================================`);
|
||||
console.log(`>>> ============== features: ${options.features.join(', ')}`);
|
||||
console.log(`>>> ============== outDir: ${options.outDir}`);
|
||||
const outDir = options.outDir;
|
||||
const ccbuildOptions = {
|
||||
engine: engineRoot,
|
||||
out: outDir,
|
||||
platform: options.platform,
|
||||
moduleFormat: "system",
|
||||
compress: true,
|
||||
split: false,
|
||||
nativeCodeBundleMode: options.nativeCodeBundleMode,
|
||||
assetURLFormat: "runtime-resolved",
|
||||
noDeprecatedFeatures: options.noDeprecatedFeatures,
|
||||
sourceMap: false,
|
||||
features: options.features,
|
||||
loose: true,
|
||||
mode: "BUILD",
|
||||
flags: {
|
||||
DEBUG: false,
|
||||
NET_MODE: 0,
|
||||
SERVER_MODE: false
|
||||
},
|
||||
wasmCompressionMode: options.wasmCompressionMode,
|
||||
inlineEnum: true,
|
||||
mangleProperties: {
|
||||
mangleList: [
|
||||
'UITransform._sortSiblings',
|
||||
'UITransform._cleanChangeMap',
|
||||
'Node._findComponents',
|
||||
'Node._findChildComponent',
|
||||
'Node._findChildComponents',
|
||||
'Node.idGenerator',
|
||||
'Node._stacks',
|
||||
'Node._stackId',
|
||||
'Node._setScene',
|
||||
'EffectAsset._layoutValid',
|
||||
'EffectAsset._effects',
|
||||
'ReflectionProbe.DEFAULT_CUBE_SIZE',
|
||||
'ReflectionProbe.DEFAULT_PLANER_SIZE',
|
||||
'WebGLDeviceManager.setInstance',
|
||||
'WebGL2DeviceManager.setInstance',
|
||||
'CanvasPool',
|
||||
],
|
||||
dontMangleList: [
|
||||
'Component',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
await fs.ensureDir(outDir);
|
||||
await fs.emptyDir(outDir);
|
||||
|
||||
await buildEngine(ccbuildOptions);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const statsQuery = await StatsQuery.create(engineRoot);
|
||||
|
||||
const excludeFeatures = [
|
||||
'vendor-google',
|
||||
'xr',
|
||||
'spine-3.8',
|
||||
'spine-4.2',
|
||||
];
|
||||
|
||||
const allFeatures = statsQuery.getFeatures().filter(feature => !excludeFeatures.includes(feature));
|
||||
console.log(`all features: [ ${allFeatures.join(', ')} ]`);
|
||||
const allFeaturesForWeChat = [...allFeatures, 'spine-3.8'];
|
||||
let allFeaturesForWeb = [...allFeatures, 'spine-4.2'];
|
||||
|
||||
if (!fs.pathExistsSync(ps.join(engineRoot, 'cocos', 'spine', 'lib', 'spine-version-4.2.ts'))) {
|
||||
console.log(`Doesn't found spine-version-4.2.ts`);
|
||||
allFeaturesForWeb = allFeaturesForWeChat;
|
||||
} else {
|
||||
console.log(`Found spine-version-4.2.ts`);
|
||||
}
|
||||
|
||||
await buildEngineForFeatures({
|
||||
features: allFeaturesForWeChat,
|
||||
outDir: ps.join(engineRoot, 'build-cc-out-all'),
|
||||
noDeprecatedFeatures: false,
|
||||
platform: "WECHAT",
|
||||
nativeCodeBundleMode: "wasm",
|
||||
// wasmCompressionMode: 'brotli',
|
||||
});
|
||||
|
||||
await buildEngineForFeatures({
|
||||
features: allFeaturesForWeb,
|
||||
outDir: ps.join(engineRoot, 'build-cc-out-all-web'),
|
||||
noDeprecatedFeatures: false,
|
||||
platform: "HTML5",
|
||||
});
|
||||
|
||||
await buildEngineForFeatures({
|
||||
features: features2DLegacyPipeline,
|
||||
outDir: ps.join(engineRoot, 'build-cc-out-2d-legacy-pipline'),
|
||||
noDeprecatedFeatures: true,
|
||||
platform: "WECHAT",
|
||||
nativeCodeBundleMode: "wasm",
|
||||
// wasmCompressionMode: 'brotli',
|
||||
});
|
||||
|
||||
await buildEngineForFeatures({
|
||||
features: features2DNewPipeline,
|
||||
outDir: ps.join(engineRoot, 'build-cc-out-2d-new-pipline'),
|
||||
noDeprecatedFeatures: true,
|
||||
platform: "WECHAT",
|
||||
nativeCodeBundleMode: "wasm",
|
||||
// wasmCompressionMode: 'brotli',
|
||||
});
|
||||
|
||||
await buildEngineForFeatures({
|
||||
features: features2DEmptyLegacyPipeline,
|
||||
outDir: ps.join(engineRoot, 'build-cc-out-2d-empty-legacy-pipline'),
|
||||
noDeprecatedFeatures: true,
|
||||
platform: "WECHAT",
|
||||
nativeCodeBundleMode: "wasm",
|
||||
// wasmCompressionMode: 'brotli',
|
||||
});
|
||||
})();
|
||||
@@ -1,674 +0,0 @@
|
||||
name: run test cases
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
issue_comment:
|
||||
types: [created, edited]
|
||||
|
||||
permissions: read-all
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
|
||||
|
||||
jobs:
|
||||
Win-RunTestCases:
|
||||
if: |
|
||||
contains(github.event.pull_request.body, '[X] needs automatic test cases check') ||
|
||||
contains(github.event.comment.body, '@cocos-robot run test cases')
|
||||
|
||||
runs-on: self-hosted-win
|
||||
|
||||
steps:
|
||||
- name: Get PR Details
|
||||
id: pr_details
|
||||
uses: octokit/request-action@v2.x
|
||||
with:
|
||||
route: GET /repos/cocos/cocos4/pulls/${{ env.PR_NUMBER }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Parse Pull Request
|
||||
id: parse_pr
|
||||
env:
|
||||
details: ${{ steps.pr_details.outputs.data }}
|
||||
last_update_date: ${{ github.event.comment.created_at || github.event.pull_request.updated_at }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
whoami
|
||||
pull_request=$(echo "$details" | jq -r '.')
|
||||
pr_html_url=$(echo "$pull_request" | jq -r '.html_url')
|
||||
pr_author=$(echo "$pull_request" | jq -r '.user.login')
|
||||
pr_head_ref=$(echo "$pull_request" | jq -r '.head.ref')
|
||||
pr_head_sha=$(echo "$pull_request" | jq -r '.head.sha')
|
||||
pr_base_ref=$(echo "$pull_request" | jq -r '.base.ref')
|
||||
pr_base_sha=$(echo "$pull_request" | jq -r '.base.sha')
|
||||
pr_updated_at=$(echo "$pull_request" | jq -r '.updated_at')
|
||||
# Print out the timestamps
|
||||
echo "PR Updated At Timestamp: $pr_updated_at"
|
||||
echo "Last Update Date Timestamp: $last_update_date"
|
||||
# Check if the PR has new updates
|
||||
if [[ $(date -d "$last_update_date" +%s) -gt $(date -d "$pr_updated_at" +%s) ]]; then
|
||||
# If there is an update, exit the script
|
||||
exit 101
|
||||
fi
|
||||
# If there are no new updates, write the PR details to the output file
|
||||
echo "pr_html_url=$pr_html_url" >> $GITHUB_OUTPUT
|
||||
echo "pr_author=$pr_author" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_ref=$pr_head_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_sha=$pr_head_sha" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_ref=$pr_base_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_sha=$pr_base_sha" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout engine
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
|
||||
- name: Checkout rebase
|
||||
env:
|
||||
BASE: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
HEAD: ${{ steps.parse_pr.outputs.pr_head_sha }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
echo "before whoami"
|
||||
whoami
|
||||
git fetch origin
|
||||
git reset --hard
|
||||
echo "Branch name required: $BASE"
|
||||
git checkout origin/$BASE
|
||||
git pull origin $BASE --allow-unrelated-histories
|
||||
git branch -D $BASE
|
||||
git branch $BASE
|
||||
echo "PR_NUMBER: $PR_NUMBER"
|
||||
git branch -D pull-$PR_NUMBER || true
|
||||
git fetch origin $HEAD:pull-$PR_NUMBER
|
||||
git merge --ff -s recursive --no-verify -m "PR Test" origin/$BASE pull-$PR_NUMBER
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
PRECLONE_EXTERNAL="E:/preclone/cocos-engine-external"
|
||||
if [ ! -d $PRECLONE_EXTERNAL ]; then
|
||||
mkdir -p $PRECLONE_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-engine-external $PRECLONE_EXTERNAL
|
||||
else
|
||||
echo "directory $PRECLONE_EXTERNAL is ready"
|
||||
fi
|
||||
if [ ! -d native/external ]; then
|
||||
mkdir native/external
|
||||
fi
|
||||
git -C $PRECLONE_EXTERNAL reset --hard
|
||||
git -C $PRECLONE_EXTERNAL fetch --all --prune
|
||||
git -C $PRECLONE_EXTERNAL archive --format=tar $EXT_VERSION | tar -C native/external -xf -
|
||||
|
||||
- name: Generate bindings
|
||||
run: |
|
||||
cd ./native/tools/swig-config
|
||||
echo "Create auto-generated jsbinding glue codes."
|
||||
node genbindings.js &&
|
||||
git status
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
npm -v
|
||||
npm install --registry https://registry.npmmirror.com
|
||||
|
||||
- name: Checkout test-projects
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
TEST_PROJECTS_EXTERNAL="E:/pr-test/cocos-test-projects"
|
||||
CCTEST_PLUGINS="E:/pr-test/TestPlugin"
|
||||
if [ ! -d $TEST_PROJECTS_EXTERNAL ]; then
|
||||
mkdir -p $TEST_PROJECTS_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-test-projects.git $TEST_PROJECTS_EXTERNAL
|
||||
else
|
||||
echo "directory $TEST_PROJECTS_EXTERNAL is ready"
|
||||
fi
|
||||
git -C $TEST_PROJECTS_EXTERNAL reset --hard
|
||||
git -C $TEST_PROJECTS_EXTERNAL fetch --all --prune
|
||||
git -C $TEST_PROJECTS_EXTERNAL checkout origin/${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
git -C $TEST_PROJECTS_EXTERNAL pull origin ${{ steps.parse_pr.outputs.pr_base_ref }} --allow-unrelated-histories
|
||||
rm -rf $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
7z x -y $CCTEST_PLUGINS/*.zip -o$TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
|
||||
- name: Run test cases
|
||||
timeout-minutes: 100
|
||||
id: run_test_cases
|
||||
run: |
|
||||
scheduler cicd -p PR-TEST -v ${{ steps.parse_pr.outputs.pr_base_ref }} -g PR-TEST -i "1,3,5" -d E:\cctest\devices.json -r https://cctest.cocos.org
|
||||
$JOBID = Get-Content C:\Users\Administrator\AppData\Roaming\npm\node_modules\@cctest\scheduler\logs\PR-TEST\nowJobId.log
|
||||
cd ..
|
||||
pwd
|
||||
python3 -u ./python/main.py --target=job_editor --jobid=$JOBID
|
||||
|
||||
- name: Write comment body and issue number to file
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PR_AUTHOR: ${{ steps.parse_pr.outputs.pr_author }}
|
||||
EDITOR_VERSION: ${{ steps.run_test_cases.outputs.editor }}
|
||||
TASK_STATUS: ${{ steps.run_test_cases.outputs.status }}
|
||||
TASK_REPORT: ${{ steps.run_test_cases.outputs.report }}
|
||||
JOB_ID: ${{ steps.run_test_cases.outputs.jobid }}
|
||||
GITHUB_RUN_ID: ${{ github.run_id }}
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('commentwin.txt', `@${process.env.PR_AUTHOR}, Please check the result of \`run test cases\`:
|
||||
- Test Platform: PR-Test
|
||||
- Editor Version: ${process.env.EDITOR_VERSION}
|
||||
- Task Result: ${process.env.TASK_STATUS}
|
||||
- Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/${process.env.JOB_ID}/-1
|
||||
- GitHub Action: https://github.com/cocos/cocos4/actions/runs/${process.env.GITHUB_RUN_ID}
|
||||
## Task Details
|
||||
${process.env.TASK_REPORT}`);
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: commentwin.txt
|
||||
path: |
|
||||
commentwin.txt
|
||||
|
||||
macOS-RunTestCases:
|
||||
if: |
|
||||
contains(github.event.pull_request.body, '[X] needs automatic test cases check') ||
|
||||
contains(github.event.comment.body, '@cocos-robot run test cases')
|
||||
runs-on: self-hosted-mac
|
||||
|
||||
steps:
|
||||
- name: Get PR Details
|
||||
id: pr_details
|
||||
uses: octokit/request-action@v2.x
|
||||
with:
|
||||
route: GET /repos/cocos/cocos4/pulls/${{ env.PR_NUMBER }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Parse Pull Request
|
||||
id: parse_pr
|
||||
env:
|
||||
details: ${{ steps.pr_details.outputs.data }}
|
||||
last_update_date: ${{ github.event.comment.created_at || github.event.pull_request.updated_at }}
|
||||
run: |
|
||||
set -x
|
||||
pull_request=$(echo "$details" | jq -r '.')
|
||||
pr_html_url=$(echo "$pull_request" | jq -r '.html_url')
|
||||
pr_author=$(echo "$pull_request" | jq -r '.user.login')
|
||||
pr_head_ref=$(echo "$pull_request" | jq -r '.head.ref')
|
||||
pr_head_sha=$(echo "$pull_request" | jq -r '.head.sha')
|
||||
pr_base_ref=$(echo "$pull_request" | jq -r '.base.ref')
|
||||
pr_base_sha=$(echo "$pull_request" | jq -r '.base.sha')
|
||||
pr_updated_at=$(echo "$pull_request" | jq -r '.updated_at')
|
||||
# Print out the timestamps
|
||||
echo "PR Updated At Timestamp: $pr_updated_at"
|
||||
echo "Last Update Date Timestamp: $last_update_date"
|
||||
# Check if the PR has new updates
|
||||
if [[ $(gdate -d "$last_update_date" +%s) -gt $(gdate -d "$pr_updated_at" +%s) ]]; then
|
||||
# If there is an update, exit the script
|
||||
exit 101
|
||||
fi
|
||||
# If there are no new updates, write the PR details to the output file
|
||||
echo "pr_html_url=$pr_html_url" >> $GITHUB_OUTPUT
|
||||
echo "pr_author=$pr_author" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_ref=$pr_head_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_sha=$pr_head_sha" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_ref=$pr_base_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_sha=$pr_base_sha" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout engine
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
|
||||
- name: Checkout rebase
|
||||
env:
|
||||
BASE: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
HEAD: ${{ steps.parse_pr.outputs.pr_head_sha }}
|
||||
run: |
|
||||
git fetch origin
|
||||
git reset --hard
|
||||
git checkout origin/$BASE
|
||||
git pull origin $BASE --allow-unrelated-histories
|
||||
git branch -D $BASE
|
||||
git branch $BASE
|
||||
git branch -D pull-$PR_NUMBER || true
|
||||
git fetch origin $HEAD:pull-$PR_NUMBER
|
||||
git merge --ff -s recursive --no-verify -m "PR Test" origin/$BASE pull-$PR_NUMBER
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
PRECLONE_EXTERNAL="/Users/admin/Documents/actions-runner/preclone/cocos-engine-external"
|
||||
if [ ! -d $PRECLONE_EXTERNAL ]; then
|
||||
echo "create directory $PRECLONE_EXTERNAL"
|
||||
# remove all sub-folders
|
||||
rm -rf /Users/admin/Documents/actions-runner/preclone
|
||||
mkdir -p $PRECLONE_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-engine-external $PRECLONE_EXTERNAL
|
||||
else
|
||||
echo "directory $PRECLONE_EXTERNAL is ready"
|
||||
fi
|
||||
if [ ! -d native/external ]; then
|
||||
mkdir native/external
|
||||
fi
|
||||
git -C $PRECLONE_EXTERNAL reset --hard
|
||||
git -C $PRECLONE_EXTERNAL fetch --all --prune
|
||||
git -C $PRECLONE_EXTERNAL archive --format=tar $EXT_VERSION | tar -C native/external -xf -
|
||||
|
||||
- name: Generate bindings
|
||||
run: |
|
||||
cd ./native/tools/swig-config
|
||||
echo "Create auto-generated jsbinding glue codes."
|
||||
node genbindings.js &&
|
||||
git status
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
npm -v
|
||||
npm install --registry https://registry.npmmirror.com
|
||||
|
||||
- name: Checkout test-projects
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
TEST_PROJECTS_EXTERNAL="../../cocos-test-projects"
|
||||
CCTEST_PLUGINS="../../TestPlugin"
|
||||
if [ ! -d $TEST_PROJECTS_EXTERNAL ]; then
|
||||
mkdir -p $TEST_PROJECTS_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-test-projects.git $TEST_PROJECTS_EXTERNAL
|
||||
else
|
||||
echo "directory $TEST_PROJECTS_EXTERNAL is ready"
|
||||
fi
|
||||
git -C $TEST_PROJECTS_EXTERNAL reset --hard
|
||||
git -C $TEST_PROJECTS_EXTERNAL fetch --all --prune
|
||||
git -C $TEST_PROJECTS_EXTERNAL checkout origin/${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
git -C $TEST_PROJECTS_EXTERNAL pull origin ${{ steps.parse_pr.outputs.pr_base_ref }} --allow-unrelated-histories
|
||||
rm -rf $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
unzip -oq $CCTEST_PLUGINS/*.zip -d $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
|
||||
- name: Run test cases
|
||||
timeout-minutes: 100
|
||||
id: run_test_cases
|
||||
run: |
|
||||
scheduler cicd -p PR-TEST -v ${{ steps.parse_pr.outputs.pr_base_ref }} -g PR-TEST -i 0,2,4 -d /Users/admin/Documents/cctest/devices.json -r https://cctest.cocos.org
|
||||
JOBID=`cat /usr/local/lib/node_modules/@cctest/scheduler/logs/PR-TEST/nowJobId.log`
|
||||
cd ..
|
||||
python3 -u ./python/main.py --target=job_editor --jobid=$JOBID
|
||||
|
||||
- name: Write comment body and issue number to file
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PR_AUTHOR: ${{ steps.parse_pr.outputs.pr_author }}
|
||||
EDITOR_VERSION: ${{ steps.run_test_cases.outputs.editor }}
|
||||
TASK_STATUS: ${{ steps.run_test_cases.outputs.status }}
|
||||
TASK_REPORT: ${{ steps.run_test_cases.outputs.report }}
|
||||
JOB_ID: ${{ steps.run_test_cases.outputs.jobid }}
|
||||
GITHUB_RUN_ID: ${{ github.run_id }}
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('pr.txt', process.env.PR_NUMBER);
|
||||
fs.writeFileSync('comment.txt', `@${process.env.PR_AUTHOR}, Please check the result of \`run test cases\`:
|
||||
- Test Platform: PR-Test
|
||||
- Editor Version: ${process.env.EDITOR_VERSION}
|
||||
- Task Result: ${process.env.TASK_STATUS}
|
||||
- Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/${process.env.JOB_ID}/-1
|
||||
- GitHub Action: https://github.com/cocos/cocos4/actions/runs/${process.env.GITHUB_RUN_ID}
|
||||
## Task Details
|
||||
${process.env.TASK_REPORT}`);
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pr.txt
|
||||
path: |
|
||||
pr.txt
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: comment.txt
|
||||
path: |
|
||||
comment.txt
|
||||
|
||||
|
||||
Win-RunTestCasesCustom:
|
||||
if: |
|
||||
contains(github.event.comment.body, '@cocos-robot run-test-cases-custom')
|
||||
|
||||
runs-on: self-hosted-win
|
||||
|
||||
steps:
|
||||
- name: Get PR Details
|
||||
id: pr_details
|
||||
uses: octokit/request-action@v2.x
|
||||
with:
|
||||
route: GET /repos/cocos/cocos4/pulls/${{ env.PR_NUMBER }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Parse Pull Request
|
||||
id: parse_pr
|
||||
env:
|
||||
details: ${{ steps.pr_details.outputs.data }}
|
||||
last_update_date: ${{ github.event.comment.created_at || github.event.pull_request.updated_at }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
whoami
|
||||
pull_request=$(echo "$details" | jq -r '.')
|
||||
pr_html_url=$(echo "$pull_request" | jq -r '.html_url')
|
||||
pr_author=$(echo "$pull_request" | jq -r '.user.login')
|
||||
pr_head_ref=$(echo "$pull_request" | jq -r '.head.ref')
|
||||
pr_head_sha=$(echo "$pull_request" | jq -r '.head.sha')
|
||||
pr_base_ref=$(echo "$pull_request" | jq -r '.base.ref')
|
||||
pr_base_sha=$(echo "$pull_request" | jq -r '.base.sha')
|
||||
pr_updated_at=$(echo "$pull_request" | jq -r '.updated_at')
|
||||
# Print out the timestamps
|
||||
echo "PR Updated At Timestamp: $pr_updated_at"
|
||||
echo "Last Update Date Timestamp: $last_update_date"
|
||||
# Check if the PR has new updates
|
||||
if [[ $(date -d "$last_update_date" +%s) -gt $(date -d "$pr_updated_at" +%s) ]]; then
|
||||
# If there is an update, exit the script
|
||||
exit 101
|
||||
fi
|
||||
# If there are no new updates, write the PR details to the output file
|
||||
echo "pr_html_url=$pr_html_url" >> $GITHUB_OUTPUT
|
||||
echo "pr_author=$pr_author" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_ref=$pr_head_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_sha=$pr_head_sha" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_ref=$pr_base_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_sha=$pr_base_sha" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout engine
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
|
||||
- name: Checkout rebase
|
||||
env:
|
||||
BASE: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
HEAD: ${{ steps.parse_pr.outputs.pr_head_sha }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
echo "before whoami"
|
||||
whoami
|
||||
git fetch origin
|
||||
git reset --hard
|
||||
echo "Branch name required: $BASE"
|
||||
git checkout origin/$BASE
|
||||
git pull origin $BASE --allow-unrelated-histories
|
||||
git branch -D $BASE
|
||||
git branch $BASE
|
||||
echo "PR_NUMBER: $PR_NUMBER"
|
||||
git branch -D pull-$PR_NUMBER || true
|
||||
git fetch origin $HEAD:pull-$PR_NUMBER
|
||||
git merge --ff -s recursive --no-verify -m "PR Test" origin/$BASE pull-$PR_NUMBER
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
PRECLONE_EXTERNAL="E:/preclone/cocos-engine-external"
|
||||
if [ ! -d $PRECLONE_EXTERNAL ]; then
|
||||
mkdir -p $PRECLONE_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-engine-external $PRECLONE_EXTERNAL
|
||||
else
|
||||
echo "directory $PRECLONE_EXTERNAL is ready"
|
||||
fi
|
||||
if [ ! -d native/external ]; then
|
||||
mkdir native/external
|
||||
fi
|
||||
git -C $PRECLONE_EXTERNAL reset --hard
|
||||
git -C $PRECLONE_EXTERNAL fetch --all --prune
|
||||
git -C $PRECLONE_EXTERNAL archive --format=tar $EXT_VERSION | tar -C native/external -xf -
|
||||
|
||||
- name: Generate bindings
|
||||
run: |
|
||||
cd ./native/tools/swig-config
|
||||
echo "Create auto-generated jsbinding glue codes."
|
||||
node genbindings.js &&
|
||||
git status
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
npm -v
|
||||
npm install --registry https://registry.npmmirror.com
|
||||
|
||||
- name: Checkout test-projects
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
TEST_PROJECTS_EXTERNAL="E:/pr-test/cocos-test-projects"
|
||||
CCTEST_PLUGINS="E:/pr-test/TestPlugin"
|
||||
if [ ! -d $TEST_PROJECTS_EXTERNAL ]; then
|
||||
mkdir -p $TEST_PROJECTS_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-test-projects.git $TEST_PROJECTS_EXTERNAL
|
||||
else
|
||||
echo "directory $TEST_PROJECTS_EXTERNAL is ready"
|
||||
fi
|
||||
git -C $TEST_PROJECTS_EXTERNAL reset --hard
|
||||
git -C $TEST_PROJECTS_EXTERNAL fetch --all --prune
|
||||
git -C $TEST_PROJECTS_EXTERNAL checkout origin/${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
git -C $TEST_PROJECTS_EXTERNAL pull origin ${{ steps.parse_pr.outputs.pr_base_ref }} --allow-unrelated-histories
|
||||
rm -rf $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
7z x -y $CCTEST_PLUGINS/*.zip -o$TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
|
||||
- name: Run test cases
|
||||
timeout-minutes: 100
|
||||
id: run_test_cases
|
||||
run: |
|
||||
scheduler cicd -p PR-TEST-DEFERRED -v ${{ steps.parse_pr.outputs.pr_base_ref }} -g PR-TEST -i "1,3,5" -d E:\cctest\devices.json -r https://cctest.cocos.org
|
||||
$JOBID = Get-Content C:\Users\Administrator\AppData\Roaming\npm\node_modules\@cctest\scheduler\logs\PR-TEST\nowJobId.log
|
||||
cd ..
|
||||
pwd
|
||||
python3 -u ./python/main.py --target=job_editor --jobid=$JOBID
|
||||
|
||||
- name: Write comment body and issue number to file
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PR_AUTHOR: ${{ steps.parse_pr.outputs.pr_author }}
|
||||
EDITOR_VERSION: ${{ steps.run_test_cases.outputs.editor }}
|
||||
TASK_STATUS: ${{ steps.run_test_cases.outputs.status }}
|
||||
TASK_REPORT: ${{ steps.run_test_cases.outputs.report }}
|
||||
JOB_ID: ${{ steps.run_test_cases.outputs.jobid }}
|
||||
GITHUB_RUN_ID: ${{ github.run_id }}
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('commentwin.txt', `@${process.env.PR_AUTHOR}, Please check the result of \`run test cases\`:
|
||||
- Test Platform: PR-Test
|
||||
- Editor Version: ${process.env.EDITOR_VERSION}
|
||||
- Task Result: ${process.env.TASK_STATUS}
|
||||
- Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/${process.env.JOB_ID}/-1
|
||||
- GitHub Action: https://github.com/cocos/cocos4/actions/runs/${process.env.GITHUB_RUN_ID}
|
||||
## Task Details
|
||||
${process.env.TASK_REPORT}`);
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: commentwin.txt
|
||||
path: |
|
||||
commentwin.txt
|
||||
|
||||
macOS-RunTestCasesCustom:
|
||||
if: |
|
||||
contains(github.event.comment.body, '@cocos-robot run-test-cases-custom')
|
||||
runs-on: self-hosted-mac
|
||||
|
||||
steps:
|
||||
- name: Get PR Details
|
||||
id: pr_details
|
||||
uses: octokit/request-action@v2.x
|
||||
with:
|
||||
route: GET /repos/cocos/cocos4/pulls/${{ env.PR_NUMBER }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Parse Pull Request
|
||||
id: parse_pr
|
||||
env:
|
||||
details: ${{ steps.pr_details.outputs.data }}
|
||||
last_update_date: ${{ github.event.comment.created_at || github.event.pull_request.updated_at }}
|
||||
run: |
|
||||
set -x
|
||||
pull_request=$(echo "$details" | jq -r '.')
|
||||
pr_html_url=$(echo "$pull_request" | jq -r '.html_url')
|
||||
pr_author=$(echo "$pull_request" | jq -r '.user.login')
|
||||
pr_head_ref=$(echo "$pull_request" | jq -r '.head.ref')
|
||||
pr_head_sha=$(echo "$pull_request" | jq -r '.head.sha')
|
||||
pr_base_ref=$(echo "$pull_request" | jq -r '.base.ref')
|
||||
pr_base_sha=$(echo "$pull_request" | jq -r '.base.sha')
|
||||
pr_updated_at=$(echo "$pull_request" | jq -r '.updated_at')
|
||||
# Print out the timestamps
|
||||
echo "PR Updated At Timestamp: $pr_updated_at"
|
||||
echo "Last Update Date Timestamp: $last_update_date"
|
||||
# Check if the PR has new updates
|
||||
if [[ $(gdate -d "$last_update_date" +%s) -gt $(gdate -d "$pr_updated_at" +%s) ]]; then
|
||||
# If there is an update, exit the script
|
||||
exit 101
|
||||
fi
|
||||
# If there are no new updates, write the PR details to the output file
|
||||
echo "pr_html_url=$pr_html_url" >> $GITHUB_OUTPUT
|
||||
echo "pr_author=$pr_author" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_ref=$pr_head_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_head_sha=$pr_head_sha" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_ref=$pr_base_ref" >> $GITHUB_OUTPUT
|
||||
echo "pr_base_sha=$pr_base_sha" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout engine
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
|
||||
- name: Checkout rebase
|
||||
env:
|
||||
BASE: ${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
HEAD: ${{ steps.parse_pr.outputs.pr_head_sha }}
|
||||
run: |
|
||||
git fetch origin
|
||||
git reset --hard
|
||||
git checkout origin/$BASE
|
||||
git pull origin $BASE --allow-unrelated-histories
|
||||
git branch -D $BASE
|
||||
git branch $BASE
|
||||
git branch -D pull-$PR_NUMBER || true
|
||||
git fetch origin $HEAD:pull-$PR_NUMBER
|
||||
git merge --ff -s recursive --no-verify -m "PR Test" origin/$BASE pull-$PR_NUMBER
|
||||
|
||||
- name: Download external libraries
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
PRECLONE_EXTERNAL="/Users/admin/Documents/actions-runner/preclone/cocos-engine-external"
|
||||
if [ ! -d $PRECLONE_EXTERNAL ]; then
|
||||
echo "create directory $PRECLONE_EXTERNAL"
|
||||
# remove all sub-folders
|
||||
rm -rf /Users/admin/Documents/actions-runner/preclone
|
||||
mkdir -p $PRECLONE_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-engine-external $PRECLONE_EXTERNAL
|
||||
else
|
||||
echo "directory $PRECLONE_EXTERNAL is ready"
|
||||
fi
|
||||
if [ ! -d native/external ]; then
|
||||
mkdir native/external
|
||||
fi
|
||||
git -C $PRECLONE_EXTERNAL reset --hard
|
||||
git -C $PRECLONE_EXTERNAL fetch --all --prune
|
||||
git -C $PRECLONE_EXTERNAL archive --format=tar $EXT_VERSION | tar -C native/external -xf -
|
||||
|
||||
- name: Generate bindings
|
||||
run: |
|
||||
cd ./native/tools/swig-config
|
||||
echo "Create auto-generated jsbinding glue codes."
|
||||
node genbindings.js &&
|
||||
git status
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
npm -v
|
||||
npm install --registry https://registry.npmmirror.com
|
||||
|
||||
- name: Checkout test-projects
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
TEST_PROJECTS_EXTERNAL="../../cocos-test-projects"
|
||||
CCTEST_PLUGINS="../../TestPlugin"
|
||||
if [ ! -d $TEST_PROJECTS_EXTERNAL ]; then
|
||||
mkdir -p $TEST_PROJECTS_EXTERNAL
|
||||
git clone https://github.com/cocos/cocos-test-projects.git $TEST_PROJECTS_EXTERNAL
|
||||
else
|
||||
echo "directory $TEST_PROJECTS_EXTERNAL is ready"
|
||||
fi
|
||||
git -C $TEST_PROJECTS_EXTERNAL reset --hard
|
||||
git -C $TEST_PROJECTS_EXTERNAL fetch --all --prune
|
||||
git -C $TEST_PROJECTS_EXTERNAL checkout origin/${{ steps.parse_pr.outputs.pr_base_ref }}
|
||||
git -C $TEST_PROJECTS_EXTERNAL pull origin ${{ steps.parse_pr.outputs.pr_base_ref }} --allow-unrelated-histories
|
||||
rm -rf $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
unzip -oq $CCTEST_PLUGINS/*.zip -d $TEST_PROJECTS_EXTERNAL/extensions/automation-framework
|
||||
|
||||
- name: Run test cases
|
||||
timeout-minutes: 100
|
||||
id: run_test_cases
|
||||
run: |
|
||||
scheduler cicd -p PR-TEST-DEFERRED -v ${{ steps.parse_pr.outputs.pr_base_ref }} -g PR-TEST -i 0,2,4 -d /Users/admin/Documents/cctest/devices.json -r https://cctest.cocos.org
|
||||
JOBID=`cat /usr/local/lib/node_modules/@cctest/scheduler/logs/PR-TEST/nowJobId.log`
|
||||
cd ..
|
||||
python3 -u ./python/main.py --target=job_editor --jobid=$JOBID
|
||||
|
||||
- name: Write comment body and issue number to file
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PR_AUTHOR: ${{ steps.parse_pr.outputs.pr_author }}
|
||||
EDITOR_VERSION: ${{ steps.run_test_cases.outputs.editor }}
|
||||
TASK_STATUS: ${{ steps.run_test_cases.outputs.status }}
|
||||
TASK_REPORT: ${{ steps.run_test_cases.outputs.report }}
|
||||
JOB_ID: ${{ steps.run_test_cases.outputs.jobid }}
|
||||
GITHUB_RUN_ID: ${{ github.run_id }}
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('pr.txt', process.env.PR_NUMBER);
|
||||
fs.writeFileSync('comment.txt', `@${process.env.PR_AUTHOR}, Please check the result of \`run test cases\`:
|
||||
- Test Platform: PR-Test
|
||||
- Editor Version: ${process.env.EDITOR_VERSION}
|
||||
- Task Result: ${process.env.TASK_STATUS}
|
||||
- Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/${process.env.JOB_ID}/-1
|
||||
- GitHub Action: https://github.com/cocos/cocos4/actions/runs/${process.env.GITHUB_RUN_ID}
|
||||
## Task Details
|
||||
${process.env.TASK_REPORT}`);
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pr.txt
|
||||
path: |
|
||||
pr.txt
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: comment.txt
|
||||
path: |
|
||||
comment.txt
|
||||
@@ -1,48 +0,0 @@
|
||||
name: run test cases PR comment
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["run test cases"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
post-pr-comment:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
run-id: ${{ github.event.workflow_run.id }}
|
||||
merge-multiple: true
|
||||
path: ./artifacts
|
||||
|
||||
- name: Display structure of downloaded files
|
||||
run: |
|
||||
ls -R ./artifacts
|
||||
|
||||
- name: Set PR environment variable
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const pr = Number(fs.readFileSync('./artifacts/pr.txt', 'utf8'));
|
||||
core.exportVariable('PR_NUMBER', pr);
|
||||
|
||||
- name: Update Mac Comment
|
||||
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
|
||||
with:
|
||||
issue-number: ${{ env.PR_NUMBER }}
|
||||
body-path: './artifacts/comment.txt'
|
||||
|
||||
- name: Update Win Comment
|
||||
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
|
||||
with:
|
||||
issue-number: ${{ env.PR_NUMBER }}
|
||||
body-path: './artifacts/commentwin.txt'
|
||||
@@ -1,39 +0,0 @@
|
||||
name: <Web> Check version
|
||||
|
||||
#on: push
|
||||
on: [create, pull_request]
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
Check_package_version:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions: read-all
|
||||
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
node -v
|
||||
npm install || exit 0
|
||||
|
||||
- name: check version pull_request
|
||||
if: github.event_name == 'pull_request'
|
||||
run: |
|
||||
branch=`echo ${{ github.base_ref }} | awk -F'/' '{print $NF}'`
|
||||
echo "Branch: ${branch}"
|
||||
npm run verify:engine-version -- ${branch}
|
||||
|
||||
- name: check version create
|
||||
if: github.event_name == 'create'
|
||||
run: |
|
||||
branch=`echo ${{ github.ref }} | awk -F'/' '{print $NF}'`
|
||||
echo "Branch: ${branch}"
|
||||
npm run verify:engine-version -- ${branch}
|
||||
@@ -1,427 +0,0 @@
|
||||
name: <Web> Interface check
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
|
||||
jobs:
|
||||
dts-and-size:
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
SPINE_WASM_UP_TO_DATE_BASE: ${{ steps.check-wasm-up-to-date-base.outputs.SPINE_WASM_UP_TO_DATE_BASE }}
|
||||
SPINE_WASM_UP_TO_DATE_HEAD: ${{ steps.check-wasm-up-to-date-head.outputs.SPINE_WASM_UP_TO_DATE_HEAD }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { target: base }
|
||||
- { target: head }
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 3.1.41
|
||||
|
||||
- name: Verify
|
||||
run: |
|
||||
which emcc
|
||||
emcc -v
|
||||
|
||||
- name: Install ninja
|
||||
run: |
|
||||
if ! command -v ninja &> /dev/null; then
|
||||
echo "Ninja not found, installing..."
|
||||
# sudo apt update
|
||||
sudo apt install ninja-build
|
||||
else
|
||||
echo "Ninja is already installed."
|
||||
fi
|
||||
which ninja
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout Base Ref
|
||||
if: ${{ matrix.config.target == 'base' }}
|
||||
with:
|
||||
repository: ${{ github.event.pull_request.base.repo.full_name }}
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout Head Ref for using the latest .github/workflows for base
|
||||
if: ${{ matrix.config.target == 'base' }}
|
||||
with:
|
||||
path: './engine-HEAD'
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout Head Ref
|
||||
if: ${{ matrix.config.target == 'head' }}
|
||||
|
||||
- name: Show Refs
|
||||
run: |
|
||||
echo "Commit log:"
|
||||
git --no-pager log -3
|
||||
echo "git status"
|
||||
git status
|
||||
|
||||
- name: Apply emscripten patches (base)
|
||||
if: ${{ matrix.config.target == 'base' }}
|
||||
run: |
|
||||
ls -l $EMSDK/upstream/emscripten/
|
||||
echo "--------------------------------- Save bind.cpp ---------------------------------"
|
||||
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
|
||||
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
|
||||
cp -f ./engine-HEAD/.github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
|
||||
echo "--------------------------------- Apply patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
|
||||
- name: Apply emscripten patches (head)
|
||||
if: ${{ matrix.config.target == 'head' }}
|
||||
run: |
|
||||
ls -l $EMSDK/upstream/emscripten/
|
||||
echo "--------------------------------- Save bind.cpp ---------------------------------"
|
||||
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
|
||||
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
|
||||
cp -f .github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
|
||||
echo "--------------------------------- Apply patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
|
||||
- run: |
|
||||
echo "EXT_VERSION=$(node .github/workflows/get-native-external-version.js)" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
name: Download external
|
||||
with:
|
||||
repository: cocos/cocos-engine-external
|
||||
path: './native/external'
|
||||
ref: "${{ env.EXT_VERSION }}"
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Build Spine 3.8 WASM
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
|
||||
sed -i 's/set(SPINE_VERSION "4.2")/set(SPINE_VERSION "3.8")/g' CMakeLists.txt
|
||||
cat CMakeLists.txt
|
||||
rm -rf build-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 3.8 ASMJS
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
sed -i 's/set(SPINE_VERSION "4.2")/set(SPINE_VERSION "3.8")/g' CMakeLists.txt
|
||||
cat CMakeLists.txt
|
||||
rm -rf build-asmjs
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 3.8 files to external directory
|
||||
run: |
|
||||
SPINE_VERSION="3.8"
|
||||
DIST_PATH="dist-${{ matrix.config.target }}/3.8"
|
||||
mkdir -p $DIST_PATH
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
mkdir -p ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-----------------------------------------------"
|
||||
cd ./native/external
|
||||
git status
|
||||
|
||||
- name: Build Spine 4.2 WASM
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
cat CMakeLists.txt
|
||||
git status
|
||||
rm -rf build-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 4.2 ASMJS
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
cat CMakeLists.txt
|
||||
git status
|
||||
rm -rf build-asmjs
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 4.2 files to external directory
|
||||
run: |
|
||||
DIST_PATH="dist-${{ matrix.config.target }}/4.2"
|
||||
mkdir -p $DIST_PATH
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
mkdir -p ./native/external/emscripten/spine/4.2/
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
ls -l ./native/external/emscripten/spine/4.2/
|
||||
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/4.2/
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l ./native/external/emscripten/spine/4.2/
|
||||
echo "-----------------------------------------------"
|
||||
cd ./native/external
|
||||
git status
|
||||
|
||||
- name: Check if spine wasm files are up-to-date (base)
|
||||
id: check-wasm-up-to-date-base
|
||||
if: ${{ matrix.config.target == 'base' }}
|
||||
run: |
|
||||
cd ./native/external
|
||||
diff_output=$(git diff)
|
||||
if [ -n "$diff_output" ]; then
|
||||
echo "SPINE_WASM_UP_TO_DATE_BASE=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "SPINE_WASM_UP_TO_DATE_BASE=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Check if spine wasm files are up-to-date (head)
|
||||
id: check-wasm-up-to-date-head
|
||||
if: ${{ matrix.config.target == 'head' }}
|
||||
run: |
|
||||
cd ./native/external
|
||||
diff_output=$(git diff)
|
||||
if [ -n "$diff_output" ]; then
|
||||
echo "SPINE_WASM_UP_TO_DATE_HEAD=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "SPINE_WASM_UP_TO_DATE_HEAD=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Upload Spine Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: spine-emscripten-${{ matrix.config.target }}
|
||||
path: dist-${{ matrix.config.target }}
|
||||
|
||||
- name: Build Declarations (base)
|
||||
if: ${{ matrix.config.target == 'base' }}
|
||||
run: |
|
||||
ROOT_DIR=$(pwd)
|
||||
npm install
|
||||
cd ./engine-HEAD
|
||||
npm install --ignore-scripts
|
||||
# Use package-size-check.js in HEAD
|
||||
node .github/workflows/package-size-check.js "$ROOT_DIR"
|
||||
|
||||
- name: Build Declarations (head)
|
||||
if: ${{ matrix.config.target == 'head' }}
|
||||
run: |
|
||||
ROOT_DIR=$(pwd)
|
||||
npm install
|
||||
node .github/workflows/package-size-check.js "$ROOT_DIR"
|
||||
|
||||
- name: Pack for compare
|
||||
run: |
|
||||
mkdir package-for-compare
|
||||
cp ./bin/.declarations/cc.d.ts ./package-for-compare
|
||||
cp -r build-cc-out-2d-empty-legacy-pipline ./package-for-compare
|
||||
cp -r build-cc-out-2d-legacy-pipline ./package-for-compare
|
||||
cp -r build-cc-out-2d-new-pipline ./package-for-compare
|
||||
cp -r build-cc-out-all ./package-for-compare
|
||||
cp -r build-cc-out-all-web ./package-for-compare
|
||||
|
||||
- name: Upload Declarations Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: package-for-compare-${{ matrix.config.target }}
|
||||
path: package-for-compare
|
||||
|
||||
- name: Restore patches
|
||||
run: |
|
||||
echo "-------------------------- Restore patches ---------------------------------"
|
||||
rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
echo "-------------------------- Restore patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
|
||||
interface_check:
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
needs: dts-and-size
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download Artifacts (base)
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: package-for-compare-base
|
||||
path: artifacts/package-for-compare-base
|
||||
|
||||
- name: Download Artifacts (head)
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: package-for-compare-head
|
||||
path: artifacts/package-for-compare-head
|
||||
|
||||
- uses: LouisBrunner/diff-action@v2.0.0
|
||||
with:
|
||||
old: ./artifacts/package-for-compare-base/cc.d.ts
|
||||
new: ./artifacts/package-for-compare-head/cc.d.ts
|
||||
mode: addition
|
||||
tolerance: worse
|
||||
output: ./interface-diff.txt
|
||||
|
||||
- name: optimize interface check report
|
||||
run: |
|
||||
cat ./interface-diff.txt
|
||||
node ./.github/workflows/interface-check-report.js
|
||||
|
||||
- name: After optimize interface check report
|
||||
run: |
|
||||
cat ./interface-diff.txt
|
||||
|
||||
- name: Check Package Size
|
||||
run: |
|
||||
PACKAGE_SIZE_INFO="## Code Size Check Report
|
||||
| Wechat (WASM) | Before | After | Diff |
|
||||
|:-:|:-:|:-:|:-:|"
|
||||
|
||||
BASE_SIZE=0
|
||||
HEAD_SIZE=0
|
||||
DIFF_SIZE=0
|
||||
ICON="✅ "
|
||||
|
||||
reset_diff_vars() {
|
||||
BASE_SIZE=0
|
||||
HEAD_SIZE=0
|
||||
DIFF_SIZE=0
|
||||
ICON="✅ "
|
||||
}
|
||||
|
||||
check_diff() {
|
||||
ccbuild_out_folder_name="$1"
|
||||
if [ -d ./artifacts/package-for-compare-base/$ccbuild_out_folder_name ]; then
|
||||
BASE_SIZE=$(du -sb ./artifacts/package-for-compare-base/$ccbuild_out_folder_name | awk '{print $1}')
|
||||
fi
|
||||
HEAD_SIZE=$(du -sb ./artifacts/package-for-compare-head/$ccbuild_out_folder_name | awk '{print $1}')
|
||||
DIFF_SIZE=$((HEAD_SIZE - BASE_SIZE))
|
||||
if [ "$DIFF_SIZE" -gt 0 ]; then
|
||||
ICON="⚠️ +"
|
||||
elif [ "$DIFF_SIZE" -lt 0 ]; then
|
||||
ICON="👍 "
|
||||
else
|
||||
ICON="✅ "
|
||||
fi
|
||||
}
|
||||
|
||||
# Check Wechat platform
|
||||
check_diff "build-cc-out-2d-empty-legacy-pipline"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D Empty (legacy pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
|
||||
reset_diff_vars
|
||||
|
||||
check_diff "build-cc-out-2d-legacy-pipline"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D All (legacy pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
|
||||
reset_diff_vars
|
||||
|
||||
check_diff "build-cc-out-2d-new-pipline"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D All (new pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
|
||||
reset_diff_vars
|
||||
|
||||
check_diff "build-cc-out-all"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| (2D + 3D) All | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
|
||||
reset_diff_vars
|
||||
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n" "${PACKAGE_SIZE_INFO}")
|
||||
|
||||
# Check Web platform
|
||||
WEB_PLATFORM_TABLE_HEADER="| Web (WASM + ASMJS) | Before | After | Diff |
|
||||
|:-:|:-:|:-:|:-:|"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n\n\n%s\n" "${PACKAGE_SIZE_INFO}" "$WEB_PLATFORM_TABLE_HEADER")
|
||||
|
||||
check_diff "build-cc-out-all-web"
|
||||
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| (2D + 3D) All | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
|
||||
reset_diff_vars
|
||||
|
||||
printf "%s\n" "$PACKAGE_SIZE_INFO"
|
||||
|
||||
DIFF_FILE_PATH=./interface-diff.txt
|
||||
ORIGINAL_DIFF_CONTENT=$(cat ${DIFF_FILE_PATH})
|
||||
echo "Original Diff: "
|
||||
printf "%s\n" "$ORIGINAL_DIFF_CONTENT"
|
||||
|
||||
# Use printf to avoid \n missing
|
||||
printf "%s\n" "$PACKAGE_SIZE_INFO" > ${DIFF_FILE_PATH}
|
||||
printf "%s\n" "$ORIGINAL_DIFF_CONTENT" >> ${DIFF_FILE_PATH}
|
||||
|
||||
echo "Diff after merge: "
|
||||
cat ${DIFF_FILE_PATH}
|
||||
|
||||
- name: Write PR number to file
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('interface-check-pr.txt', process.env.PR_NUMBER);
|
||||
|
||||
- name: Upload PR number artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: interface-check-pr.txt
|
||||
path: |
|
||||
interface-check-pr.txt
|
||||
|
||||
- name: Upload interface diff artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: interface-diff.txt
|
||||
path: |
|
||||
./interface-diff.txt
|
||||
|
||||
check-wasm-up-to-date:
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
needs: dts-and-size
|
||||
|
||||
steps:
|
||||
- name: Check if wasm files are up-to-date (head)
|
||||
run: |
|
||||
if [ "${{ needs.dts-and-size.outputs.SPINE_WASM_UP_TO_DATE_HEAD }}" == "true" ]; then
|
||||
echo "Spine WASM files in native/external is up-to-date."
|
||||
exit 0
|
||||
else
|
||||
echo "Spine WASM files in native/external is not up-to-date, please update native/external-config.json"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,50 +0,0 @@
|
||||
name: <Web> Interface Post Comment
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["<Web> Interface check"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
post-pr-comment:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
run-id: ${{ github.event.workflow_run.id }}
|
||||
merge-multiple: true
|
||||
path: ./artifacts
|
||||
|
||||
- name: Display structure of downloaded files
|
||||
run: |
|
||||
ls -R ./artifacts
|
||||
|
||||
- name: Set PR environment variable
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const pr = Number(fs.readFileSync('./artifacts/interface-check-pr.txt', 'utf8'));
|
||||
core.exportVariable('PR_NUMBER', pr);
|
||||
|
||||
- name: Find Comment
|
||||
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ env.PR_NUMBER }}
|
||||
comment-author: 'github-actions[bot]'
|
||||
body-includes: Interface Check Report
|
||||
|
||||
- name: Update Comment
|
||||
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
|
||||
with:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ env.PR_NUMBER }}
|
||||
edit-mode: replace
|
||||
body-path: './artifacts/interface-diff.txt'
|
||||
@@ -1,152 +0,0 @@
|
||||
name: <Web> npm test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
npm_test:
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 3.1.41
|
||||
|
||||
- name: Verify
|
||||
run: |
|
||||
which emcc
|
||||
emcc -v
|
||||
|
||||
- name: Install ninja
|
||||
run: |
|
||||
if ! command -v ninja &> /dev/null; then
|
||||
echo "Ninja not found, installing..."
|
||||
# sudo apt update
|
||||
sudo apt install ninja-build
|
||||
else
|
||||
echo "Ninja is already installed."
|
||||
fi
|
||||
which ninja
|
||||
|
||||
- name: Download external
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- name: Apply emscripten patches
|
||||
run: |
|
||||
echo "--------------------------------- Save bind.cpp ---------------------------------"
|
||||
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
|
||||
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
|
||||
cp -f ./.github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
|
||||
echo "--------------------------------- Apply patches DONE! ---------------------------------"
|
||||
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
|
||||
|
||||
- name: Build Spine 3.8 WASM
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
rm -rf build-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 3.8 ASMJS
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
rm -rf build-asmjs
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 3.8 files to external directory
|
||||
run: |
|
||||
SPINE_VERSION="3.8"
|
||||
DIST_PATH="dist/3.8"
|
||||
rm -rf $DIST_PATH
|
||||
mkdir -p $DIST_PATH
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
mkdir -p ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
|
||||
echo "-----------------------------------------------"
|
||||
cd ./native/external
|
||||
git status
|
||||
|
||||
- name: Build Spine 4.2 WASM
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
rm -rf build-wasm
|
||||
mkdir build-wasm
|
||||
cd build-wasm
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Build Spine 4.2 ASMJS
|
||||
run: |
|
||||
cd ./native/cocos/editor-support/spine-wasm
|
||||
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
|
||||
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
|
||||
rm -rf build-asmjs
|
||||
mkdir build-asmjs
|
||||
cd build-asmjs
|
||||
emcmake cmake .. -GNinja
|
||||
ninja
|
||||
ls -l
|
||||
|
||||
- name: Copy Spine 4.2 files to external directory
|
||||
run: |
|
||||
DIST_PATH="dist/4.2"
|
||||
rm -rf $DIST_PATH
|
||||
mkdir -p $DIST_PATH
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
|
||||
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
|
||||
mkdir -p ./native/external/emscripten/spine/4.2/
|
||||
echo "-------- Before replace spine wasm -----------"
|
||||
ls -l ./native/external/emscripten/spine/4.2/
|
||||
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/4.2/
|
||||
echo "-------- After replace spine wasm ------------"
|
||||
ls -l ./native/external/emscripten/spine/4.2/
|
||||
echo "-----------------------------------------------"
|
||||
cd ./native/external
|
||||
git status
|
||||
|
||||
- name: npm install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: build-debug-infos
|
||||
run: |
|
||||
npm run build:debug-infos
|
||||
|
||||
- name: run test
|
||||
run: |
|
||||
export NODE_OPTIONS="--max-old-space-size=8192"
|
||||
npm test
|
||||
@@ -1,32 +0,0 @@
|
||||
name: <Web> Quality
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
# github.head_ref is only defined on pull_request events
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
eslint:
|
||||
name: Run ESLint
|
||||
#if: github.actor!= 'dependabot' # ignore the pull request which comes from user dependabot. See https://github.community/t/how-to-stop-github-actions-workflow-to-trigger-when-the-pull-request-is-from-dependabot-preview/116486/3
|
||||
if:
|
||||
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
|
||||
- name: Download external
|
||||
run: |
|
||||
EXT_VERSION=`node ./.github/workflows/get-native-external-version.js`
|
||||
git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external
|
||||
|
||||
- run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
shell: pwsh
|
||||
run: ./.github/workflows/eslint.ps1
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/.project
|
||||
/bin
|
||||
/package
|
||||
/Cocos-Creator-API.json
|
||||
/declarations
|
||||
|
||||
.turbo
|
||||
.idea
|
||||
.history
|
||||
.DS_Store
|
||||
|
||||
lib
|
||||
build
|
||||
aspnet_client
|
||||
node_modules
|
||||
npm-debug.log
|
||||
DebugInfos.json
|
||||
playground/library
|
||||
tests/core/serialization/ccob-serialized-gallery
|
||||
scripts/build-engine/dist
|
||||
scripts/native-pack-tool/dist
|
||||
scripts/runtime-web-adapter
|
||||
scripts/typedoc-plugin/lib/
|
||||
native/external/
|
||||
editor/library/
|
||||
|
||||
!templates/**/*
|
||||
templates/**/.DS_Store
|
||||
|
||||
platforms/runtime/local-commit.json
|
||||
platforms/runtime/common/web-adapter.js
|
||||
platforms/runtime/common/web-adapter.min.js
|
||||
platforms/runtime/platforms/cocos-play/ral.js
|
||||
platforms/runtime/platforms/cocos-play/ral.min.js
|
||||
platforms/runtime/platforms/huawei-quick-game/ral.js
|
||||
platforms/runtime/platforms/huawei-quick-game/ral.min.js
|
||||
platforms/runtime/platforms/link-sure/ral.js
|
||||
platforms/runtime/platforms/link-sure/ral.min.js
|
||||
platforms/runtime/platforms/oppo-mini-game/ral.js
|
||||
platforms/runtime/platforms/oppo-mini-game/ral.min.js
|
||||
platforms/runtime/platforms/qtt/ral.js
|
||||
platforms/runtime/platforms/qtt/ral.min.js
|
||||
platforms/runtime/platforms/vivo-mini-game/ral.js
|
||||
platforms/runtime/platforms/vivo-mini-game/ral.min.js
|
||||
|
||||
@types/consts.d.ts
|
||||
|
||||
__TS_ENGINE__/
|
||||
|
||||
# pal 由 @cocos/engine-pal 在 postinstall 挂载(软链/复制),不入库
|
||||
/pal
|
||||
|
||||
# platforms 源码已抽到 @cocos/engine-platforms;其预打包 adapter 由 postinstall 的
|
||||
# spread-adapter.cjs 复制到 bin/adapter(/bin 已忽略)。platforms 源码不再入库。
|
||||
/platforms
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EslintConfiguration">
|
||||
<option name="fix-on-save" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
Vendored
-57
@@ -1,57 +0,0 @@
|
||||
{
|
||||
"version": "0.1",
|
||||
"words": [
|
||||
"ALIPAY",
|
||||
"Arial",
|
||||
"BYTEDANCE",
|
||||
"ccclass",
|
||||
"ccenum",
|
||||
"ccon",
|
||||
"Chukong",
|
||||
"clampf",
|
||||
"COCOSPLAY",
|
||||
"coeff",
|
||||
"deinterleave",
|
||||
"deserialization",
|
||||
"deserialize",
|
||||
"deserializes",
|
||||
"Dpad",
|
||||
"earcut",
|
||||
"emscripten",
|
||||
"endregion",
|
||||
"eventified",
|
||||
"eventify",
|
||||
"forin",
|
||||
"interruptible",
|
||||
"glsl",
|
||||
"grayscale",
|
||||
"IGFX",
|
||||
"lerp",
|
||||
"lerpable",
|
||||
"lightmap",
|
||||
"LINKSURE",
|
||||
"MINIGAME",
|
||||
"mipmaps",
|
||||
"octree",
|
||||
"OPENGL",
|
||||
"OPPO",
|
||||
"polyfill",
|
||||
"QTT",
|
||||
"quadtree",
|
||||
"raycast",
|
||||
"realloc",
|
||||
"renderable",
|
||||
"serializable",
|
||||
"skybox",
|
||||
"slerp",
|
||||
"SNORM",
|
||||
"struct",
|
||||
"typedoc",
|
||||
"UNORM",
|
||||
"wasm",
|
||||
"WECHAT",
|
||||
"WECHATGAME",
|
||||
"XIAOMI",
|
||||
"Yaji"
|
||||
]
|
||||
}
|
||||
Vendored
-84
@@ -1,84 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Build Declarations",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"args": [
|
||||
"build-declarations"
|
||||
],
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Build Code",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"args": [
|
||||
"build-code"
|
||||
],
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome",
|
||||
"url": "http://localhost:8002/playground/simple.html",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"name": "Unit Test",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js"
|
||||
},
|
||||
"args": [
|
||||
"--logHeapUsage"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"name": "Unit Test Current File",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js"
|
||||
},
|
||||
"args": [
|
||||
"--runTestsByPath",
|
||||
"${relativeFileDirname}/${fileBasename}"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"disableOptimisticBPs": true,
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"name": "Unit Test Serialization",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js"
|
||||
},
|
||||
"args": [
|
||||
"--testPathPattern=shared/.*\\.test\\.ts"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"disableOptimisticBPs": true,
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
-38
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
".git": true,
|
||||
"node_modules": true,
|
||||
},
|
||||
"search.exclude": {
|
||||
".git": true,
|
||||
"node_modules": true,
|
||||
".github": true,
|
||||
"bin": true
|
||||
},
|
||||
"typescript.preferences.importModuleSpecifier": "relative",
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"typescript"
|
||||
],
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll": "explicit",
|
||||
},
|
||||
"files.associations": {
|
||||
"*.cmake": "makefile",
|
||||
"iterator": "cpp",
|
||||
"*.ipp": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"chrono": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"regex": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xstring": "cpp",
|
||||
"tuple": "cpp",
|
||||
"vector": "cpp",
|
||||
"istream": "c"
|
||||
},
|
||||
"cmake.configureOnOpen": false,
|
||||
"cmake.sourceDirectory": "${workspaceFolder}/native",
|
||||
}
|
||||
Vendored
-789
@@ -1,789 +0,0 @@
|
||||
declare namespace b2jsb {
|
||||
const maxPolygonVertices: number;
|
||||
|
||||
export interface XY {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
class Vec2 implements XY {
|
||||
x: number;
|
||||
y: number;
|
||||
constructor();
|
||||
constructor(data: Float32Array);
|
||||
constructor(x: number, y: number);
|
||||
constructor(...args: any[]);
|
||||
Clone(): Vec2;
|
||||
SetZero(): Vec2;
|
||||
Set(): Vec2;
|
||||
Copy(): Vec2;
|
||||
SelfAdd(): Vec2;
|
||||
SelfAddXY(): Vec2;
|
||||
SelfSub(): Vec2;
|
||||
SelfSubXY(): Vec2;
|
||||
SelfMul(): Vec2;
|
||||
SelfMulAdd(): Vec2;
|
||||
SelfMulSub(): Vec2;
|
||||
Dot(): any;
|
||||
Cross(): any;
|
||||
Length(): any;
|
||||
LengthSquared(): any;
|
||||
Normalize(): any;
|
||||
SelfNormalize(): Vec2;
|
||||
SelfRotate(): Vec2;
|
||||
IsValid(): any;
|
||||
SelfCrossVS(): Vec2;
|
||||
SelfCrossSV(): Vec2;
|
||||
SelfMinV(): Vec2;
|
||||
SelfMaxV(): Vec2;
|
||||
SelfAbs(): Vec2;
|
||||
SelfNeg(): Vec2;
|
||||
SelfSkew(): Vec2;
|
||||
MakeArray(): any;
|
||||
AbsV(): any;
|
||||
MinV(): any;
|
||||
MaxV(): any;
|
||||
ClampV(): any;
|
||||
RotateV(): any;
|
||||
DotVV(): any;
|
||||
CrossVV(): any;
|
||||
CrossVS(): any;
|
||||
CrossVOne(): any;
|
||||
CrossSV(): any;
|
||||
CrossOneV(): any;
|
||||
AddVV(a, b, out): any;
|
||||
SubVV(a, b, out): any;
|
||||
MulSV(s, v, out): any;
|
||||
MulVS(v, s, out): any;
|
||||
AddVMulSV(a, s, b, out): any;
|
||||
SubVMulSV(a, s, b, out): any;
|
||||
AddVCrossSV(a, s, v, out): any;
|
||||
MidVV(a, b, out): any;
|
||||
ExtVV(a, b, out): any;
|
||||
IsEqualToV(a, b): any;
|
||||
DistanceVV(a, b): any;
|
||||
DistanceSquaredVV(a, b): any;
|
||||
NegV(v, out): any;
|
||||
}
|
||||
|
||||
export enum b2ManifoldType {
|
||||
e_unknown = -1,
|
||||
e_circles = 0,
|
||||
e_faceA = 1,
|
||||
e_faceB = 2,
|
||||
}
|
||||
class Manifold {
|
||||
readonly points: b2ManifoldPoint[];
|
||||
readonly localNormal: Vec2;
|
||||
readonly localPoint: Vec2;
|
||||
type: b2ManifoldType;
|
||||
pointCount: number;
|
||||
Reset (): void;
|
||||
Copy (o: Manifold): Manifold;
|
||||
Clone(): Manifold;
|
||||
}
|
||||
|
||||
class ContactID {
|
||||
readonly cf: any;
|
||||
Copy(o: ContactID): ContactID ;
|
||||
Clone(): ContactID;
|
||||
get key(): number;
|
||||
set key(value: number);
|
||||
}
|
||||
|
||||
class b2ManifoldPoint {
|
||||
readonly localPoint: Vec2; ///< usage depends on manifold type
|
||||
normalImpulse: number; ///< the non-penetration impulse
|
||||
tangentImpulse: number; ///< the friction impulse
|
||||
readonly id: ContactID; ///< uniquely identifies a contact point between two shapes
|
||||
static MakeArray (length: number): b2ManifoldPoint[];
|
||||
Reset (): void;
|
||||
Copy (o: b2ManifoldPoint): b2ManifoldPoint;
|
||||
}
|
||||
|
||||
export interface Vec2Vector {
|
||||
push_back(v: Vec2): void;
|
||||
get(i: number): Vec2;
|
||||
size(): number;
|
||||
}
|
||||
|
||||
export interface Int32Vector {
|
||||
push_back(v: number): void;
|
||||
get(i: number): number;
|
||||
size(): number;
|
||||
}
|
||||
|
||||
export interface MassData {
|
||||
mass: number;
|
||||
center: Vec2;
|
||||
I: number;
|
||||
}
|
||||
|
||||
class b2Rot {
|
||||
s: number;
|
||||
c: number;
|
||||
constructor(angle) ;
|
||||
Clone(): b2Rot;
|
||||
Copy(angle: b2Rot): b2Rot;
|
||||
SetAngle(angle);
|
||||
SetIdentity(): b2Rot;
|
||||
GetAngle(): number;
|
||||
GetXAxis(out): b2Rot;
|
||||
GetYAxis(out): b2Rot;
|
||||
MulRR(q, r, out): any;
|
||||
MulTRR(q, r, out): any;
|
||||
MulRV(q, v, out): any;
|
||||
MulTRV(q, v, out): any;
|
||||
IDENTITY: b2Rot;
|
||||
}
|
||||
export class Transform {
|
||||
static MulXV(_xf: any, center: any, _tmp_vec2: any): any;
|
||||
constructor();
|
||||
p: Vec2;
|
||||
q: b2Rot;
|
||||
}
|
||||
const _tempFloatArray: Float32Array; // For other ts file in box2d-jsb module to access this arraybuffer.
|
||||
function _setTempFloatArray(_array: any);
|
||||
|
||||
class AABB {
|
||||
constructor();
|
||||
lowerBound: any;
|
||||
upperBound: any;
|
||||
IsValid(): boolean;
|
||||
GetCenter(): Vec2;
|
||||
GetExtents(): Vec2;
|
||||
GetPerimeter(): number;
|
||||
Combine(aabb: AABB): void;
|
||||
CombineTwo(aabb1: AABB, aabb2: AABB): void;
|
||||
Contains(aabb: AABB): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput): boolean;
|
||||
TestOverlap(other: AABB): boolean;
|
||||
}
|
||||
|
||||
class RayCastCallback {
|
||||
initWithThis(thisObj: RayCastCallback);
|
||||
constructor();
|
||||
ReportFixture(fixture, point, normal, fraction): number;
|
||||
// #if B2_ENABLE_PARTICLE
|
||||
ReportParticle(system, index, point, normal, fraction): number;
|
||||
ShouldQueryParticleSystem(system): boolean;
|
||||
}
|
||||
class QueryCallback {
|
||||
initWithThis(thisObj: QueryCallback);
|
||||
constructor();
|
||||
ReportFixture(fixture: Fixture): boolean;
|
||||
}
|
||||
|
||||
export interface RayCastInput {
|
||||
p1: Vec2;
|
||||
p2: Vec2;
|
||||
maxFraction: number;
|
||||
}
|
||||
|
||||
export interface RayCastOutput {
|
||||
normal: Vec2;
|
||||
fraction: number;
|
||||
}
|
||||
|
||||
export class Filter {
|
||||
constructor();
|
||||
categoryBits: number;
|
||||
maskBits: number;
|
||||
groupIndex: number;
|
||||
}
|
||||
|
||||
class ContactListener {
|
||||
initWithThis(param: any);
|
||||
constructor();
|
||||
BeginContact(contact: Contact): void;
|
||||
EndContact(contact: Contact): void;
|
||||
PreSolve(contact: Contact, oldManifold: Manifold): void;
|
||||
PostSolve(contact: Contact, impulse: ContactImpulse): void;
|
||||
registerContactFixture(fixture: Fixture): void;
|
||||
unregisterContactFixture(fixture: Fixture): void;
|
||||
isIndexOf(fixture: Fixture): void;
|
||||
}
|
||||
|
||||
/// Friction mixing law. The idea is to allow either fixture to drive the friction to zero.
|
||||
/// For example, anything slides on ice.
|
||||
function b2MixFriction(friction1: number, friction2: number): number;
|
||||
|
||||
/// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface.
|
||||
/// For example, a superball bounces on anything.
|
||||
function b2MixRestitution(restitution1: number, restitution2: number): number;
|
||||
|
||||
class ContactEdge {
|
||||
_other: Body | null; ///< provides quick access to the other body attached.
|
||||
get other(): Body;
|
||||
set other(value: Body);
|
||||
readonly contact: Contact; ///< the contact
|
||||
prev: ContactEdge | null; ///< the previous contact edge in the body's contact list
|
||||
next: ContactEdge | null; ///< the next contact edge in the body's contact list
|
||||
constructor(contact: Contact);
|
||||
Reset(): void;
|
||||
}
|
||||
class WorldManifold {
|
||||
readonly normal: Vec2;
|
||||
readonly points: Vec2[];
|
||||
readonly separations: number[];
|
||||
|
||||
static Initialize_s_pointA;
|
||||
static Initialize_s_pointB;
|
||||
static Initialize_s_cA;
|
||||
static Initialize_s_cB;
|
||||
static Initialize_s_planePoint;
|
||||
static Initialize_s_clipPoint;
|
||||
Initialize(manifold: Manifold, xfA: Transform, radiusA: number, xfB: Transform, radiusB: number): void ;
|
||||
}
|
||||
|
||||
class Color {
|
||||
constructor (rIn?: number, gIn?: number, bIn?: number, aIn?: number);
|
||||
|
||||
Set (rIn?: number, gIn?: number, bIn?: number, aIn?: number): void;
|
||||
|
||||
declare r: number;
|
||||
declare g: number;
|
||||
declare b: number;
|
||||
declare a: number;
|
||||
}
|
||||
|
||||
export abstract class Contact<A extends Shape = Shape, B extends Shape = Shape> {
|
||||
m_islandFlag: boolean; /// Used when crawling contact graph when forming islands.
|
||||
m_touchingFlag: boolean; /// Set when the shapes are touching.
|
||||
m_enabledFlag: boolean; /// This contact can be disabled (by user)
|
||||
m_filterFlag: boolean; /// This contact needs filtering because a fixture filter was changed.
|
||||
m_bulletHitFlag: boolean; /// This bullet contact had a TOI event
|
||||
m_toiFlag: boolean; /// This contact has a valid TOI in m_toi
|
||||
|
||||
m_prev: Contact | null;
|
||||
m_next: Contact | null;
|
||||
|
||||
readonly m_nodeA: ContactEdge;
|
||||
readonly m_nodeB: ContactEdge;
|
||||
|
||||
m_fixtureA: Fixture;
|
||||
m_fixtureB: Fixture;
|
||||
|
||||
m_indexA: number;
|
||||
m_indexB: number;
|
||||
|
||||
m_manifold: Manifold; // TODO: readonly
|
||||
|
||||
m_toiCount: number;
|
||||
m_toi: number;
|
||||
|
||||
m_friction: number;
|
||||
m_restitution: number;
|
||||
|
||||
m_tangentSpeed: number;
|
||||
|
||||
m_oldManifold: Manifold; // TODO: readonly
|
||||
|
||||
GetManifold() ;
|
||||
|
||||
GetWorldManifold(worldManifold: any): void;
|
||||
|
||||
IsTouching(): boolean ;
|
||||
|
||||
SetEnabled(flag: any);
|
||||
|
||||
IsEnabled();
|
||||
|
||||
GetNext(): Contact | null;
|
||||
|
||||
GetFixtureA(): Fixture ;
|
||||
|
||||
GetChildIndexA(): number ;
|
||||
|
||||
GetShapeA(): A ;
|
||||
|
||||
GetFixtureB(): Fixture ;
|
||||
|
||||
GetChildIndexB(): number;
|
||||
|
||||
GetShapeB(): B;
|
||||
|
||||
abstract Evaluate(manifold: Manifold, xfA: Transform, xfB: Transform): void;
|
||||
|
||||
FlagForFiltering(): void;
|
||||
|
||||
SetFriction(friction: any): void;
|
||||
|
||||
GetFriction(): number;
|
||||
|
||||
ResetFriction(): void;
|
||||
|
||||
SetRestitution(restitution: any): void;
|
||||
|
||||
GetRestitution(): number;
|
||||
|
||||
ResetRestitution(): void;
|
||||
|
||||
SetTangentSpeed(speed: any): void;
|
||||
|
||||
GetTangentSpeed(): number;
|
||||
|
||||
Reset(fixtureA: Fixture, indexA: number, fixtureB: Fixture, indexB: number): void ;
|
||||
}
|
||||
|
||||
class Draw {
|
||||
initWithThis(param: any);
|
||||
constructor();
|
||||
SetFlags(flags: number): void;
|
||||
GetFlags(): number;
|
||||
AppendFlags(flags: number): void;
|
||||
ClearFlags(flags: number): void;
|
||||
DrawPolygon(vertices: Vec2[], vertexCount: number, color: Color): void;
|
||||
DrawSolidPolygon(vertices: Vec2[], vertexCount: number, color: Color): void;
|
||||
DrawCircle(center: Vec2, radius: number, color: Color): void;
|
||||
DrawSolidCircle(center: Vec2, radius: number, axis: Vec2, color: Color): void;
|
||||
}
|
||||
export interface ContactImpulse {
|
||||
count: number;
|
||||
normalImpulses: number[];
|
||||
/**
|
||||
* @en
|
||||
* Tangent impulses.
|
||||
* @zh
|
||||
* 切线方向的冲量。
|
||||
* @property tangentImpulses
|
||||
*/
|
||||
tangentImpulses: number[];
|
||||
}
|
||||
|
||||
class World {
|
||||
constructor(gravity: Vec2);
|
||||
DrawDebugData(): void;
|
||||
SetContactListener(listener: any): void;
|
||||
SetDebugDraw(debugDraw: Draw): void;
|
||||
CreateBody(def: BodyDef): Body;
|
||||
DestroyBody(body: Body): void;
|
||||
CreateJoint(def: JointDef): Joint;
|
||||
DestroyJoint(joint: Joint|null): void;
|
||||
Step(timeStep: number, velocityIterations: number, positionIterations: number): void;
|
||||
DebugDraw(): void;
|
||||
QueryAABB(callback: QueryCallback, aabb: AABB): void;
|
||||
RayCast(callback: RayCastCallback, point1: any, point2: any): void;
|
||||
SetAllowSleeping(flag: boolean): void;
|
||||
GetAllowSleeping(): boolean;
|
||||
SetGravity(gravity: Vec2): void;
|
||||
GetGravity(): Vec2;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class Shape {
|
||||
m_type: number;
|
||||
m_radius: number;
|
||||
GetType(): number;
|
||||
GetChildCount(): number;
|
||||
TestPoint(xf: Transform, p: Vec2): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput, transform: Transform, childIndex: number): boolean;
|
||||
ComputeAABB(aabb: AABB, xf: Transform, childIndex: number): void;
|
||||
ComputeMass(massData: MassData, density: number): void;
|
||||
SetRadius(radius: number): void;
|
||||
GetRadius(): number;
|
||||
}
|
||||
|
||||
class CircleShape extends Shape {
|
||||
constructor();
|
||||
m_p: any;
|
||||
Clone(): CircleShape;
|
||||
GetChildCount(): number;
|
||||
TestPoint(transform: Transform, p: Vec2): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput, transform: Transform, childIndex: number): boolean;
|
||||
ComputeAABB(aabb: AABB, transform: Transform, childIndex: number): void;
|
||||
ComputeMass(massData: MassData, density: number): void;
|
||||
}
|
||||
|
||||
class EdgeShape extends Shape {
|
||||
constructor();
|
||||
Set(v1: Vec2, v2: Vec2): void;
|
||||
Clone(): EdgeShape;
|
||||
GetChildCount(): number;
|
||||
TestPoint(transform: Transform, p: Vec2): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput, transform: Transform, childIndex: number): boolean;
|
||||
ComputeAABB(aabb: AABB, transform: Transform, childIndex: number): void;
|
||||
ComputeMass(massData: MassData, density: number): void;
|
||||
}
|
||||
|
||||
class PolygonShape extends Shape {
|
||||
constructor();
|
||||
Clone(): PolygonShape;
|
||||
Set(vertices: any, count: number): void;
|
||||
SetAsBox(hx: number, hy: number): void;
|
||||
SetAsBox(hx: number, hy: number, p: Vec2, px: number): void;
|
||||
SetAsBoxWithCenterAndAngle(hx: number, hy: number, center: Vec2, angle: number): void;
|
||||
GetChildCount(): number;
|
||||
TestPoint(transform: Transform, p: Vec2): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput, transform: Transform, childIndex: number): boolean;
|
||||
ComputeAABB(aabb: AABB, transform: Transform, childIndex: number): void;
|
||||
ComputeMass(massData: MassData, density: number): void;
|
||||
Validate(): boolean;
|
||||
}
|
||||
|
||||
class FixtureDef {
|
||||
shape: Shape;
|
||||
userData: any;
|
||||
friction: number;
|
||||
restitution: number;
|
||||
density: number;
|
||||
isSensor: boolean;
|
||||
filter: Filter;
|
||||
SetShape(shape: Shape): void;
|
||||
GetShape(): Shape;
|
||||
}
|
||||
|
||||
class Fixture {
|
||||
m_userData: any;
|
||||
GetType(): number;
|
||||
GetShape(): Shape;
|
||||
SetSensor(sensor: boolean): void;
|
||||
IsSensor(): boolean;
|
||||
SetFilterData(filter: any): void;
|
||||
GetFilterData(): Filter;
|
||||
Refilter(): void;
|
||||
GetBody(): Body;
|
||||
GetNext(): Fixture;
|
||||
TestPoint(p: Vec2): boolean;
|
||||
RayCast(output: RayCastOutput, input: RayCastInput, childIndex: number): boolean;
|
||||
GetMassData(massData: MassData): void;
|
||||
SetDensity(density: number): void;
|
||||
GetDensity(): number;
|
||||
GetFriction(): number;
|
||||
SetFriction(friction: number): void;
|
||||
GetRestitution(): number;
|
||||
SetRestitution(restitution: number): void;
|
||||
GetAABB(childIndex: number): AABB;
|
||||
Dump(bodyIndex: number): void;
|
||||
}
|
||||
|
||||
enum BodyType{
|
||||
b2_staticBody = 0,
|
||||
b2_kinematicBody,
|
||||
b2_dynamicBody,
|
||||
cc_animatedBody,
|
||||
}
|
||||
|
||||
class BodyDef {
|
||||
constructor();
|
||||
type: BodyType;
|
||||
position: Vec2;
|
||||
angle: number;
|
||||
linearVelocity: Vec2;
|
||||
angularVelocity: number;
|
||||
linearDamping: number;
|
||||
angularDamping: number;
|
||||
allowSleep: boolean;
|
||||
awake: boolean;
|
||||
fixedRotation: boolean;
|
||||
bullet: boolean;
|
||||
gravityScale: number;
|
||||
}
|
||||
|
||||
class Body {
|
||||
m_userData: any;
|
||||
_SetTransformJSB();
|
||||
_SetPositionJSB();
|
||||
_SetAngleJSB();
|
||||
_GetTransformJSB(): any;
|
||||
CreateFixture (fixtureDef: FixtureDef): Fixture;
|
||||
CreateFixtureWithShape (shape: Shape, density: number): Fixture;
|
||||
DestroyFixture(fixture: Fixture): void;
|
||||
SetTransform(position: Vec2, angle: number): void;
|
||||
GetTransform(): Transform;
|
||||
GetPosition(): Vec2;
|
||||
SetPosition(pos: Vec2): void;
|
||||
GetAngle(): number;
|
||||
SetAngle(angle: number): void;
|
||||
GetWorldCenter(): Vec2;
|
||||
GetLocalCenter(): Vec2;
|
||||
SetLinearVelocity(v: Vec2): void;
|
||||
GetLinearVelocity(): Vec2;
|
||||
SetAngularVelocity(omega: number): void;
|
||||
GetAngularVelocity(): number;
|
||||
ApplyForce(force: Vec2, point: Vec2, wake: boolean): void;
|
||||
ApplyForceToCenter(force: Vec2, wake: boolean): void;
|
||||
ApplyTorque(torque: number, wake: boolean): void;
|
||||
ApplyLinearImpulse(impulse: Vec2, point: Vec2, wake: boolean): void;
|
||||
ApplyLinearImpulseToCenter(impulse: Vec2, wake: boolean): void;
|
||||
ApplyAngularImpulse(impulse: number, wake: boolean): void;
|
||||
GetMass(): number;
|
||||
GetInertia(): number;
|
||||
GetMassData(data: MassData): void;
|
||||
SetMassData(data: MassData): void;
|
||||
ResetMassData(): void;
|
||||
GetWorldPoint(localPoint: Vec2): Vec2;
|
||||
GetWorldVector(localVector: Vec2): Vec2;
|
||||
GetLocalPoint(worldPoint: Vec2): Vec2;
|
||||
GetLocalVector(worldVector: Vec2): Vec2;
|
||||
GetLinearVelocityFromWorldPoint(worldPoint: Vec2): Vec2;
|
||||
GetLinearVelocityFromLocalPoint(localPoint: Vec2): Vec2;
|
||||
GetLinearDamping(): number;
|
||||
SetLinearDamping(linearDamping: number): void;
|
||||
GetAngularDamping(): number;
|
||||
SetAngularDamping(angularDamping: number): void;
|
||||
GetGravityScale(): number;
|
||||
SetGravityScale(scale: number): void;
|
||||
SetType(type: BodyType): void;
|
||||
GetType(): BodyType;
|
||||
SetBullet(flag: boolean): void;
|
||||
IsBullet(): boolean;
|
||||
SetSleepingAllowed(flag: boolean): void;
|
||||
IsSleepingAllowed(): boolean;
|
||||
SetAwake(flag: boolean): void;
|
||||
IsAwake(): boolean;
|
||||
SetEnabled(flag: boolean): void;
|
||||
IsEnabled(): boolean;
|
||||
SetFixedRotation(flag: boolean): void;
|
||||
IsFixedRotation(): boolean;
|
||||
GetFixtureList(): number;
|
||||
GetJointList(): number;
|
||||
GetWorld(): World;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
enum JointType {
|
||||
e_unknownJoint,
|
||||
e_revoluteJoint,
|
||||
e_prismaticJoint,
|
||||
e_distanceJoint,
|
||||
e_pulleyJoint,
|
||||
e_mouseJoint,
|
||||
e_gearJoint,
|
||||
e_wheelJoint,
|
||||
e_weldJoint,
|
||||
e_frictionJoint,
|
||||
e_ropeJoint,
|
||||
e_motorJoint
|
||||
}
|
||||
|
||||
class JointDef {
|
||||
constructor(type: JointType);
|
||||
type: JointType;
|
||||
collideConnected: boolean;
|
||||
bodyA: any;
|
||||
bodyB: any;
|
||||
SetBodyA(bodyA: Body): void;
|
||||
SetBodyB(bodyB: Body): void;
|
||||
GetBodyA(): Body;
|
||||
GetBodyB(): Body;
|
||||
SetCollideConnected(flag: boolean): void;
|
||||
}
|
||||
|
||||
class Joint {
|
||||
GetType(): JointType;
|
||||
GetBodyA(): Body;
|
||||
GetBodyB(): Body;
|
||||
GetAnchorA(): Vec2;
|
||||
GetAnchorB(): Vec2;
|
||||
GetReactionForce(inv_dt: number): Vec2;
|
||||
GetReactionTorque(inv_dt: number): number;
|
||||
IsActive(): boolean;
|
||||
GetCollideConnected(): boolean;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class DistanceJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
length: number;
|
||||
frequencyHz: number;
|
||||
dampingRatio: number;
|
||||
}
|
||||
|
||||
class DistanceJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
SetLength(length: number): void;
|
||||
GetLength(): number;
|
||||
SetFrequency(hz: number): void;
|
||||
GetFrequency(): number;
|
||||
SetDampingRatio(ratio: number): void;
|
||||
GetDampingRatio(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class MotorJointDef extends JointDef {
|
||||
constructor();
|
||||
linearOffset: any;
|
||||
angularOffset: number;
|
||||
maxForce: number;
|
||||
maxTorque: number;
|
||||
correctionFactor: number;
|
||||
}
|
||||
|
||||
class MotorJoint extends Joint {
|
||||
m_correctionFactor: any;
|
||||
SetLinearOffset(linearOffset: Vec2): void;
|
||||
GetLinearOffset(): Vec2;
|
||||
SetAngularOffset(angularOffset: number): void;
|
||||
GetAngularOffset(): number;
|
||||
SetMaxForce(force: number): void;
|
||||
GetMaxForce(): number;
|
||||
SetMaxTorque(torque: number): void;
|
||||
GetMaxTorque(): number;
|
||||
SetCorrectionFactor(factor: number): void;
|
||||
GetCorrectionFactor(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class MouseJointDef extends JointDef {
|
||||
constructor();
|
||||
target: Vec2;
|
||||
maxForce: number;
|
||||
frequencyHz: number;
|
||||
dampingRatio: number;
|
||||
}
|
||||
|
||||
class MouseJoint extends Joint {
|
||||
SetTarget(target: Vec2): void;
|
||||
GetTarget(): Vec2;
|
||||
SetMaxForce(force: number): void;
|
||||
GetMaxForce(): number;
|
||||
SetFrequency(hz: number): void;
|
||||
GetFrequency(): number;
|
||||
SetDampingRatio(ratio: number): void;
|
||||
GetDampingRatio(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class PrismaticJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
localAxisA: any;
|
||||
referenceAngle: number;
|
||||
enableLimit: boolean;
|
||||
lowerTranslation: number;
|
||||
upperTranslation: number;
|
||||
enableMotor: boolean;
|
||||
maxMotorForce: number;
|
||||
motorSpeed: number;
|
||||
}
|
||||
|
||||
class PrismaticJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
GetLocalAxisA(): Vec2;
|
||||
GetReferenceAngle(): number;
|
||||
GetJointTranslation(): number;
|
||||
GetJointSpeed(): number;
|
||||
IsLimitEnabled(): boolean;
|
||||
EnableLimit(flag: boolean): void;
|
||||
GetLowerLimit(): number;
|
||||
GetUpperLimit(): number;
|
||||
SetLimits(lower: number, upper: number): void;
|
||||
IsMotorEnabled(): boolean;
|
||||
EnableMotor(flag: boolean): void;
|
||||
SetMotorSpeed(speed: number): void;
|
||||
GetMotorSpeed(): number;
|
||||
SetMaxMotorForce(force: number): void;
|
||||
GetMaxMotorForce(): number;
|
||||
GetMotorForce(inv_dt: number): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class RevoluteJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
referenceAngle: number;
|
||||
enableLimit: boolean;
|
||||
lowerAngle: number;
|
||||
upperAngle: number;
|
||||
enableMotor: boolean;
|
||||
motorSpeed: number;
|
||||
maxMotorTorque: number;
|
||||
}
|
||||
|
||||
class RevoluteJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
GetReferenceAngle(): number;
|
||||
GetJointAngle(): number;
|
||||
GetJointSpeed(): number;
|
||||
IsLimitEnabled(): boolean;
|
||||
EnableLimit(flag: boolean): void;
|
||||
GetLowerLimit(): number;
|
||||
GetUpperLimit(): number;
|
||||
SetLimits(lower: number, upper: number): void;
|
||||
IsMotorEnabled(): boolean;
|
||||
EnableMotor(flag: boolean): void;
|
||||
SetMotorSpeed(speed: number): void;
|
||||
GetMotorSpeed(): number;
|
||||
SetMaxMotorTorque(torque: number): void;
|
||||
GetMaxMotorTorque(): number;
|
||||
GetMotorTorque(inv_dt: number): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class RopeJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
maxLength: number;
|
||||
}
|
||||
|
||||
class RopeJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
GetReactionForce(inv_dt: number): Vec2;
|
||||
GetReactionTorque(inv_dt: number): number;
|
||||
SetMaxLength(length: number): void;
|
||||
GetMaxLength(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class WeldJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
referenceAngle: number;
|
||||
frequencyHz: number;
|
||||
dampingRatio: number;
|
||||
}
|
||||
|
||||
class WeldJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
GetReferenceAngle(): number;
|
||||
SetFrequency(hz: number): void;
|
||||
GetFrequency(): number;
|
||||
SetDampingRatio(ratio: number): void;
|
||||
GetDampingRatio(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
class WheelJointDef extends JointDef {
|
||||
constructor();
|
||||
localAnchorA: any;
|
||||
localAnchorB: any;
|
||||
localAxisA: any;
|
||||
enableMotor: boolean;
|
||||
maxMotorTorque: number;
|
||||
motorSpeed: number;
|
||||
frequencyHz: number;
|
||||
dampingRatio: number;
|
||||
}
|
||||
|
||||
class WheelJoint extends Joint {
|
||||
GetLocalAnchorA(): Vec2;
|
||||
GetLocalAnchorB(): Vec2;
|
||||
GetLocalAxisA(): Vec2;
|
||||
GetJointTranslation(): number;
|
||||
IsMotorEnabled(): boolean;
|
||||
EnableMotor(flag: boolean): void;
|
||||
SetMotorSpeed(speed: number): void;
|
||||
GetMotorSpeed(): number;
|
||||
SetMaxMotorTorque(torque: number): void;
|
||||
GetMaxMotorTorque(): number;
|
||||
GetMotorTorque(inv_dt: number): number;
|
||||
SetSpringFrequencyHz(hz: number): void;
|
||||
GetSpringFrequencyHz(): number;
|
||||
SetSpringDampingRatio(ratio: number): void;
|
||||
GetSpringDampingRatio(): number;
|
||||
Dump(): void;
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
-101
@@ -1,101 +0,0 @@
|
||||
interface EditorAssetInfo {
|
||||
name: string; // 资源名字
|
||||
displayName: string; // 资源用于显示的名字
|
||||
source: string; // url 地址
|
||||
path: string; // loader 加载的层级地址
|
||||
url: string; // loader 加载地址会去掉扩展名,这个参数不去掉
|
||||
file: string; // 绝对路径
|
||||
uuid: string; // 资源的唯一 ID
|
||||
importer: string; // 使用的导入器名字
|
||||
type: string; // 类型
|
||||
isDirectory: boolean; // 是否是文件夹
|
||||
library: { [key: string]: string }; // 导入资源的 map
|
||||
subAssets: { [key: string]: EditorAssetInfo }; // 子资源 map
|
||||
visible: boolean; // 是否显示
|
||||
readonly: boolean; // 是否只读
|
||||
instantiation: string | undefined; // 虚拟资源可以实例化成实体的话,会带上这个扩展名
|
||||
redirect?: string; // 跳转指向资源
|
||||
meta?: any,
|
||||
fatherInfo?: any;
|
||||
}
|
||||
|
||||
interface EditorExtendsScript {
|
||||
add(uuid: string, ctor: any): any;
|
||||
remove(uuid: string, ctor: any): any;
|
||||
getCtors(uuid: string): { [uuid: string]: any }
|
||||
}
|
||||
|
||||
interface EditorExtendsNode {
|
||||
add(uuid: string, node: any): any;
|
||||
remove(uuid: string): any;
|
||||
clear(): any;
|
||||
getNode(uuid: string): any;
|
||||
getNodes(): {[uuid: string]: any};
|
||||
emit(name: string, ...args: any): void;
|
||||
}
|
||||
|
||||
interface EditorExtendsPrefabUtils {
|
||||
addPrefabInstance(node: import('cocos/scene-graph/node').Node);
|
||||
}
|
||||
|
||||
interface EditorExtendsComponent {
|
||||
addMenu(component: Function, path: string, priority?: number);
|
||||
removeMenu(component: Function);
|
||||
getMenus(): { [uuid: string]: Object };
|
||||
add(uuid: string, component: any): any;
|
||||
remove(uuid: string): any;
|
||||
clear(): any;
|
||||
getComponent(uuid: string): any;
|
||||
getComponents(): {[uuid: string]: any};
|
||||
}
|
||||
|
||||
interface EditorExtendsAsset {
|
||||
queryAssetInfo(uuid: string, callback: Function): any;
|
||||
getAssetInfoFromUrl(url: string): EditorAssetInfo;
|
||||
saveDataToImage(buffer: Uint8Array | null, width: number, height: number, sceneName: string, fileName: string): any;
|
||||
bakeReflectionProbe(files: string[], isHDR: boolean, sceneName:string, probeID: number, callback: Function): any
|
||||
}
|
||||
|
||||
interface EditorExtendsUuid {
|
||||
NonUuidMark: string;
|
||||
compressUuid(uuid: string, min: boolean): string;
|
||||
compressHex(hexString: string, reservedHeadLength: number): string;
|
||||
decompressUuid(str: string): string;
|
||||
isUuid(str: string): boolean;
|
||||
getUuidFromLibPath(path: string): string;
|
||||
uuid(): string;
|
||||
}
|
||||
|
||||
declare namespace EditorExtends {
|
||||
const Script: EditorExtendsScript;
|
||||
const Node: EditorExtendsNode;
|
||||
const Component: EditorExtendsComponent;
|
||||
const Asset: EditorExtendsAsset;
|
||||
const UuidUtils: EditorExtendsUuid;
|
||||
const PrefabUtils:EditorExtendsPrefabUtils;
|
||||
const MissingReporter: {
|
||||
classInstance: any;
|
||||
class: any;
|
||||
object: any;
|
||||
};
|
||||
|
||||
const serialize: any;
|
||||
|
||||
interface EventMap {
|
||||
/**
|
||||
* Called when a cc-class is registered.
|
||||
* @param classConstructor Registering class.
|
||||
*/
|
||||
'class-registered'(classConstructor: Function, metadata: Readonly<any> | undefined, className: string): void;
|
||||
}
|
||||
|
||||
type EventArgs<EventName extends keyof EventMap> = Parameters<EventMap[EventName]>;
|
||||
|
||||
type Listener<EventName extends keyof EventMap> = (...args: EventArgs<EventName>) => void;
|
||||
|
||||
function emit<EventName extends keyof EventMap>(name: EventName, ...args: EventArgs<EventName>): void;
|
||||
|
||||
function on<EventName extends keyof EventMap>(name: EventName, listener: Listener<EventName>): void;
|
||||
|
||||
function removeListener<EventName extends keyof EventMap>(name: EventName, listener: Listener<EventName>): void;
|
||||
}
|
||||
Vendored
-128
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
declare const gfx: any;
|
||||
declare const global: any;
|
||||
declare const xr: any;
|
||||
|
||||
interface Window {
|
||||
|
||||
[x: string]: any;
|
||||
|
||||
WebGL2RenderingContext: any;
|
||||
|
||||
sharedCanvas: any;
|
||||
__canvas: any;
|
||||
canvas: any;
|
||||
|
||||
XMLHttpRequest: any;
|
||||
mozRequestAnimationFrame(callback: any, element?: any): any;
|
||||
oRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msRequestAnimationFrame(callback: any, element?: any): any;
|
||||
cancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
mozCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
oCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
webkitCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msCancelAnimationFrame(callback: any, element?: any): any;
|
||||
mozCancelAnimationFrame(callback: any, element?: any): any;
|
||||
ocancelAnimationFrame(callback: any, element?: any): any;
|
||||
}
|
||||
|
||||
interface Document {
|
||||
mozHidden: any;
|
||||
msHidden: any;
|
||||
webkitHidden: any;
|
||||
}
|
||||
|
||||
interface HTMLElement {
|
||||
content: any;
|
||||
name: any;
|
||||
}
|
||||
|
||||
declare type CompareFunction<T> = (a: T, b: T) => number;
|
||||
|
||||
declare type RecursivePartial<T> = {
|
||||
[P in keyof T]?:
|
||||
T[P] extends Array<infer U> ? Array<RecursivePartial<U>> :
|
||||
T[P] extends ReadonlyArray<infer V> ? ReadonlyArray<RecursivePartial<V>> : RecursivePartial<T[P]>;
|
||||
};
|
||||
|
||||
declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array |
|
||||
Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
|
||||
|
||||
declare type TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor |
|
||||
Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor |
|
||||
Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
||||
|
||||
declare interface IWritableArrayLike<T> {
|
||||
readonly length: number;
|
||||
[index: number]: T;
|
||||
}
|
||||
|
||||
declare type Constructor<T = unknown> = new (...args: any[]) => T;
|
||||
|
||||
declare type AbstractedConstructor<T = unknown> = abstract new (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* Alias of `Function` but suppress eslint warning.
|
||||
* Please avoid using it and explicitly specify function signatures as possible.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
declare type AnyFunction = Function;
|
||||
|
||||
declare type Mutable<T> = { -readonly [P in keyof T]: T[P] };
|
||||
|
||||
declare type Getter = () => any;
|
||||
|
||||
declare type Setter = (value: any) => void;
|
||||
|
||||
declare const Buffer: any;
|
||||
|
||||
declare type EnumAlias<EnumT> = EnumT[keyof EnumT];
|
||||
|
||||
declare module 'internal:native' {}
|
||||
|
||||
/**
|
||||
* Only declare on minigame platforms.
|
||||
*/
|
||||
declare const GameGlobal: any;
|
||||
|
||||
/**
|
||||
* only implemented on Editor.
|
||||
*/
|
||||
declare const Editor: any;
|
||||
|
||||
/**
|
||||
* To provide a safe Record type, if you want to enable checking index access on Object, please use SafeRecord instead of Record.
|
||||
* we provide this type because we don't want to enable `noUncheckedIndexedAccess` in tsconfig.json for it's noisy for a lot of code.
|
||||
*/
|
||||
type SafeRecord<T extends (string | number | symbol), K> = Record<T, K | undefined>;
|
||||
/**
|
||||
* To provide a safe Array type, if you want to enable checking index access on Array, please use SafeArray instead of Array.
|
||||
* we provide this type because we don't want to enable `noUncheckedIndexedAccess` in tsconfig.json for it's noisy for a lot of code.
|
||||
*/
|
||||
type SafeArray<T> = Array<T | undefined>;
|
||||
Vendored
-800
@@ -1,800 +0,0 @@
|
||||
// some interfaces might be overridden
|
||||
/* eslint-disable import/no-mutable-exports */
|
||||
|
||||
/**
|
||||
* API for jsb module
|
||||
* Author: haroel
|
||||
* Homepage: https://github.com/haroel/creatorexDTS
|
||||
*
|
||||
* @deprecated since v3.6.0, please import `native` from 'cc' module instead like `import { native } from 'cc';`.
|
||||
*/
|
||||
declare namespace jsb {
|
||||
|
||||
let window: any;
|
||||
|
||||
type AccelerationXYZ = number;
|
||||
type AccelerationIncludingGravityXYZ = number;
|
||||
type RotationRateAlpha = number;
|
||||
type RotationRateBeta = number;
|
||||
type RotationRateGamma = number;
|
||||
type DeviceMotionValue = [AccelerationXYZ, AccelerationXYZ, AccelerationXYZ,
|
||||
AccelerationIncludingGravityXYZ, AccelerationIncludingGravityXYZ, AccelerationIncludingGravityXYZ,
|
||||
RotationRateAlpha, RotationRateBeta, RotationRateGamma];
|
||||
export namespace device {
|
||||
export function getBatteryLevel(): number;
|
||||
export function getDevicePixelRatio(): number;
|
||||
export function getDeviceOrientation(): number;
|
||||
export function getNetworkType(): number; // TODO: enum type
|
||||
export function getSafeAreaEdge(): NativeSafeAreaEdge;
|
||||
export function setKeepScreenOn(enabled: boolean): void;
|
||||
|
||||
export function setAccelerometerEnabled(isEnabled: boolean);
|
||||
export function setAccelerometerInterval(intervalInSeconds: number);
|
||||
export function getDeviceMotionValue(): DeviceMotionValue;
|
||||
}
|
||||
|
||||
export interface NativeSafeAreaEdge {
|
||||
/**
|
||||
* top
|
||||
*/
|
||||
x: number;
|
||||
/**
|
||||
* left
|
||||
*/
|
||||
y: number;
|
||||
/**
|
||||
* bottom
|
||||
*/
|
||||
z: number;
|
||||
/**
|
||||
* right
|
||||
*/
|
||||
w: number;
|
||||
}
|
||||
|
||||
export interface MouseEvent {
|
||||
x: number,
|
||||
y: number,
|
||||
xDelta: number | undefined,
|
||||
yDelta: number | undefined,
|
||||
button: number,
|
||||
windowId: number,
|
||||
}
|
||||
type MouseEventCallback = (mouseEvent: MouseEvent) => void;
|
||||
export interface MouseWheelEvent extends MouseEvent {
|
||||
wheelDeltaX: number,
|
||||
wheelDeltaY: number,
|
||||
}
|
||||
type MouseWheelEventCallback = (mouseEvent: MouseWheelEvent) => void;
|
||||
export let onMouseDown: MouseEventCallback | undefined;
|
||||
export let onMouseMove: MouseEventCallback | undefined;
|
||||
export let onMouseUp: MouseEventCallback | undefined;
|
||||
export let onMouseWheel: MouseWheelEventCallback | undefined;
|
||||
|
||||
type TouchEventCallback = (touchList: TouchList, windowId?: number) => void;
|
||||
export let onTouchStart: TouchEventCallback | undefined;
|
||||
export let onTouchMove: TouchEventCallback | undefined;
|
||||
export let onTouchEnd: TouchEventCallback | undefined;
|
||||
export let onTouchCancel: TouchEventCallback | undefined;
|
||||
|
||||
export interface ControllerInfo {
|
||||
id: number;
|
||||
axisInfoList: AxisInfo[],
|
||||
buttonInfoList: ButtonInfo[],
|
||||
touchInfoList: TouchInfo[],
|
||||
}
|
||||
|
||||
export interface AxisInfo {
|
||||
code: number,
|
||||
value: number,
|
||||
}
|
||||
|
||||
export interface ButtonInfo {
|
||||
code: number,
|
||||
isPressed: boolean,
|
||||
}
|
||||
|
||||
export interface TouchInfo {
|
||||
code: number,
|
||||
value: number,
|
||||
}
|
||||
|
||||
export let onControllerInput: (infoList: ControllerInfo[]) => void | undefined;
|
||||
export let onHandleInput: (infoList: ControllerInfo[]) => void | undefined;
|
||||
export let onControllerChange: (controllerIds: number[]) => void | undefined;
|
||||
|
||||
export interface PoseInfo {
|
||||
code: number,
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
quaternionX: number,
|
||||
quaternionY: number,
|
||||
quaternionZ: number,
|
||||
quaternionW: number,
|
||||
}
|
||||
|
||||
export let onHandlePoseInput: (infoList: PoseInfo[]) => void | undefined;
|
||||
export let onHMDPoseInput: (infoList: PoseInfo[]) => void | undefined;
|
||||
export let onHandheldPoseInput: (infoList: PoseInfo[]) => void | undefined;
|
||||
|
||||
export interface KeyboardEvent {
|
||||
altKey: boolean;
|
||||
ctrlKey: boolean;
|
||||
metaKey: boolean;
|
||||
shiftKey: boolean;
|
||||
repeat: boolean;
|
||||
keyCode: number;
|
||||
windowId: number;
|
||||
code: string;
|
||||
}
|
||||
type KeyboardEventCallback = (keyboardEvent: KeyboardEvent) => void;
|
||||
export let onKeyDown: KeyboardEventCallback | undefined;
|
||||
export let onKeyUp: KeyboardEventCallback | undefined;
|
||||
|
||||
export interface WindowEvent {
|
||||
windowId: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en WindowEvent.width and WindowEvent.height have both been multiplied by DPR
|
||||
* @zh WindowEvent.width 和 WindowEvent.height 都已乘以 DPR
|
||||
*/
|
||||
export let onResize: (event: WindowEvent) => void | undefined;
|
||||
export let onOrientationChanged: (event: { orientation: number }) => void | undefined; // TODO: enum orientation type
|
||||
export let onResume: () => void | undefined;
|
||||
export let onPause: () => void | undefined;
|
||||
export let onClose: () => void | undefined;
|
||||
export let onWindowLeave: () => void | undefined;
|
||||
export let onWindowEnter: () => void | undefined;
|
||||
export function openURL(url: string): void;
|
||||
export function garbageCollect(): void;
|
||||
enum AudioFormat {
|
||||
UNKNOWN,
|
||||
SIGNED_8,
|
||||
UNSIGNED_8,
|
||||
SIGNED_16,
|
||||
UNSIGNED_16,
|
||||
SIGNED_32,
|
||||
UNSIGNED_32,
|
||||
FLOAT_32,
|
||||
FLOAT_64
|
||||
}
|
||||
interface PCMHeader {
|
||||
totalFrames: number;
|
||||
sampleRate: number;
|
||||
bytesPerFrame: number;
|
||||
audioFormat: AudioFormat;
|
||||
channelCount: number;
|
||||
}
|
||||
export namespace AudioEngine {
|
||||
export function preload(url: string, cb: (isSuccess: boolean) => void);
|
||||
|
||||
export function play2d(url: string, loop: boolean, volume: number): number;
|
||||
export function pause(id: number);
|
||||
export function pauseAll();
|
||||
export function resume(id: number);
|
||||
export function resumeAll();
|
||||
export function stop(id: number);
|
||||
export function stopAll();
|
||||
|
||||
export function getPlayingAudioCount(): number;
|
||||
export function getMaxAudioInstance(): number;
|
||||
export function getState(id: number): any;
|
||||
export function getDuration(id: number): number;
|
||||
export function getVolume(id: number): number;
|
||||
export function isLoop(id: number): boolean;
|
||||
export function getCurrentTime(id: number): number;
|
||||
|
||||
export function setVolume(id: number, val: number);
|
||||
export function setLoop(id: number, val: boolean);
|
||||
export function setCurrentTime(id: number, val: number);
|
||||
|
||||
export function uncache(url: string);
|
||||
export function uncacheAll();
|
||||
export function setErrorCallback(id: number, cb: (err: any) => void);
|
||||
export function setFinishCallback(id: number, cb: () => void);
|
||||
|
||||
/**
|
||||
* Get PCM header without pcm data. if you want to get pcm data, use getOriginalPCMBuffer instead
|
||||
*/
|
||||
export function getPCMHeader(url: string): PCMHeader;
|
||||
/**
|
||||
* Get PCM Data in decode format for example Int16Array, the format information is written in PCMHeader.
|
||||
* @param url: file relative path, for example player._path
|
||||
* @param channelID: ChannelID which should smaller than channel count, start from 0
|
||||
*/
|
||||
export function getOriginalPCMBuffer(url: string, channelID: number): ArrayBuffer | undefined;
|
||||
}
|
||||
|
||||
class NativePOD {
|
||||
underlyingData(): ArrayBuffer;
|
||||
_data(): TypedArray;
|
||||
__data: TypedArray;
|
||||
}
|
||||
|
||||
export class Color extends NativePOD {
|
||||
}
|
||||
export class Quat extends NativePOD {
|
||||
}
|
||||
export class Vec2 extends NativePOD {
|
||||
}
|
||||
export class Vec3 extends NativePOD {
|
||||
}
|
||||
export class Vec4 extends NativePOD {
|
||||
}
|
||||
|
||||
export class Mat3 extends NativePOD {
|
||||
}
|
||||
export class Mat4 extends NativePOD {
|
||||
}
|
||||
export interface ManifestAsset {
|
||||
md5: string;
|
||||
path: string;
|
||||
compressed: boolean;
|
||||
size: number;
|
||||
downloadState: number;
|
||||
}
|
||||
|
||||
export class Manifest {
|
||||
constructor(manifestUrl: string);
|
||||
constructor(content: string, manifestRoot: string);
|
||||
parseFile(manifestUrl: string): void;
|
||||
parseJSONString(content: string, manifestRoot: string): void;
|
||||
|
||||
getManifestRoot(): string;
|
||||
getManifestFileUrl(): string;
|
||||
getVersionFileUrl(): string;
|
||||
getSearchPaths(): [string];
|
||||
getVersion(): string;
|
||||
getPackageUrl(): boolean;
|
||||
|
||||
setUpdating(isUpdating: boolean): void;
|
||||
isUpdating(): boolean;
|
||||
isVersionLoaded(): boolean;
|
||||
isLoaded(): boolean;
|
||||
}
|
||||
|
||||
export class EventAssetsManager {
|
||||
// EventCode
|
||||
static ERROR_NO_LOCAL_MANIFEST: number;
|
||||
static ERROR_DOWNLOAD_MANIFEST: number;
|
||||
static ERROR_PARSE_MANIFEST: number;
|
||||
static NEW_VERSION_FOUND: number;
|
||||
static ALREADY_UP_TO_DATE: number;
|
||||
static UPDATE_PROGRESSION: number;
|
||||
static ASSET_UPDATED: number;
|
||||
static ERROR_UPDATING: number;
|
||||
static UPDATE_FINISHED: number;
|
||||
static UPDATE_FAILED: number;
|
||||
static ERROR_DECOMPRESS: number;
|
||||
|
||||
constructor(eventName: string, manager: AssetsManager, eventCode: number,
|
||||
assetId?: string, message?: string, curleCode?: number, curlmCode?: number);
|
||||
getAssetsManagerEx(): AssetsManager;
|
||||
isResuming(): boolean;
|
||||
|
||||
getDownloadedFiles(): number;
|
||||
getDownloadedBytes(): number;
|
||||
getTotalFiles(): number;
|
||||
getTotalBytes(): number;
|
||||
getPercent(): number;
|
||||
getPercentByFile(): number;
|
||||
|
||||
getEventCode(): number;
|
||||
getMessage(): string;
|
||||
getAssetId(): string;
|
||||
getCURLECode(): number;
|
||||
getCURLMCode(): number;
|
||||
}
|
||||
|
||||
export namespace AssetsManager {
|
||||
export enum State {
|
||||
UNINITED,
|
||||
UNCHECKED,
|
||||
PREDOWNLOAD_VERSION,
|
||||
DOWNLOADING_VERSION,
|
||||
VERSION_LOADED,
|
||||
PREDOWNLOAD_MANIFEST,
|
||||
DOWNLOADING_MANIFEST,
|
||||
MANIFEST_LOADED,
|
||||
NEED_UPDATE,
|
||||
READY_TO_UPDATE,
|
||||
UPDATING,
|
||||
UNZIPPING,
|
||||
UP_TO_DATE,
|
||||
FAIL_TO_UPDATE,
|
||||
}
|
||||
}
|
||||
|
||||
export class AssetsManager {
|
||||
constructor(manifestUrl: string, storagePath: string, versionCompareHandle?: (versionA: string, versionB: string) => number);
|
||||
static create(manifestUrl: string, storagePath: string): AssetsManager;
|
||||
|
||||
getState(): AssetsManager.State;
|
||||
getStoragePath(): string
|
||||
getMaxConcurrentTask(): number;
|
||||
// setMaxConcurrentTask (max: number): void; // actually not supported
|
||||
|
||||
checkUpdate(): void;
|
||||
prepareUpdate(): void;
|
||||
update(): void;
|
||||
isResuming(): boolean;
|
||||
cancelUpdate(): void;
|
||||
|
||||
getDownloadedFiles(): number;
|
||||
getDownloadedBytes(): number;
|
||||
getTotalFiles(): number;
|
||||
getTotalBytes(): number;
|
||||
downloadFailedAssets(): void;
|
||||
|
||||
getLocalManifest(): Manifest;
|
||||
loadLocalManifest(manifestUrl: string): boolean;
|
||||
loadLocalManifest(localManifest: Manifest, storagePath: string): boolean;
|
||||
getRemoteManifest(): Manifest;
|
||||
loadRemoteManifest(remoteManifest: Manifest): boolean;
|
||||
|
||||
/**
|
||||
* Setup your own version compare handler, versionA and B is versions in string.
|
||||
* if the return value greater than 0, versionA is greater than B,
|
||||
* if the return value equals 0, versionA equals to B,
|
||||
* if the return value smaller than 0, versionA is smaller than B.
|
||||
*/
|
||||
setVersionCompareHandle(versionCompareHandle?: (versionA: string, versionB: string) => number): void;
|
||||
/**
|
||||
* Setup the verification callback, Return true if the verification passed, otherwise return false
|
||||
*/
|
||||
setVerifyCallback(verifyCallback: (path: string, asset: ManifestAsset) => boolean): void;
|
||||
setEventCallback(eventCallback: (event: EventAssetsManager) => void): void;
|
||||
}
|
||||
|
||||
// Android ADPF module
|
||||
const adpf: {
|
||||
readonly thermalHeadroom: number;
|
||||
readonly thermalStatus: number;
|
||||
readonly thermalStatusMin: number;
|
||||
readonly thermalStatusMax: number;
|
||||
readonly thermalStatusNormalized: number;
|
||||
onThermalStatusChanged?: (previousStatus: number, newStatus: number, statusMin: number, statusMax: number) => void;
|
||||
} | undefined;
|
||||
|
||||
export class PlayException {
|
||||
/**
|
||||
* @en Getting Exception message.
|
||||
* @zh 获取异常信息。
|
||||
*/
|
||||
getMessage(): string;
|
||||
/**
|
||||
* @en Returns the name of the exception in the local language of the user (Chinese etc.).
|
||||
* @zh 用户的本地语言(中文等)返回异常名称。
|
||||
*/
|
||||
getLocalizedMessage(): string;
|
||||
/**
|
||||
* @en Print the exception stack.
|
||||
* @zh 打印异常堆栈。
|
||||
*/
|
||||
printStackTrace(): void;
|
||||
/**
|
||||
* @en To string.
|
||||
* @zh 转换成字符串。
|
||||
*/
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export interface OnCanceledListener {
|
||||
/**
|
||||
* @en Called when the Task is canceled successfully.
|
||||
* @zh 当任务成功取消时调用。
|
||||
*/
|
||||
onCanceled(): void;
|
||||
}
|
||||
|
||||
export interface OnCompleteListener {
|
||||
/**
|
||||
* @en Called when the Task completes.
|
||||
* @zh 任务完成时调用。
|
||||
*/
|
||||
onComplete(task: any): void;
|
||||
}
|
||||
|
||||
export interface OnFailureListener {
|
||||
/**
|
||||
* @en Called when the Task fails with an exception.
|
||||
* @zh 当任务因异常而失败时调用。
|
||||
*/
|
||||
onFailure(e: PlayException): void;
|
||||
}
|
||||
|
||||
export interface OnSuccessListener {
|
||||
/**
|
||||
* @en Called when the Task completes successfully.
|
||||
* @zh 成功完成时调用 Task 。
|
||||
*/
|
||||
onSuccess(result: any): void;
|
||||
}
|
||||
|
||||
export interface OnContinueWithListener {
|
||||
/**
|
||||
* @en Returns the result of applying this Continuation to task.
|
||||
* @zh 返回将此 Continuation 应用到 的结果 task 。
|
||||
*/
|
||||
then(result: any): void;
|
||||
}
|
||||
|
||||
export class PlayTask {
|
||||
/**
|
||||
* @en Adds a listener that is called if the Task is canceled.
|
||||
* @zh 添加一个侦听器,当任务被取消时调用该侦听器。
|
||||
*/
|
||||
public addOnCanceledListener(listener: OnCanceledListener): PlayTask;
|
||||
/**
|
||||
* @en Adds a listener that is called when the Task completes.
|
||||
* @zh 添加在任务完成时调用的监听器。
|
||||
*/
|
||||
public addOnCompleteListener(listener: OnCompleteListener): PlayTask;
|
||||
/**
|
||||
* @en Adds a listener that is called if the Task fails.
|
||||
* @zh 添加一个在任务失败时调用的监听器。
|
||||
*/
|
||||
public addOnFailureListener(listener: OnFailureListener): PlayTask;
|
||||
/**
|
||||
* @en Adds a listener that is called if the Task completes successfully.
|
||||
* @zh 添加一个侦听器,当任务成功完成时调用该侦听器。
|
||||
*/
|
||||
public addOnSuccessListener(listener: OnSuccessListener): PlayTask;
|
||||
/**
|
||||
* @en Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
|
||||
* @zh 返回一个新任务,该任务将通过将指定的延续应用于此任务的结果来完成。
|
||||
*/
|
||||
public continueWith(listener: OnContinueWithListener): PlayTask;
|
||||
/**
|
||||
* @en Gets the result of the Task, if it has already completed.
|
||||
* @zh 如果任务已经完成,则获取任务的结果。
|
||||
*/
|
||||
public getResult(listener: OnSuccessListener): any;
|
||||
/**
|
||||
* @en Returns true if the Task is canceled; false otherwise.
|
||||
* @zh true 如果任务被取消则返回;false 否则返回。
|
||||
*/
|
||||
public isCanceled(): boolean;
|
||||
/**
|
||||
* @en Returns true if the Task is complete; false otherwise.
|
||||
* @zh true 如果任务完成则返回;false 否则返回。
|
||||
*/
|
||||
public isComplete(): boolean;
|
||||
/**
|
||||
* @en Returns true if the Task has completed successfully; false otherwise.
|
||||
* @zh true 如果任务已成功完成则返回;false 否则返回。
|
||||
*/
|
||||
public isSuccessful(): boolean;
|
||||
}
|
||||
/**
|
||||
* @en Represents the current authentication status with Play Games Services.
|
||||
* @zh 代表 Play Games Services 的当前身份验证状态。
|
||||
*/
|
||||
export class AuthenticationResult {
|
||||
private constructor();
|
||||
/**
|
||||
* @en Returns true if your game is authenticated to Play Games Services.
|
||||
* @zh 返回true表示您的游戏已通过 Play Games Services 的身份验证。
|
||||
*/
|
||||
public isAuthenticated(): boolean;
|
||||
}
|
||||
/**
|
||||
* @en Contains the result of RecallClient.requestRecallAccess().
|
||||
* @zh 包含 RecallClient.requestRecallAccess() 的返回结果
|
||||
*/
|
||||
export class RecallAccess {
|
||||
private constructor();
|
||||
/**
|
||||
* @en Hash code
|
||||
* @zh hash值
|
||||
*/
|
||||
public hashCode(): number;
|
||||
/**
|
||||
* @en Returns the session id to be passed into PGS server API.
|
||||
* @zh 返回要传递到 PGS server API 的会话 ID。
|
||||
*/
|
||||
public getSessionId(): string;
|
||||
/**
|
||||
* @en Is it equal to another RecallAccess.
|
||||
* @zh 判断与另一个 RecallAccess 是否相等。
|
||||
*/
|
||||
public equals(other: RecallAccess): boolean;
|
||||
}
|
||||
/**
|
||||
* @en A client for performing sign-in with Play Games Services.
|
||||
* @zh 用于使用 Play Games Services 执行登录的客户端。
|
||||
*/
|
||||
export class GamesSignInClient {
|
||||
/**
|
||||
* @en Returns the current authentication status via an AuthenticationResult.
|
||||
* @zh 通过 返回当前身份验证状态 AuthenticationResult 。
|
||||
*/
|
||||
public isAuthenticated(): PlayTask;
|
||||
/**
|
||||
* @en Requests server-side access to Play Games Services for the currently signed-in player.
|
||||
* @zh 向当前登录的玩家请求服务器端访问 Play Games Services。
|
||||
*/
|
||||
public requestServerSideAccess(serverClientId: string, forceRefreshToken: boolean): PlayTask;
|
||||
/**
|
||||
* @en Manually requests that your game sign in with Play Games Services.
|
||||
* @zh 手动请求您的游戏通过 Play Games Services 登录。
|
||||
*/
|
||||
public signIn(): PlayTask;
|
||||
}
|
||||
/**
|
||||
* @en Data interface for retrieving achievement information.
|
||||
* @zh 用于检索成就信息的数据接口。
|
||||
*/
|
||||
export class Achievement {
|
||||
/**
|
||||
* @en Constant returned by getState() indicating an unlocked achievement.
|
||||
* @zh getState 返回的常量表示未解锁的成就。
|
||||
*/
|
||||
public static STATE_UNLOCKED: number;
|
||||
/**
|
||||
* @en Constant returned by getState() indicating a revealed achievement.
|
||||
* @zh getState 返回的常量表示已显示的成就。
|
||||
*/
|
||||
public static STATE_REVEALED: number;
|
||||
/**
|
||||
* @en Constant returned by getState() indicating a hidden achievement.
|
||||
* @zh getState 返回的常量表示隐藏的成就。
|
||||
*/
|
||||
public static STATE_HIDDEN: number;
|
||||
/**
|
||||
* @en Constant returned by getType() indicating a standard achievement.
|
||||
* @zh getState 返回的常量表示标准的成就。
|
||||
*/
|
||||
public static TYPE_STANDARD: number;
|
||||
/**
|
||||
* @en Constant returned by getType() indicating an incremental achievement.
|
||||
* @zh getState 返回的常量表示增量的成就。
|
||||
*/
|
||||
public static TYPE_INCREMENTAL: number;
|
||||
/**
|
||||
* @en Retrieves the number of steps this user has gone toward unlocking this achievement;
|
||||
* only applicable for TYPE_INCREMENTAL achievement types.
|
||||
* @zh 检索该用户为解锁该成就所走的步数;仅适用于 TYPE_INCREMENTAL 成就类型。
|
||||
*/
|
||||
public getCurrentSteps(): number;
|
||||
/**
|
||||
* @en Returns the Achievement.AchievementState of the achievement.
|
||||
* @zh 返回 Achievement.AchievementState 成就。
|
||||
*/
|
||||
public getState(): number;
|
||||
/**
|
||||
* @en Retrieves the total number of steps necessary to unlock this achievement; only applicable for TYPE_INCREMENTAL achievement types
|
||||
* @zh 检索解锁此成就所需的总步数;仅适用于 TYPE_INCREMENTAL 成就类型。
|
||||
*/
|
||||
public getTotalSteps(): number;
|
||||
/**
|
||||
* @en Returns the Achievement.AchievementType of this achievement.
|
||||
* @zh 返回 Achievement.AchievementType 此成就。
|
||||
*/
|
||||
public getType(): number;
|
||||
/**
|
||||
* @en Retrieves the timestamp (in millseconds since epoch) at which this achievement was last updated.
|
||||
* @zh 检索此成就最后更新的时间戳(以纪元以来的毫秒数为单位)。
|
||||
*/
|
||||
public getLastUpdatedTimestamp(): number;
|
||||
/**
|
||||
* @en Retrieves the XP value of this achievement.
|
||||
* @zh 检索此成就的 XP 值。
|
||||
*/
|
||||
public getXpValue(): number;
|
||||
/**
|
||||
* @en Retrieves the ID of this achievement.
|
||||
* @zh 检索此成就的 ID。
|
||||
*/
|
||||
public getAchievementId(): string;
|
||||
/**
|
||||
* @en Retrieves the description for this achievement.
|
||||
* @zh 检索此成就的描述。
|
||||
*/
|
||||
public getDescription(): string;
|
||||
/**
|
||||
* @enRetrieves the number of steps this user has gone toward unlocking this achievement
|
||||
* (formatted for the user's locale); only applicable for TYPE_INCREMENTAL achievement types.
|
||||
* @zh 检索该用户为解锁此成就所经过的步数(根据用户的语言环境格式化);仅适用于 TYPE_INCREMENTAL成就类型。
|
||||
*/
|
||||
public getFormattedCurrentSteps(): string;
|
||||
/**
|
||||
* @en Loads the total number of steps necessary to unlock this achievement
|
||||
* (formatted for the user's locale) into the given CharArrayBuffer; only applicable for TYPE_INCREMENTAL achievement types.
|
||||
* @zh 检索解锁此成就所需的总步数;仅适用于 TYPE_INCREMENTAL 成就类型。
|
||||
*/
|
||||
public getFormattedTotalSteps(): string;
|
||||
/**
|
||||
* @en Retrieves the name of this achievement.
|
||||
* @zh 检索此成就的名称。
|
||||
*/
|
||||
public getName(): string;
|
||||
/**
|
||||
* @en Retrieves a URI that can be used to load the achievement's revealed image icon.
|
||||
* @zh 检索可用于加载成就显示图像图标的 URI。
|
||||
*/
|
||||
public getRevealedImageUrl(): string;
|
||||
/**
|
||||
* @en Retrieves a URI that can be used to load the achievement's unlocked image icon.
|
||||
* @zh 检索可用于加载成就的解锁图像图标的 URI。
|
||||
*/
|
||||
public getUnlockedImageUrl(): string;
|
||||
}
|
||||
/**
|
||||
* @en Data structure providing access to a list of achievements.
|
||||
* @zh 提供访问成就列表的数据结构。
|
||||
*/
|
||||
export class AchievementBuffer {
|
||||
/**
|
||||
* @en Get the count of achievement.
|
||||
* @zh 获取 achievement 的数量 。
|
||||
*/
|
||||
public getCount(): number;
|
||||
/**
|
||||
* @en Get the item at the specified position.
|
||||
* @zh 获取指定位置的物品。
|
||||
*/
|
||||
public get(i: number): Achievement;
|
||||
/**
|
||||
* @en Releases the data buffer, for use in try-with-resources.
|
||||
* @zh 释放数据缓冲区,以供在 try-with-resources 中使用。
|
||||
*/
|
||||
public close(): void;
|
||||
/**
|
||||
* @en Releases resources used by the buffer.
|
||||
* @zh 释放缓冲区使用的资源。
|
||||
*/
|
||||
public release(): void;
|
||||
}
|
||||
/**
|
||||
* @en Class to return annotated data. Currently, the only annotation is whether the data is stale or not.
|
||||
* @zh 用于返回带 annotated 数据的类。目前,唯一的 annotated 是数据是否过时。
|
||||
*/
|
||||
export class AnnotatedData {
|
||||
/**
|
||||
* @en Returns true if the data returned by get() is stale.
|
||||
* @zh true如果返回的数据已过时,则返回 get() 。
|
||||
*/
|
||||
public isStale(): boolean;
|
||||
/**
|
||||
* @en Returns the data that is annotated by this class.
|
||||
* @zh 返回由此类 annotated 的数据。
|
||||
*/
|
||||
public get(): AchievementBuffer;
|
||||
}
|
||||
/**
|
||||
* @en A client to interact with achievements functionality.
|
||||
* @zh 与 Achievements 功能交互的客户端。
|
||||
*/
|
||||
export class AchievementsClient {
|
||||
/**
|
||||
* @en Show default achievement page.
|
||||
* @zh 显示默认的成就页面。
|
||||
*/
|
||||
public showAchievements(): void;
|
||||
/**
|
||||
* @en Returns a Task which asynchronously increments an achievement by the given number of steps.
|
||||
* @zh 返回一个 Task 以给定步数异步增加成就的方法。
|
||||
*/
|
||||
public incrementImmediate(id: string, numSteps: number): PlayTask;
|
||||
/**
|
||||
* @en Returns a Task which asynchronously loads an annotated AchievementBuffer that represents the achievement data.
|
||||
* for the currently signed-in player.
|
||||
* @zh 返回一个 Task 异步加载的task, AchievementBuffer该注释代表当前登录玩家的成就数据。
|
||||
*/
|
||||
public load(forceReload: boolean): PlayTask;
|
||||
/**
|
||||
* @en Returns a Task which asynchronously reveals a hidden achievement to the currently signed in player.
|
||||
* @zh 返回一个 Task 异步向当前登录的玩家显示隐藏成就的对象。
|
||||
*/
|
||||
public revealImmediate(id: string): PlayTask;
|
||||
/**
|
||||
* @en Returns a Task which asynchronously sets an achievement to have at least the given number of steps completed.
|
||||
* @zh 返回一个 Task 异步设置成就以至少完成给定数量的步骤。
|
||||
*/
|
||||
public setStepsImmediate(id: string, numSteps: number): PlayTask;
|
||||
/**
|
||||
* @en Returns a Task which asynchronously unlocks an achievement for the currently signed in player.
|
||||
* @zh 返回一个 Task 异步解锁当前登录玩家的成就。
|
||||
*/
|
||||
public unlockImmediate(id: string): PlayTask;
|
||||
/**
|
||||
* @en Increments an achievement by the given number of steps.
|
||||
* @zh 按给定的步数增加成就。
|
||||
*/
|
||||
public increment(id: string, numSteps: number): void;
|
||||
/**
|
||||
* @en Reveals a hidden achievement to the currently signed-in player.
|
||||
* @zh 向当前登录的玩家揭示隐藏的成就。
|
||||
*/
|
||||
public reveal(id: string): void;
|
||||
/**
|
||||
* @en Sets an achievement to have at least the given number of steps completed.
|
||||
* @zh 设置一项成就,至少完成给定数量的步骤。
|
||||
*/
|
||||
public setSteps(id: string, numSteps: number): void;
|
||||
/**
|
||||
* @en Unlocks an achievement for the currently signed in player.
|
||||
* @zh 为当前登录的玩家解锁一项成就。
|
||||
*/
|
||||
public unlock(id: string): void;
|
||||
}
|
||||
/**
|
||||
* @en A client for the recall functionality.
|
||||
* @zh Recall 功能客户端。
|
||||
*/
|
||||
export class RecallClient {
|
||||
/**
|
||||
* @en Returns a RecallAccess to use for server-to-server communication between the 3p game server and Play Games Services server.
|
||||
* @zh 返回 RecallAccess 用于第三方游戏服务器和 Play 游戏服务服务器之间的服务器到服务器通信。
|
||||
*/
|
||||
public requestRecallAccess(): PlayTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Main entry point for the Games APIs. This class provides APIs and interfaces to access the Google Play Games Services functionality.
|
||||
* @zh 游戏 API 的主要入口点。此类提供用于访问 Google Play Games Services 功能的 API 和接口。
|
||||
*/
|
||||
export class PlayGames {
|
||||
/**
|
||||
* @en Returns a new instance of AchievementsClient.
|
||||
* @zh 返回一个新的 AchievementsClient 实例。
|
||||
*/
|
||||
public static getAchievementsClient(): AchievementsClient;
|
||||
/**
|
||||
* @en Returns a new instance of GamesSignInClient.
|
||||
* @zh 返回一个新的 GamesSignInClient 实例。
|
||||
*/
|
||||
public static getGamesSignInClient(): GamesSignInClient;
|
||||
/**
|
||||
* @en Returns a new instance of RecallClient.
|
||||
* @zh 返回一个新的 RecallClient 实例。
|
||||
*/
|
||||
public static getRecallClient(): RecallClient;
|
||||
}
|
||||
/**
|
||||
* @en Entry point for the Play Games SDK.
|
||||
* @zh Play Games SDK 的入口点。
|
||||
*/
|
||||
export class PlayGamesSdk {
|
||||
/**
|
||||
* @en Initializes the Play Games SDK using the Game services application id defined in the application's manifest.
|
||||
* @zh 使用应用程序清单中定义的游戏服务应用程序 ID 初始化 Play 游戏 SDK。
|
||||
*/
|
||||
public static initialize(): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace ns {
|
||||
|
||||
class NativePOD {
|
||||
underlyingData(): ArrayBuffer;
|
||||
_arraybuffer(): ArrayBuffer;
|
||||
}
|
||||
export class Line extends jsb.NativePOD {
|
||||
}
|
||||
export class Plane extends jsb.NativePOD {
|
||||
}
|
||||
export class Ray extends jsb.NativePOD {
|
||||
}
|
||||
export class Triangle extends jsb.NativePOD {
|
||||
}
|
||||
export class Sphere extends jsb.NativePOD {
|
||||
}
|
||||
export class AABB extends jsb.NativePOD {
|
||||
}
|
||||
export class Capsule extends jsb.NativePOD {
|
||||
}
|
||||
export class Frustum extends jsb.NativePOD {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only defined on native platforms.
|
||||
* Now we only support 'V8'
|
||||
*/
|
||||
declare const scriptEngineType: 'V8';
|
||||
Vendored
-188
@@ -1,188 +0,0 @@
|
||||
declare module 'pal/audio' {
|
||||
/**
|
||||
* Each audio instance needs to be managed, but should not take up too much memory.
|
||||
* The `OneShotAudio` is a lite version of audio class designed for audio manager.
|
||||
*/
|
||||
export class OneShotAudio {
|
||||
/**
|
||||
* Constructor for OneShotAudio.
|
||||
* This is a private constructor.
|
||||
* OneShotAudio shoulb be instantiated by `AudioPlayer.loadOneShotAudio()` method.
|
||||
* @param nativeAudio The native audio such as `HTMLAudioElement` or `AudioBuffer`.
|
||||
* @param volume Init the audio volume.
|
||||
*/
|
||||
private constructor (nativeAudio: unknown, volume: number);
|
||||
|
||||
/**
|
||||
* Play the audio.
|
||||
*/
|
||||
public play (): void;
|
||||
|
||||
/**
|
||||
* Stops playing the audio.
|
||||
*/
|
||||
public stop (): void;
|
||||
|
||||
/**
|
||||
* Get or set the onPlay callback.
|
||||
*/
|
||||
get onPlay (): () => void | undefined;
|
||||
set onPlay (cb: () => void | undefined);
|
||||
|
||||
/**
|
||||
* Get or set the onEnd callback.
|
||||
*/
|
||||
get onEnd (): () => void | undefined;
|
||||
set onEnd (cb: () => void | undefined);
|
||||
}
|
||||
|
||||
export class AudioPlayer {
|
||||
private constructor (nativeAudio: unknown);
|
||||
|
||||
/**
|
||||
* Destroys the player.
|
||||
*/
|
||||
destroy (): void;
|
||||
|
||||
/**
|
||||
* Asynchronously creates an audio player to load an audio.
|
||||
* @param url URL to the audio.
|
||||
* @param opts Load options.
|
||||
* @returns The audio player.
|
||||
*/
|
||||
static load (url: string, opts?: import('pal/audio/type').AudioLoadOptions): Promise<AudioPlayer>;
|
||||
|
||||
/**
|
||||
* Asynchronously load a native audio for playing one shot.
|
||||
* This is a basic loading method for AudioPlayer.
|
||||
* @param url URL to the audio.
|
||||
* @param opts Load options.
|
||||
* @returns The native audio such as `HTMLAudioElement` or `AudioBuffer`.
|
||||
*/
|
||||
static loadNative (url: string, opts?: import('pal/audio/type').AudioLoadOptions): Promise<unknown>;
|
||||
|
||||
/**
|
||||
* Asynchronously load an OneShotAudio instance.
|
||||
* @param url URL to the audio.
|
||||
* @param volume Specify the volume.
|
||||
* @param opts Load options.
|
||||
* @returns The OneShotAudio instance.
|
||||
*/
|
||||
static loadOneShotAudio (url: string, volume: number, opts?: import('pal/audio/type').AudioLoadOptions): Promise<OneShotAudio>;
|
||||
|
||||
/**
|
||||
* Max audio channel count allowed on current platform.
|
||||
* If the amount of playing audios exceeds the limit,
|
||||
* some audio instances would be discarded by audio manager.
|
||||
*/
|
||||
static readonly maxAudioChannel: number;
|
||||
|
||||
/**
|
||||
* Readonly property to get the url of audio src.
|
||||
*/
|
||||
get src (): string;
|
||||
|
||||
/**
|
||||
* The type of this player.
|
||||
* For WEB platform, it can be `WEB_AUDIO` or `DOM_AUDIO`.
|
||||
*/
|
||||
get type (): import('pal/audio/type').AudioType;
|
||||
|
||||
/**
|
||||
* The state of this player.
|
||||
* The state would be restored to `INIT` when the audio finished its playing.
|
||||
*/
|
||||
get state (): import('pal/audio/type').AudioState;
|
||||
|
||||
/**
|
||||
* Gets or sets whether if the playing audio should be looped.
|
||||
*/
|
||||
get loop (): boolean;
|
||||
set loop (val: boolean);
|
||||
|
||||
/**
|
||||
* The volume of this player, ranged from 0 to 1.
|
||||
*/
|
||||
get volume (): number;
|
||||
set volume (val: number);
|
||||
|
||||
/**
|
||||
* The duration of this audio player.
|
||||
*/
|
||||
get duration (): number;
|
||||
|
||||
/**
|
||||
* The current time of this player, in seconds, ranged from 0 to its total duration.
|
||||
* Note this field is immutable, if you want to set the current time, please call the seek() method instead.
|
||||
*/
|
||||
get currentTime (): number;
|
||||
|
||||
/**
|
||||
* Get the sample rate.
|
||||
*/
|
||||
get sampleRate (): number;
|
||||
|
||||
/**
|
||||
* Get pcm data view from specified channel.
|
||||
* @param channelIndex The channel index. 0 is left channel, 1 is right channel.
|
||||
*/
|
||||
public getPCMData (channelIndex: number): import('pal/audio/type').AudioPCMDataView | undefined;
|
||||
|
||||
/**
|
||||
* Asynchronously seeks the player's playing time onto specified location.
|
||||
* @param time Desired playing time.
|
||||
*/
|
||||
seek (time: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Asynchronously plays the audio or resumes the audio while it is paused.
|
||||
*/
|
||||
play (): Promise<void>;
|
||||
|
||||
/**
|
||||
* Asynchronously pauses the playing.
|
||||
*/
|
||||
pause (): Promise<void>;
|
||||
/**
|
||||
* Asynchronously stops the playing.
|
||||
*/
|
||||
stop (): Promise<void>;
|
||||
|
||||
/**
|
||||
* Registers an callback which would be called at an interruption begin.
|
||||
* The interruption includes the show/hide events, phone call/alarm, earphones un-plugging.
|
||||
* @param cb The callback.
|
||||
*/
|
||||
onInterruptionBegin (cb: () => void): void;
|
||||
|
||||
/**
|
||||
* Unregister the callback that registered to `onInterruptionBegin`.
|
||||
* @param cb The callback. If not specified, all callback would be unregistered.
|
||||
*/
|
||||
offInterruptionBegin (cb?: () => void): void;
|
||||
|
||||
/**
|
||||
* Register an callback which would be called at an interruption end.
|
||||
* @param cb The callback.
|
||||
*/
|
||||
onInterruptionEnd (cb: () => void): void;
|
||||
|
||||
/**
|
||||
* Unregister the callback that registered to `onInterruptionEnd`.
|
||||
* @param cb The callback. If not specified, all callback would be unregistered.
|
||||
*/
|
||||
offInterruptionEnd (cb?: () => void): void;
|
||||
|
||||
/**
|
||||
* Register an callback which would be called when the player finished its playing.
|
||||
* @param cb The callback.
|
||||
*/
|
||||
onEnded (cb: () => void): void;
|
||||
|
||||
/**
|
||||
* Unregister the callback that registered to `onEnded`.
|
||||
* @param cb The callback. If not specified, all callback would be unregistered.
|
||||
*/
|
||||
offEnded (cb?: () => void): void;
|
||||
}
|
||||
}
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
declare module 'pal/env' {
|
||||
export function findCanvas (): { frame: HTMLDivElement, container: HTMLDivElement, canvas: HTMLCanvasElement };
|
||||
export function loadJsFile (path: string): Promise<void>;
|
||||
}
|
||||
Vendored
-34
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Class designed for UI input box.
|
||||
* TODO: add more description for this class
|
||||
*/
|
||||
export class InputBox {
|
||||
/**
|
||||
* Asynchronously show the UI input box, also show the soft keyboard on mobile.
|
||||
*/
|
||||
public show (): Promise<void>;
|
||||
/**
|
||||
* Asynchronously hide the UI input box, also hide the soft keyboard on mobile.
|
||||
*/
|
||||
public hide (): Promise<void>;
|
||||
/**
|
||||
* Register the UI input box change event callback.
|
||||
* @param cb
|
||||
*/
|
||||
public onChange (cb: () => void);
|
||||
/**
|
||||
* Register the UI input box complete event callback.
|
||||
* @param cb
|
||||
*/
|
||||
public onComplete (cb: () => void);
|
||||
/**
|
||||
* Unregister the UI input box change event callback.
|
||||
* @param cb If not specified, all callback would be unregistered.
|
||||
*/
|
||||
public offChange (cb?: () => void);
|
||||
/**
|
||||
* Unregister the UI input box complete event callback.
|
||||
* @param cb If not specified, all callback would be unregistered.
|
||||
*/
|
||||
public offComplete (cb?: () => void);
|
||||
}
|
||||
Vendored
-452
@@ -1,452 +0,0 @@
|
||||
declare module 'pal/input' {
|
||||
type InputSourceButton = import('pal/input/input-source').InputSourceButton;
|
||||
type InputSourceStick = import('pal/input/input-source').InputSourceStick;
|
||||
type InputSourceDpad = import('pal/input/input-source').InputSourceDpad;
|
||||
type InputSourcePosition = import('pal/input/input-source').InputSourcePosition;
|
||||
type InputSourceOrientation = import('pal/input/input-source').InputSourceOrientation;
|
||||
|
||||
type TouchCallback = (res: import('cocos/input/types').EventTouch) => void;
|
||||
/**
|
||||
* Class designed for touch input.
|
||||
*/
|
||||
export class TouchInputSource {
|
||||
/**
|
||||
* Register the touch event callback.
|
||||
*/
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: TouchCallback, target?: any);
|
||||
public dispatchEventsInCache (): void;
|
||||
}
|
||||
|
||||
type MouseCallback = (res: import('cocos/input/types').EventMouse) => void;
|
||||
/**
|
||||
* Class designed for mouse input.
|
||||
*/
|
||||
export class MouseInputSource {
|
||||
/**
|
||||
* Register the mouse event callback.
|
||||
*/
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: MouseCallback, target?: any);
|
||||
|
||||
public dispatchMouseDownEvent? (nativeMouseEvent: any);
|
||||
public dispatchMouseMoveEvent? (nativeMouseEvent: any);
|
||||
public dispatchMouseUpEvent? (nativeMouseEvent: any);
|
||||
public dispatchScrollEvent? (nativeMouseEvent: any);
|
||||
|
||||
public dispatchEventsInCache (): void
|
||||
}
|
||||
|
||||
type KeyboardCallback = (res: import('cocos/input/types').EventKeyboard) => void;
|
||||
/**
|
||||
* Class Designed for keyboard input.
|
||||
*/
|
||||
export class KeyboardInputSource {
|
||||
/**
|
||||
* Register the keyboard event callback.
|
||||
*/
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: KeyboardCallback, target?: any);
|
||||
|
||||
public dispatchKeyboardDownEvent? (nativeKeyboardEvent: any);
|
||||
public dispatchKeyboardUpEvent? (nativeKeyboardEvent: any);
|
||||
}
|
||||
|
||||
type GamepadCallback = (res: import('cocos/input/types/event').EventGamepad) => void;
|
||||
|
||||
/**
|
||||
* Class designed for gamepad input
|
||||
*/
|
||||
export class GamepadInputDevice {
|
||||
private constructor(deviceId: number);
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
public static _init (): void;
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
public static _on (eventType: import('cocos/input/types/event-enum').InputEventType, cb: GamepadCallback, target?: any): void;
|
||||
|
||||
public static all: GamepadInputDevice[];
|
||||
public static xr: (GamepadInputDevice | null);
|
||||
/**
|
||||
* @en The gamepad device id
|
||||
* @zh 手柄设备 id
|
||||
*/
|
||||
public get deviceId (): number;
|
||||
/**
|
||||
* @en whether the gamepad is connected
|
||||
* @zh 手柄是否处于连接状态
|
||||
*/
|
||||
public get connected (): boolean;
|
||||
/**
|
||||
* @en The control button in the north direction which is generally the button Y
|
||||
* @zh 处于北向的控制按键,一般是按键 Y
|
||||
*/
|
||||
public get buttonNorth (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the east direction which is generally the button B
|
||||
* @zh 处于东向的控制按键,一般是按键 B
|
||||
*/
|
||||
public get buttonEast (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the west direction which is generally the button X
|
||||
* @zh 处于西向的控制按键,一般是按键 X
|
||||
*/
|
||||
public get buttonWest (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the south direction which is generally the button A
|
||||
* @zh 处于南向的控制按键,一般是按键 A
|
||||
*/
|
||||
public get buttonSouth (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The button L1
|
||||
* @zh 按键 L1
|
||||
*/
|
||||
public get buttonL1 (): InputSourceButton;
|
||||
/**
|
||||
* @en The button L2
|
||||
* @zh 按键 L2
|
||||
*/
|
||||
public get buttonL2 (): InputSourceButton;
|
||||
/**
|
||||
* @en The button L3
|
||||
* @zh 按键 L3
|
||||
*/
|
||||
public get buttonL3 (): InputSourceButton;
|
||||
/**
|
||||
* @en The button R1
|
||||
* @zh 按键 R1
|
||||
*/
|
||||
public get buttonR1 (): InputSourceButton;
|
||||
/**
|
||||
* @en The button R2
|
||||
* @zh 按键 R2
|
||||
*/
|
||||
public get buttonR2 (): InputSourceButton;
|
||||
/**
|
||||
* @en The button R3
|
||||
* @zh 按键 R3
|
||||
*/
|
||||
public get buttonR3 (): InputSourceButton;
|
||||
|
||||
// public get buttonTouchPad (): InputSourceButton;
|
||||
// public get buttonHome (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The button Share
|
||||
* @zh 分享按键
|
||||
*/
|
||||
public get buttonShare (): InputSourceButton;
|
||||
/**
|
||||
* @en The button Options
|
||||
* @zh 选项按键
|
||||
*/
|
||||
public get buttonOptions (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The dpad buttons
|
||||
* @zh 方向按键
|
||||
*/
|
||||
public get dpad (): InputSourceDpad;
|
||||
/**
|
||||
* @en The left stick
|
||||
* @zh 左摇杆
|
||||
*/
|
||||
public get leftStick (): InputSourceStick;
|
||||
/**
|
||||
* @en The right stick
|
||||
* @zh 右摇杆
|
||||
*/
|
||||
public get rightStick (): InputSourceStick;
|
||||
|
||||
/**
|
||||
* @en The button Start
|
||||
* @zh 开始按键
|
||||
*/
|
||||
public get buttonStart (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The grab Left Grip
|
||||
* @zh 左手柄握住
|
||||
*/
|
||||
public get gripLeft (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Right Grip
|
||||
* @zh 右手柄握住
|
||||
*/
|
||||
public get gripRight (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The position Left hand
|
||||
* @zh 左手位置
|
||||
*/
|
||||
public get handLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left hand
|
||||
* @zh 左手方向
|
||||
*/
|
||||
public get handLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right hand
|
||||
* @zh 右手位置
|
||||
*/
|
||||
public get handRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right hand
|
||||
* @zh 右手方向
|
||||
*/
|
||||
public get handRightOrientation (): InputSourceOrientation;
|
||||
|
||||
/**
|
||||
* @en The position Left aim
|
||||
* @zh 左射线位置
|
||||
*/
|
||||
public get aimLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left aim
|
||||
* @zh 左射线方向
|
||||
*/
|
||||
public get aimLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right aim
|
||||
* @zh 右射线位置
|
||||
*/
|
||||
public get aimRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right aim
|
||||
* @zh 右射线方向
|
||||
*/
|
||||
public get aimRightOrientation (): InputSourceOrientation;
|
||||
}
|
||||
|
||||
type AccelerometerCallback = (res: import('cocos/input/types').EventAcceleration) => void;
|
||||
/**
|
||||
* Class designed for accelerometer input
|
||||
*/
|
||||
export class AccelerometerInputSource {
|
||||
/**
|
||||
* Asynchronously start the accelerometer.
|
||||
* TODO: return a promise.
|
||||
*/
|
||||
public start (): void;
|
||||
/**
|
||||
* Stop the accelerometer.
|
||||
* TODO: return a promise.
|
||||
*/
|
||||
public stop (): void;
|
||||
/**
|
||||
* Set interval of the accelerometer callback.
|
||||
* The interval is in mile seconds.
|
||||
* @param intervalInMileSeconds interval in mile seconds.
|
||||
*/
|
||||
public setInterval (intervalInMileSeconds: number): void;
|
||||
/**
|
||||
* Register the acceleration event callback.
|
||||
*/
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: AccelerometerCallback, target?: any): void;
|
||||
}
|
||||
|
||||
type HandleCallback = (res: import('cocos/input/types').EventHandle) => void;
|
||||
/**
|
||||
* Class designed for handle input.
|
||||
*/
|
||||
export class HandleInputDevice {
|
||||
/**
|
||||
* Register the handle event callback.
|
||||
* @engineInternal
|
||||
*/
|
||||
public _on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: HandleCallback, target?: any);
|
||||
|
||||
/**
|
||||
* @en The control button in the north direction which is generally the button Y
|
||||
* @zh 处于北向的控制按键,一般是按键 Y
|
||||
*/
|
||||
public get buttonNorth (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the east direction which is generally the button B
|
||||
* @zh 处于东向的控制按键,一般是按键 B
|
||||
*/
|
||||
public get buttonEast (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the west direction which is generally the button X
|
||||
* @zh 处于西向的控制按键,一般是按键 X
|
||||
*/
|
||||
public get buttonWest (): InputSourceButton;
|
||||
/**
|
||||
* @en The control button in the south direction which is generally the button A
|
||||
* @zh 处于南向的控制按键,一般是按键 A
|
||||
*/
|
||||
public get buttonSouth (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The button Left Trigger
|
||||
* @zh 左扳机按键
|
||||
*/
|
||||
public get buttonTriggerLeft (): InputSourceButton;
|
||||
/**
|
||||
* @en The button Right Trigger
|
||||
* @zh 右扳机按键
|
||||
*/
|
||||
public get buttonTriggerRight (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Left Trigger
|
||||
* @zh 左扳机扣动
|
||||
*/
|
||||
public get triggerLeft (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Right Trigger
|
||||
* @zh 右扳机扣动
|
||||
*/
|
||||
public get triggerRight (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Left Grip
|
||||
* @zh 左手柄握住
|
||||
*/
|
||||
public get gripLeft (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Right Grip
|
||||
* @zh 右手柄握住
|
||||
*/
|
||||
public get gripRight (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The left stick
|
||||
* @zh 左摇杆
|
||||
*/
|
||||
public get leftStick (): InputSourceStick;
|
||||
/**
|
||||
* @en The right stick
|
||||
* @zh 右摇杆
|
||||
*/
|
||||
public get rightStick (): InputSourceStick;
|
||||
|
||||
/**
|
||||
* @en The button Left Stick
|
||||
* @zh 左摇杆按键
|
||||
*/
|
||||
public get buttonLeftStick (): InputSourceButton;
|
||||
/**
|
||||
* @en The button Right Stick
|
||||
* @zh 右摇杆按键
|
||||
*/
|
||||
public get buttonRightStick (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The button Options
|
||||
* @zh 选项按键
|
||||
*/
|
||||
public get buttonOptions (): InputSourceButton;
|
||||
/**
|
||||
* @en The button Start
|
||||
* @zh 开始按键
|
||||
*/
|
||||
public get buttonStart (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The position Left hand
|
||||
* @zh 左手位置
|
||||
*/
|
||||
public get handLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left hand
|
||||
* @zh 左手方向
|
||||
*/
|
||||
public get handLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right hand
|
||||
* @zh 右手位置
|
||||
*/
|
||||
public get handRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right hand
|
||||
* @zh 右手方向
|
||||
*/
|
||||
public get handRightOrientation (): InputSourceOrientation;
|
||||
|
||||
/**
|
||||
* @en The position Left aim
|
||||
* @zh 左射线位置
|
||||
*/
|
||||
public get aimLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left aim
|
||||
* @zh 左射线方向
|
||||
*/
|
||||
public get aimLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right aim
|
||||
* @zh 右射线位置
|
||||
*/
|
||||
public get aimRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right aim
|
||||
* @zh 右射线方向
|
||||
*/
|
||||
public get aimRightOrientation (): InputSourceOrientation;
|
||||
}
|
||||
|
||||
type HMDCallback = (res: import('cocos/input/types').EventHMD) => void;
|
||||
/**
|
||||
* Class designed for HMD input.
|
||||
*/
|
||||
export class HMDInputDevice {
|
||||
/**
|
||||
* Register the hmd event callback.
|
||||
* @engineInternal
|
||||
*/
|
||||
public _on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: HMDCallback, target?: any);
|
||||
|
||||
/**
|
||||
* @en The position Left view
|
||||
* @zh 左窗口位置
|
||||
*/
|
||||
public get viewLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left view
|
||||
* @zh 左窗口方向
|
||||
*/
|
||||
public get viewLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right view
|
||||
* @zh 右窗口位置
|
||||
*/
|
||||
public get viewRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right view
|
||||
* @zh 右窗口方向
|
||||
*/
|
||||
public get viewRightOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Middle head
|
||||
* @zh 头部中间位置
|
||||
*/
|
||||
public get headMiddlePosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Middle head
|
||||
* @zh 头部中间方向
|
||||
*/
|
||||
public get headMiddleOrientation (): InputSourceOrientation;
|
||||
}
|
||||
|
||||
type HandheldCallback = (res: import('cocos/input/types').EventHandheld) => void;
|
||||
/**
|
||||
* Class designed for Handheld input.
|
||||
*/
|
||||
export class HandheldInputDevice {
|
||||
/**
|
||||
* Register the handheld event callback.
|
||||
* @engineInternal
|
||||
*/
|
||||
public _on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: HandheldCallback, target?: any);
|
||||
/**
|
||||
* @en The position handheld
|
||||
* @zh 手持设备相机位置
|
||||
*/
|
||||
public get handheldPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation handheld
|
||||
* @zh 手持设备相机方向
|
||||
*/
|
||||
public get handheldOrientation (): InputSourceOrientation;
|
||||
}
|
||||
}
|
||||
Vendored
-532
@@ -1,532 +0,0 @@
|
||||
declare module 'pal/minigame' {
|
||||
export const minigame: IMiniGame;
|
||||
export interface IMiniGame {
|
||||
setPreferredFramesPerSecond(_targetFrameRate: number);
|
||||
// platform related
|
||||
wx?: WeChatAPI;
|
||||
tt?: ByteDanceAPI;
|
||||
ral?: RuntimeAPI;
|
||||
|
||||
// system
|
||||
isDevTool: boolean;
|
||||
isLandscape: boolean;
|
||||
orientation: import('pal/screen-adapter/enum-type').Orientation;
|
||||
/**
|
||||
* Most mini game platforms have performance issues calling this interface, so the engine does caching internally.
|
||||
* This interface is deprecated in WeChat mini games, please use 'getSystemSetting', 'getAppAuthorizeSetting','getSystemSetting',
|
||||
* 'getDeviceInfo','getWindowInfo', 'getAppBaseInfo' instead.
|
||||
*/
|
||||
getSystemInfoSync(): SystemInfo;
|
||||
onShow(callback: () => void): void;
|
||||
offShow(callback: () => void): void;
|
||||
onHide(callback: () => void): void;
|
||||
offHide(callback: () => void): void;
|
||||
onWindowResize?(callback: () => void): void;
|
||||
/**
|
||||
* This method returns the standardized SafeArea based on the screen coordinate system,
|
||||
* which is not affected by the orientation of the screen.
|
||||
* @returns {SafeArea} An interface displaying the data of safe area, including 'top', 'bottom', 'left', 'right', 'width' and 'height'.
|
||||
*/
|
||||
getSafeArea(): SafeArea;
|
||||
triggerGC?(): void;
|
||||
getBatteryInfoSync(): BatteryInfo;
|
||||
|
||||
exitMiniProgram? (): void;
|
||||
|
||||
// render
|
||||
getSharedCanvas(): any;
|
||||
getOpenDataContext(): any;
|
||||
|
||||
// worker
|
||||
/**
|
||||
* Create a worker thread from a packaged script path.
|
||||
*
|
||||
* IMPORTANT — this is optional and genuinely absent on some platforms:
|
||||
* - Present: WeChat (`wx.createWorker`), ByteDance (`tt.createWorker`), Alipay
|
||||
* (`my.createWorker`), Baidu (`swan.createWorker`, base library 1.6.1+), and the
|
||||
* quick-game family (`qg.createWorker` on Xiaomi / Huawei 1117+ / OPPO / vivo).
|
||||
* Each `pal/minigame/*.js` adapter starts with `cloneObject(minigame, <platformGlobal>)`,
|
||||
* and `cloneObject` copies functions with `.bind(origin)` — so `createWorker` arrives on
|
||||
* `minigame` for free, already bound to the right global. No per-platform adapter code
|
||||
* is needed, and `pal/` itself must not be edited (it is regenerated from the
|
||||
* `@cocos/engine-pal` package on postinstall).
|
||||
* - Absent: Taobao mini-game has NO worker API at all (its API surface has no Worker
|
||||
* category), and no `Worker` / `Blob` / `URL.createObjectURL` either — there is no way to
|
||||
* get a real thread there. Callers must degrade to synchronous execution.
|
||||
*
|
||||
* Returns `undefined` (rather than throwing) when creation fails on Huawei quick game, so
|
||||
* the result MUST be null-checked.
|
||||
*
|
||||
* Every platform caps concurrency at ONE worker except WeChat V2 (standard worker).
|
||||
* Script paths must be relative (no leading "/") and end with ".js", and the file must be
|
||||
* packaged under the workers directory declared in game.json / manifest.json / app.json.
|
||||
*/
|
||||
createWorker?: (scriptPath: string, options?: MinigameWorkerOptions) => MinigameWorker | undefined;
|
||||
/**
|
||||
* Platform environment info. On WeChat this carries `isSupportStandardWorker`, which gates
|
||||
* the V2 standard worker (grey release; NOT supported in the WeChat devtools). Absent on
|
||||
* platforms whose global has no `env`.
|
||||
*/
|
||||
env?: MinigameEnv;
|
||||
|
||||
// file system
|
||||
getFileSystemManager(): FileSystemManager;
|
||||
loadSubpackage? (option: LoadSubpackageOption): LoadSubpackageTask;
|
||||
|
||||
// input
|
||||
onTouchStart: IEventManager<TouchEvent>;
|
||||
onTouchMove: IEventManager<TouchEvent>;
|
||||
onTouchEnd: IEventManager<TouchEvent>;
|
||||
onTouchCancel: IEventManager<TouchEvent>;
|
||||
|
||||
// audio
|
||||
createInnerAudioContext(): InnerAudioContext;
|
||||
onAudioInterruptionBegin(callback: () => void): any;
|
||||
offAudioInterruptionBegin(callback: () => void): any;
|
||||
onAudioInterruptionEnd(callback: () => void): any;
|
||||
offAudioInterruptionEnd(callback: () => void): any;
|
||||
|
||||
// font
|
||||
loadFont(url: string): string;
|
||||
|
||||
// device
|
||||
onAccelerometerChange(cb: AccelerometerChangeCallback);
|
||||
offAccelerometerChange(cb?: AccelerometerChangeCallback);
|
||||
startAccelerometer(obj: AccelerometerStartParameter);
|
||||
stopAccelerometer(obj: AccelerometerStopParameter);
|
||||
|
||||
// New interfaces for base libraries 2.25.3 and above
|
||||
getSystemSetting(): SystemSetting;
|
||||
getAppAuthorizeSetting(): AppAuthorizeSetting,
|
||||
getDeviceInfo(): DeviceInfo;
|
||||
getWindowInfo(): WindowInfo;
|
||||
getAppBaseInfo(): AppBaseInfo;
|
||||
|
||||
// interace for douyin live play feature
|
||||
checkFeedSubscribeStatus(opt: subscribeOptions): void;
|
||||
requestFeedSubscribe(opt: reqSubscribeOptions): void;
|
||||
getLaunchOptionsSync(): LaunchOptions;
|
||||
reportScene(opt: reportOption): void;
|
||||
onFeedStatusChange(cb: (type: string) => void): void;
|
||||
offFeedStatusChange(cb?: (type: string) => void): void;
|
||||
storeFeedData(opt: storeFeedDataOptions): void;
|
||||
getFeedData(opt: getFeedDataOptions): void;
|
||||
|
||||
setEnableDebug? (parm: DebugParameter): void;
|
||||
notifyMiniProgramPlayableStatus? (parm: notiOptions): void;
|
||||
}
|
||||
|
||||
interface WeChatAPI {
|
||||
onKeyDown?: (cb: (res: KeyboardEventData) => void) => void;
|
||||
onKeyUp?: (cb: (res: KeyboardEventData) => void) => void;
|
||||
|
||||
onMouseDown?: (cb: (res: MouseEventData) => void) => void;
|
||||
onMouseMove?: (cb: (res: MouseEventData) => void) => void;
|
||||
onMouseUp?: (cb: (res: MouseEventData) => void) => void;
|
||||
onWheel?: (cb: (res: MouseWheelEventData) => void) => void;
|
||||
}
|
||||
|
||||
export interface KeyboardEventData {
|
||||
key: string;
|
||||
code: string;
|
||||
timeStamp: number;
|
||||
}
|
||||
|
||||
export interface MouseEventData {
|
||||
x: number;
|
||||
y: number;
|
||||
button: number;
|
||||
timeStamp: number;
|
||||
}
|
||||
|
||||
export interface MouseWheelEventData extends MouseEventData {
|
||||
deltaX: number;
|
||||
deltaY: number;
|
||||
deltaZ: number;
|
||||
}
|
||||
|
||||
interface ICANVAS_CONTEXT2D_TEXTBASELINE_ALPHABETIC {
|
||||
name: string,
|
||||
enable: number,
|
||||
}
|
||||
interface ICANVAS_CONTEXT2D_TEXTBASELINE_DEFAULT {
|
||||
name: string,
|
||||
alphabetic: number,
|
||||
}
|
||||
|
||||
interface RuntimeAPI {
|
||||
CANVAS_CONTEXT2D_TEXTBASELINE_ALPHABETIC: ICANVAS_CONTEXT2D_TEXTBASELINE_ALPHABETIC,
|
||||
CANVAS_CONTEXT2D_TEXTBASELINE_DEFAULT: ICANVAS_CONTEXT2D_TEXTBASELINE_DEFAULT,
|
||||
getFeaturePropertyInt(featureName: string): number;
|
||||
setFeaturePropertyInt(featureName: string, value: number);
|
||||
}
|
||||
|
||||
interface ByteDanceAPI {
|
||||
getAudioContext?: () => AudioContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options accepted by `minigame.createWorker`. Only WeChat defines any; other platforms ignore
|
||||
* the second argument. Kept loose on purpose — the platform surface differs and grows.
|
||||
*/
|
||||
export interface MinigameWorkerOptions {
|
||||
/**
|
||||
* WeChat only, base library 2.13.0+. Uses the "experimental" worker implementation, which
|
||||
* speeds up JS execution several times over on iOS. Requires pairing with
|
||||
* `onProcessKilled`, because the system may reclaim the worker process at any time.
|
||||
* This legacy option does not select the V2 standard Worker.
|
||||
*/
|
||||
useExperimentalWorker?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform environment info exposed as `minigame.env`.
|
||||
*/
|
||||
export interface MinigameEnv {
|
||||
/**
|
||||
* WeChat only. `true` when the runtime supports the V2 standard worker: multiple concurrent
|
||||
* workers, `SharedArrayBuffer`, transfer lists in `postMessage`, `OffscreenCanvas`. Requires
|
||||
* WeChat client >= 8.0.74 (Android) and base library >= 3.17.0, is in grey release, and is
|
||||
* NOT supported in the WeChat devtools — so it must be checked at runtime, never assumed.
|
||||
*/
|
||||
isSupportStandardWorker?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The worker handle returned by `minigame.createWorker`. The API shape is remarkably consistent
|
||||
* across WeChat / ByteDance / Alipay / Baidu / quick-game: all use `postMessage` + `onMessage`,
|
||||
* and all expose the worker-side global as `worker` (NOT `self`).
|
||||
*
|
||||
* Differences that the engine's backend layer must absorb:
|
||||
* - `onError` is missing on some platforms (Huawei quick game documents only
|
||||
* create/postMessage/onMessage/terminate) — guard before calling.
|
||||
* - `onProcessKilled` is WeChat-only (iOS experimental worker reclamation).
|
||||
* - The transfer list (second `postMessage` argument) is honored ONLY by WeChat V2. Huawei quick
|
||||
* game documents data transfer as structured clone with no transferable objects; passing a
|
||||
* transfer list elsewhere may throw, so omit it unless the platform supports it.
|
||||
*/
|
||||
export interface MinigameWorker {
|
||||
postMessage(message: any, transfer?: any[]): void;
|
||||
onMessage(listener: (res: any) => void): void;
|
||||
onError?: (listener: (err: any) => void) => void;
|
||||
terminate(): void;
|
||||
/** WeChat only: fired when the system reclaims the worker process. */
|
||||
onProcessKilled?: (listener: (err: any) => void) => void;
|
||||
}
|
||||
|
||||
export type AccelerometerIntervalMode = 'game' | 'ui' | 'normal';
|
||||
|
||||
export interface AccelerometerStartParameter {
|
||||
interval: AccelerometerIntervalMode,
|
||||
success?: () => void,
|
||||
fail?: (err: any) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
export interface AccelerometerStopParameter {
|
||||
success?: () => void,
|
||||
fail?: (err: any) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
|
||||
export interface SystemInfo {
|
||||
abi: string;
|
||||
deviceAbi: string;
|
||||
brand: string;
|
||||
model: string;
|
||||
pixelRatio: number;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
windowWidth: number;
|
||||
windowHeight: number;
|
||||
statusBarHeight: number;
|
||||
language: string;
|
||||
version: string;
|
||||
system: string;
|
||||
platform: string;
|
||||
fontSizeSetting: number;
|
||||
enableDebug: boolean;
|
||||
SDKVersion: string;
|
||||
benchmarkLevel: number;
|
||||
albumAuthorized: boolean;
|
||||
cameraAuthorized: boolean;
|
||||
locationAuthorized: boolean;
|
||||
microphoneAuthorized: boolean;
|
||||
notificationAuthorized: boolean;
|
||||
notificationAlertAuthorized: boolean;
|
||||
notificationBadgeAuthorized: boolean;
|
||||
notificationSoundAuthorized: boolean;
|
||||
phoneCalendarAuthorized: string;
|
||||
host: HostInfo;
|
||||
bluetoothAuthorized: string;
|
||||
bluetoothEnabled: boolean;
|
||||
locationEnabled: boolean;
|
||||
wifiEnabled: boolean;
|
||||
safeArea: SafeArea;
|
||||
locationReducedAccuracy: boolean;
|
||||
theme: string;
|
||||
cpuType: string;
|
||||
memorySize: string;
|
||||
screenTop: number;
|
||||
mode: string;
|
||||
fontSizeScaleFactor: number;
|
||||
deviceOrientation?: 'portrait' | 'landscape';
|
||||
}
|
||||
export interface SystemSetting {
|
||||
bluetoothEnabled: boolean;
|
||||
locationEnabled: boolean;
|
||||
wifiEnabled: boolean;
|
||||
deviceOrientation?: 'portrait' | 'landscape';
|
||||
}
|
||||
export interface AppAuthorizeSetting {
|
||||
albumAuthorized: string | undefined;
|
||||
bluetoothAuthorized: string | undefined;
|
||||
cameraAuthorized: string | undefined;
|
||||
locationAuthorized: string | undefined;
|
||||
locationReducedAccuracy: boolean | undefined;
|
||||
microphoneAuthorized: string | undefined;
|
||||
notificationAuthorized: string | undefined;
|
||||
notificationAlertAuthorized: string | undefined;
|
||||
notificationBadgeAuthorized: string | undefined;
|
||||
notificationSoundAuthorized: string | undefined;
|
||||
phoneCalendarAuthorized: string | undefined;
|
||||
}
|
||||
export interface HostInfo {
|
||||
appId: string;
|
||||
}
|
||||
export interface AppBaseInfo {
|
||||
SDKVersion: string;
|
||||
enableDebug: boolean;
|
||||
host: HostInfo;
|
||||
language: string;
|
||||
version: string;
|
||||
theme: string;
|
||||
fontSizeScaleFactor: number;
|
||||
fontSizeSetting: number;
|
||||
mode: string;
|
||||
}
|
||||
export interface DeviceInfo {
|
||||
abi: string;
|
||||
deviceAbi: string;
|
||||
benchmarkLevel: number;
|
||||
brand: string;
|
||||
model: string;
|
||||
system: string;
|
||||
platform: string;
|
||||
cpuType: string;
|
||||
memorySize: string;
|
||||
}
|
||||
|
||||
export interface WindowInfo {
|
||||
pixelRatio: number;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
windowWidth: number;
|
||||
windowHeight: number;
|
||||
statusBarHeight: number;
|
||||
safeArea: SafeArea;
|
||||
screenTop: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare interface BatteryInfo {
|
||||
level: number; // ranged from 1-100
|
||||
isCharging: boolean;
|
||||
}
|
||||
|
||||
type AccelerometerChangeCallback = (res: AccelerometerData) => void;
|
||||
declare interface AccelerometerData {
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
}
|
||||
|
||||
declare interface IEventManager<Event> {
|
||||
(listener: (event: Event) => void): void;
|
||||
}
|
||||
|
||||
declare class FileSystemManager {
|
||||
access(obj: any);
|
||||
accessSync(path: string): boolean;
|
||||
appendFile(obj: any);
|
||||
appendFileSync(filePath: string, data: string|ArrayBuffer, encoding: string);
|
||||
copyFile(obj: any);
|
||||
copyFileSync(srcPath: string, destPath: string);
|
||||
getFileInfo(obj: any);
|
||||
getSavedFileList(obj: any);
|
||||
mkdir(obj: any);
|
||||
mkdirSync();
|
||||
readdir(obj: any);
|
||||
readdirSync();
|
||||
readFile(obj: any);
|
||||
readFileSync();
|
||||
removeSavedFile(obj: any);
|
||||
rename(obj: any);
|
||||
renameSync();
|
||||
rmdir(obj: any);
|
||||
rmdirSync();
|
||||
saveFile(obj: any);
|
||||
saveFileSync();
|
||||
stat(obj: any);
|
||||
statSync();
|
||||
unlink(obj: any);
|
||||
unlinkSync();
|
||||
unzip(obj: any);
|
||||
writeFile(obj: any);
|
||||
writeFileSync();
|
||||
}
|
||||
declare interface SafeArea {
|
||||
left: number;
|
||||
right: number;
|
||||
top: number;
|
||||
bottom: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
declare class InnerAudioContext {
|
||||
src: string;
|
||||
startTime: number;
|
||||
autoplay: boolean;
|
||||
loop: boolean;
|
||||
obeyMuteSwitch: boolean;
|
||||
volume: number;
|
||||
duration: number;
|
||||
currentTime: number;
|
||||
paused: boolean;
|
||||
buffered: number;
|
||||
|
||||
destroy(): any;
|
||||
offCanplay(callback: () => void): any;
|
||||
offEnded(callback: () => void): any;
|
||||
offError(callback: (err: any) => void): any;
|
||||
offPause(callback: () => void): any;
|
||||
offPlay(callback: () => void): any;
|
||||
offSeeked(callback: () => void): any;
|
||||
offSeeking(callback: () => void): any;
|
||||
offStop(callback: () => void): any;
|
||||
offTimeUpdate(callback: () => void): any;
|
||||
offWaiting(callback: () => void): any;
|
||||
onCanplay(callback: () => void): any;
|
||||
onEnded(callback: () => void): any;
|
||||
onError(callback: (err: any) => void): any;
|
||||
onPause(callback: () => void): any;
|
||||
onPlay(callback: () => void): any;
|
||||
onSeeked(callback: () => void): any;
|
||||
onSeeking(callback: () => void): any;
|
||||
onStop(callback: () => void): any;
|
||||
onTimeUpdate(callback: () => void): any;
|
||||
onWaiting(callback: () => void): any;
|
||||
pause(): any;
|
||||
play(): any;
|
||||
seek(position: number): any;
|
||||
stop(): any;
|
||||
}
|
||||
|
||||
interface LoadSubpackageOption {
|
||||
name: string;
|
||||
fail?: (...args: unknown[]) => void;
|
||||
success?: (...args: unknown[]) => void;
|
||||
complete?: (...args: unknown[]) => void;
|
||||
}
|
||||
interface LoadSubpackageTask {
|
||||
onProgressUpdate(
|
||||
listener: LoadSubpackageTaskOnProgressUpdateCallback
|
||||
): void;
|
||||
}
|
||||
type LoadSubpackageTaskOnProgressUpdateCallback = (result: LoadSubpackageTaskOnProgressUpdateListenerResult) => void;
|
||||
interface LoadSubpackageTaskOnProgressUpdateListenerResult {
|
||||
progress: number;
|
||||
totalBytesExpectedToWrite: number;
|
||||
totalBytesWritten: number;
|
||||
}
|
||||
|
||||
interface subscribeOptions {
|
||||
scene: number;
|
||||
allScene: boolean;
|
||||
type: string;
|
||||
success?: (successObj: commonSuccessObj) => void,
|
||||
fail?: (failObj: commonFailObj) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
interface reqSubscribeOptions {
|
||||
scene: number;
|
||||
contentIDs: string[];
|
||||
allScene: boolean;
|
||||
type: string;
|
||||
success?: (successObj: commonSuccessObj) => void,
|
||||
fail?: (failObj: commonFailObj) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
|
||||
interface LaunchOptions {
|
||||
query: LaunchOptionQuery;
|
||||
scene: string;
|
||||
extra: LaunchOptionExtra;
|
||||
}
|
||||
|
||||
interface LaunchOptionExtra {
|
||||
aid: object;
|
||||
appId: string;
|
||||
mpVersion: string;
|
||||
launch_from: string;
|
||||
}
|
||||
|
||||
interface LaunchOptionQuery {
|
||||
ad_params: any;
|
||||
feed_game_scene: any;
|
||||
feed_game_channel: any;
|
||||
feed_game_content_id: any;
|
||||
feed_game_extra: any;
|
||||
}
|
||||
interface reportOption {
|
||||
costTime: number; //ms
|
||||
sceneId: number;
|
||||
dimension: object;
|
||||
metric: object;
|
||||
success?: (successObj: commonSuccessObj) => void,
|
||||
fail?: (failObj: commonFailObj) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
interface commonSuccessObj {
|
||||
errMsg: string,
|
||||
data: object,
|
||||
}
|
||||
interface commonFailObj {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface storeFeedDataOptions {
|
||||
scene: string;
|
||||
extra: string;
|
||||
status: number;
|
||||
contentID: string;
|
||||
leftValue: number;//ms
|
||||
operator: string;
|
||||
rightValue: number;//ms
|
||||
success?: (successObj: {errMsg: string}) => void,
|
||||
fail?: (failObj: commonFailObj) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
|
||||
interface getFeedDataOptions {
|
||||
scene: string;
|
||||
contentID: string;
|
||||
success?: (successObj: {errMsg: string, extra: string, status: number}) => void,
|
||||
fail?: (failObj: commonFailObj) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
|
||||
interface DebugParameter {
|
||||
enableDebug: boolean,
|
||||
success?: () => void,
|
||||
fail?: (err: any) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
|
||||
interface notiOptions {
|
||||
success?: () => void,
|
||||
fail?: (err: any) => void,
|
||||
complete?: () => void,
|
||||
}
|
||||
Vendored
-10
@@ -1,10 +0,0 @@
|
||||
declare module 'pal/pacer' {
|
||||
|
||||
export class Pacer {
|
||||
get targetFrameRate (): number;
|
||||
set targetFrameRate (val: number);
|
||||
onTick: (() => void) | null;
|
||||
start (): void;
|
||||
stop (): void;
|
||||
}
|
||||
}
|
||||
Vendored
-134
@@ -1,134 +0,0 @@
|
||||
declare module 'pal/screen-adapter' {
|
||||
export interface SafeAreaEdge {
|
||||
top: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
right: number;
|
||||
}
|
||||
|
||||
export type ConfigOrientation = 'auto' | 'landscape' | 'portrait';
|
||||
export interface IScreenOptions {
|
||||
/**
|
||||
* Orientation options from editor builder.
|
||||
*/
|
||||
configOrientation: ConfigOrientation;
|
||||
/**
|
||||
* Determine whether the game frame exact fits the screen.
|
||||
* Now it only works on Web platform.
|
||||
*/
|
||||
exactFitScreen: boolean;
|
||||
|
||||
/**
|
||||
* Determine whether use headless renderer, which means do not support some screen operations.
|
||||
*/
|
||||
isHeadlessMode: boolean;
|
||||
/**
|
||||
* Optional startup DPR cap, currently consumed by Web.
|
||||
* Supporting adapters validate that it is finite and >= 1; other adapters ignore it.
|
||||
* Omission/null preserves the adapter's default policy (Web caps DPR at 2).
|
||||
*/
|
||||
maxDevicePixelRatio?: number | null;
|
||||
}
|
||||
|
||||
class ScreenAdapter {
|
||||
/**
|
||||
* Init the callback to rebuild frame buffer when update the resolution.
|
||||
* This method will also init the resolution.
|
||||
* This method should be called when the engine director.root is initiated.
|
||||
* @param options
|
||||
* @param cbToRebuildFrameBuffer
|
||||
*/
|
||||
public init (options: IScreenOptions, cbToRebuildFrameBuffer: () => void);
|
||||
/**
|
||||
* On web mobile platform, sometimes we need to rotate the game frame.
|
||||
* This field record the rotate state of game frame, which is false by default.
|
||||
*/
|
||||
public isFrameRotated: boolean;
|
||||
/**
|
||||
* On web platform, we support to set container strategy.
|
||||
* This field record whether we apply ProportionalToFrame strategy on container, which is false by default.
|
||||
*/
|
||||
public get isProportionalToFrame (): boolean;
|
||||
public set isProportionalToFrame (v: boolean);
|
||||
/**
|
||||
* In some case we don't want to handle the resize event.
|
||||
* For example, when the soft keyboard shows up, we don't want to resize the canvas.
|
||||
* This is true by default.
|
||||
*/
|
||||
public handleResizeEvent: boolean;
|
||||
/**
|
||||
* Query whether fullscreen feature is supported on the current platform.
|
||||
*/
|
||||
public get supportFullScreen (): boolean;
|
||||
/**
|
||||
* Query the current fullscreen state.
|
||||
*/
|
||||
public get isFullScreen (): boolean;
|
||||
/**
|
||||
* Optional capability: the applied startup cap, or null for the adapter's default.
|
||||
* Adapters exposing this property consume and validate maxDevicePixelRatio.
|
||||
* Absent on adapters that ignore this setting.
|
||||
*/
|
||||
public readonly maxDevicePixelRatio?: number | null;
|
||||
/**
|
||||
* The ratio of pixel sizes:
|
||||
* the size of one CSS pixel to the size of one physical pixel.
|
||||
*/
|
||||
public get devicePixelRatio (): number;
|
||||
/**
|
||||
* Get the size of current window in physical pixels.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get and set the size of current window in physical pixels.
|
||||
*/
|
||||
public get windowSize (): import('cocos/core/math').Size;
|
||||
public set windowSize (size: import('cocos/core/math').Size);
|
||||
|
||||
/**
|
||||
* Get the current resolution of game.
|
||||
* This is a readonly property, you can change the value by setting screenAdapter.resolutionScale.
|
||||
*/
|
||||
public get resolution (): import('cocos/core/math').Size;
|
||||
|
||||
/**
|
||||
* Get and set the resolution scale of screen, which will affect the quality of the rendering.
|
||||
* Note: if this value is set too high, the rendering performance of GPU will be reduced, this value is 1 by default.
|
||||
*/
|
||||
public get resolutionScale (): number;
|
||||
public set resolutionScale (value: number);
|
||||
|
||||
/**
|
||||
* Get or set the orientation of current game.
|
||||
* Available on mobile related platform for now.
|
||||
*/
|
||||
public get orientation (): import('pal/screen-adapter/enum-type').Orientation;
|
||||
public set orientation (value: import('pal/screen-adapter/enum-type').Orientation);
|
||||
|
||||
/**
|
||||
* Get the SafeAreaEdge based on the screen coordinate system in physical pixels.
|
||||
* @return {SafeAreaEdge} An interface displaying the distance of the sides 'top', 'bottom', 'left' and 'right'.
|
||||
*/
|
||||
public get safeAreaEdge (): SafeAreaEdge;
|
||||
|
||||
/**
|
||||
* Asynchronously request fullscreen
|
||||
* If failed to request fullscreen, another attempt will be made to request fullscreen the next time a user interaction occurs.
|
||||
* @returns Promise to request fullscreen
|
||||
*/
|
||||
public requestFullScreen (): Promise<void>;
|
||||
/**
|
||||
* Asynchronously exit fullscreen
|
||||
* @returns Promise to exit fullscreen
|
||||
*/
|
||||
public exitFullScreen (): Promise<void>;
|
||||
|
||||
on (event: import('pal/screen-adapter/enum-type').PalScreenEvent, cb: (...args: any) => void, target?: any);
|
||||
once (event: import('pal/screen-adapter/enum-type').PalScreenEvent, cb: (...args: any) => void, target?: any);
|
||||
off (event: import('pal/screen-adapter/enum-type').PalScreenEvent, cb?: (...args: any) => void, target?: any);
|
||||
}
|
||||
|
||||
export const screenAdapter: ScreenAdapter;
|
||||
|
||||
export {};
|
||||
}
|
||||
Vendored
-68
@@ -1,68 +0,0 @@
|
||||
// TODO: some interface need to be designed in a module called 'Application' and 'Network'
|
||||
declare module 'pal/system-info' {
|
||||
type Feature = import('../../pal/system-info/enum-type').Feature;
|
||||
type NetworkType = import('../../pal/system-info/enum-type').NetworkType;
|
||||
type Platform = import('../../pal/system-info/enum-type').Platform;
|
||||
type Language = import('../../pal/system-info/enum-type').Language;
|
||||
type OS = import('../../pal/system-info/enum-type').OS;
|
||||
type BrowserType = import('../../pal/system-info/enum-type').BrowserType;
|
||||
type PalSystemEvent = import('../../pal/system-info/enum-type').PalSystemEvent;
|
||||
|
||||
export type IFeatureMap = {
|
||||
[feature in Feature]: boolean;
|
||||
};
|
||||
|
||||
class SystemInfo {
|
||||
public get networkType (): NetworkType;
|
||||
public get isNative (): boolean;
|
||||
public get isBrowser (): boolean;
|
||||
public get isMobile (): boolean;
|
||||
public get isLittleEndian (): boolean;
|
||||
/**
|
||||
* Platform is a spacial field which is related to the build platform you choose on the Builder Panel in Cocos Creator.
|
||||
* It may point to an OS like Android or iOS.
|
||||
* It may point to a phone brand like vivo or OPPO.
|
||||
* Also it may point to an app channel like WeChat or ByteDance.
|
||||
*/
|
||||
public get platform (): Platform;
|
||||
/**
|
||||
* This is the language code typed as `Language`.
|
||||
*/
|
||||
public get language (): Language;
|
||||
/**
|
||||
* This is the native value return by platform
|
||||
* The valid value can be 'zh-tw','en','en-us','fr','fr-fr','es-es' and so on.
|
||||
*/
|
||||
public get nativeLanguage (): string;
|
||||
public get os (): OS;
|
||||
public get osVersion (): string;
|
||||
public get osMainVersion (): number;
|
||||
public get browserType (): BrowserType;
|
||||
public get browserVersion (): string;
|
||||
public get isXR (): boolean;
|
||||
public init (): Promise<void[]> ;
|
||||
public hasFeature (feature: Feature): boolean;
|
||||
public getBatteryLevel (): number;
|
||||
|
||||
public triggerGC (): void;
|
||||
public openURL (url: string): void;
|
||||
public now (): number;
|
||||
public restartJSVM (): void;
|
||||
/*
|
||||
* Trigger to exit the game
|
||||
*/
|
||||
public close (): void;
|
||||
/*
|
||||
* Free the native's resources
|
||||
*/
|
||||
public exit(): void;
|
||||
|
||||
on (event: PalSystemEvent, cb: (...args: any) => void, target?: any): void;
|
||||
off (event: PalSystemEvent, cb?: (...args: any) => void, target?: any): void;
|
||||
// TODO: support onError
|
||||
}
|
||||
|
||||
export const systemInfo: SystemInfo;
|
||||
|
||||
export {};
|
||||
}
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
declare module 'pal/wasm' {
|
||||
/**
|
||||
* The first parameter of standard `Webassembly.instantiate` interface is the arraybuffer of wasm.
|
||||
* But the implementation on some platforms is not standard.
|
||||
* So here we provide a more commonly used interface, whose first parameter is the url of wasm.
|
||||
*
|
||||
* @param wasmUrl the url of wasm, this should be a url relative from build output chunk.
|
||||
* @param importObject the standard `WebAssembly.Imports` instance
|
||||
*/
|
||||
export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
|
||||
|
||||
/**
|
||||
* Fetch binary data from wasm url or js mem url.
|
||||
* NOTE: This method should only use to instantiate asm.js compiled with `-O2` options,
|
||||
* because not all platforms support instantiate wasm by wasm binary.
|
||||
* eg. WeChat can only instantiate wasm by wasm url.
|
||||
*
|
||||
* @param binaryUrl the url of wasm or js mem, this should be a url relative from build output chunk.
|
||||
*/
|
||||
export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer>;
|
||||
|
||||
export function fetchUrl(binaryUrl: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Sometimes we need to put wasm modules in subpackage to reduce code size.
|
||||
* In this case we need to ensure that the wasm modules is ready before we import them.
|
||||
* Please remember to invoke this method before we import wasm modules.
|
||||
*/
|
||||
export function ensureWasmModuleReady (): Promise<void>;
|
||||
}
|
||||
Vendored
-61
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
* Engine-side contract of the `pal/worker` module.
|
||||
*
|
||||
* Self-contained on purpose: type checking, IDE services and declaration builds must not depend on
|
||||
* whether the installed PAL package ships a worker module. When `pal/worker` is absent (an older
|
||||
* PAL, or the single-thread compatibility module which is JS only), TypeScript resolves the import to
|
||||
* this ambient declaration. `tests/scripts/pal-worker-types.test.cjs` checks that a real PAL
|
||||
* `worker/type.d.ts` stays structurally identical to these interfaces.
|
||||
*/
|
||||
declare module 'pal/worker' {
|
||||
export interface IWorker {
|
||||
postMessage (message: any, transfer?: Transferable[]): void;
|
||||
onMessage (listener: (res: any) => void): void;
|
||||
onError (listener: (err: any) => void): void;
|
||||
terminate (): void;
|
||||
}
|
||||
|
||||
export interface IWorkerDiagnosis {
|
||||
ready: boolean;
|
||||
version: 0 | 1 | 2;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface IWorkerBackend {
|
||||
readonly concurrencyLimit: number;
|
||||
readonly supportsTransfer: boolean;
|
||||
readonly supportsSharedArrayBuffer: boolean;
|
||||
readonly supportsFunctionWorker: boolean;
|
||||
readonly capabilityReason: string;
|
||||
createScriptWorker (path: string): IWorker;
|
||||
diagnose (path: string): IWorkerDiagnosis;
|
||||
}
|
||||
|
||||
export interface IPlatformWorkerBackend extends IWorkerBackend {
|
||||
readonly supportsStandardWorker: boolean;
|
||||
readonly scriptFailureHint: string;
|
||||
resolveScriptWorker (path: string): IWorkerResolution;
|
||||
readonly hardwareConcurrency: number;
|
||||
readonly scriptFallback: IPlatformWorkerBackend | null;
|
||||
createFunctionWorker (fn: (...args: any[]) => any): IWorker | null;
|
||||
}
|
||||
|
||||
export interface IWorkerResolution {
|
||||
backend: IPlatformWorkerBackend | null;
|
||||
diagnosis: IWorkerDiagnosis;
|
||||
warnOnFailure: boolean;
|
||||
}
|
||||
|
||||
export interface IWorkerCapabilities {
|
||||
supportsStandardWorker: boolean;
|
||||
available: boolean;
|
||||
parallel: boolean;
|
||||
concurrencyLimit: number;
|
||||
supportsTransfer: boolean;
|
||||
supportsSharedArrayBuffer: boolean;
|
||||
supportsFunctionWorker: boolean;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export function createWorkerBackend (): IPlatformWorkerBackend;
|
||||
}
|
||||
Vendored
-58
@@ -1,58 +0,0 @@
|
||||
interface WEBGL_multi_draw {
|
||||
multiDrawArraysWEBGL(mode: GLenum,
|
||||
firstsList: GLint[] | Int32Array, firstsOffset: GLuint,
|
||||
countsList: GLsizei[] | Int32Array, countsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawElementsWEBGL(mode: GLenum,
|
||||
countsList: GLint[] | Int32Array, countsOffset: GLuint,
|
||||
type: GLenum,
|
||||
offsetsList: GLsizei[] | Int32Array, OffsetsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawArraysInstancedWEBGL(mode: GLenum,
|
||||
firstsList: GLint[] | Int32Array, firstsOffset: GLuint,
|
||||
countsList: GLsizei[] | Int32Array, countsOffset: GLuint,
|
||||
instanceCountsList: GLsizei[] | Int32Array, instanceCountsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawElementsInstancedWEBGL(mode: GLenum,
|
||||
countsList: GLint[] | Int32Array, countsOffset: GLuint,
|
||||
type: GLenum,
|
||||
offsetsList: GLsizei[] | Int32Array, OffsetsOffset: GLuint,
|
||||
instanceCountsList: GLsizei[] | Int32Array, instanceCountsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
}
|
||||
|
||||
interface EXT_color_buffer_half_float {
|
||||
readonly RGBA16F_EXT: GLenum;
|
||||
readonly RGB16F_EXT: GLenum;
|
||||
readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: GLenum;
|
||||
readonly UNSIGNED_NORMALIZED_EXT: GLenum;
|
||||
}
|
||||
|
||||
// note that ETC1 is not supported with the compressedTexSubImage2D() method
|
||||
interface WEBGL_compressed_texture_etc1 {
|
||||
readonly COMPRESSED_RGB_ETC1_WEBGL: GLenum;
|
||||
}
|
||||
|
||||
interface WEBGL_compressed_texture_etc {
|
||||
readonly COMPRESSED_R11_EAC: GLenum;
|
||||
readonly COMPRESSED_SIGNED_R11_EAC: GLenum;
|
||||
readonly COMPRESSED_RG11_EAC: GLenum;
|
||||
readonly COMPRESSED_SIGNED_RG11_EAC: GLenum;
|
||||
readonly COMPRESSED_RGB8_ETC2: GLenum;
|
||||
readonly COMPRESSED_RGBA8_ETC2_EAC: GLenum;
|
||||
readonly COMPRESSED_SRGB8_ETC2: GLenum;
|
||||
readonly COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: GLenum;
|
||||
readonly COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum;
|
||||
readonly COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum;
|
||||
}
|
||||
|
||||
interface WEBGL_compressed_texture_pvrtc {
|
||||
readonly COMPRESSED_RGB_PVRTC_4BPPV1_IMG: GLenum;
|
||||
readonly COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: GLenum;
|
||||
readonly COMPRESSED_RGB_PVRTC_2BPPV1_IMG: GLenum;
|
||||
readonly COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: GLenum;
|
||||
}
|
||||
Vendored
-22
@@ -1,22 +0,0 @@
|
||||
interface EXT_color_buffer_float {}
|
||||
|
||||
interface EXT_disjoint_timer_query_webgl2 {
|
||||
readonly QUERY_COUNTER_BITS_EXT: GLenum;
|
||||
readonly TIME_ELAPSED_EXT: GLenum;
|
||||
readonly TIMESTAMP_EXT: GLenum;
|
||||
readonly GPU_DISJOINT_EXT: GLenum;
|
||||
|
||||
queryCounterEXT(query: WebGLQuery, target: GLenum): void;
|
||||
}
|
||||
|
||||
interface WEBGL_texture_storage_multisample {
|
||||
readonly TEXTURE_2D_MULTISAMPLE: number;
|
||||
|
||||
texStorage2DMultisample(
|
||||
target: GLenum,
|
||||
samples: GLsizei,
|
||||
internalformat: GLenum,
|
||||
width: GLsizei,
|
||||
height: GLsizei,
|
||||
fixedsamplelocations: GLboolean): void;
|
||||
}
|
||||
Vendored
-3258
File diff suppressed because it is too large
Load Diff
-101
@@ -1,101 +0,0 @@
|
||||
Cocos Creator authors
|
||||
|
||||
(Ordered by join time)
|
||||
|
||||
Contributors:
|
||||
|
||||
@Marssssssss
|
||||
@finscn
|
||||
@feijing566
|
||||
@devhacker520
|
||||
@drelaptop
|
||||
@benloong
|
||||
@RazgrizHsu
|
||||
@zty8023ys
|
||||
@kissSimple
|
||||
@id-ilych
|
||||
@wzxjiang
|
||||
@nshmura
|
||||
@jrosich
|
||||
@caogtaa
|
||||
@Ronsku
|
||||
@FengXuner
|
||||
@yoki0805
|
||||
@yeshao2069
|
||||
@xduooo
|
||||
@wangyhzzz
|
||||
@unace
|
||||
@simon129
|
||||
@random634
|
||||
@qinhanlei
|
||||
@ohsayan
|
||||
@sarhassan12
|
||||
@lijjLyb
|
||||
@lhx6538665
|
||||
@krapnikkk
|
||||
@k8w
|
||||
@jcs090218
|
||||
@hieubuiduc
|
||||
@haxpor
|
||||
@gaolizheng
|
||||
@gamedevgarage
|
||||
@endless3000
|
||||
@chen-gaoyuan
|
||||
@caochao
|
||||
@Y-way
|
||||
@MatrixLife
|
||||
@HengHuH
|
||||
|
||||
Core Engine Developers:
|
||||
|
||||
Guo Jiawei (@jareguo)
|
||||
|
||||
Huang Yanbin (@knoxHuang)
|
||||
|
||||
Lai Jiaxin (@JayceLai)
|
||||
|
||||
Li Nan (@shrinktofit)
|
||||
|
||||
Ling Huabin (@pandamicro)
|
||||
|
||||
Liu Hang (@caryliu1999)
|
||||
|
||||
Liu Yaqiong (@JoneLau)
|
||||
|
||||
Jiang Zhan (@PatriceJiang)
|
||||
|
||||
Wang Hao (@holycanvas)
|
||||
|
||||
Wang Jianing (@LinYunMo)
|
||||
|
||||
Wang Sizhong (@MSoft1115)
|
||||
|
||||
Wang Yibin (@Mee-gu)
|
||||
|
||||
Wu Yunxiao (@YunHsiao)
|
||||
|
||||
Yang Cheng (@troublemaker52025)
|
||||
|
||||
Yin Kaile (@2youyou2)
|
||||
|
||||
Zhang Xiaoming (@minggo)
|
||||
|
||||
Zheng Jianpei (@PPpro)
|
||||
|
||||
Retired Engine Developers
|
||||
|
||||
Weiliang Wang (@jerrywwl)
|
||||
|
||||
Johnny Wu (@jwu)
|
||||
|
||||
Huabing Xu (@dabingnn)
|
||||
|
||||
Guanghui Qu (@zilongshanren)
|
||||
|
||||
Lan Wanjun (@sunnylanwanjun)
|
||||
|
||||
Xuguang Zhu (@zxg0622)
|
||||
|
||||
Yexin Dong
|
||||
|
||||
Thanks to all developers who report & trace bugs, discuss the engine usage in forum!
|
||||
Vendored
-15
@@ -1,15 +0,0 @@
|
||||
|
||||
/**
|
||||
* This is a declaration file for 'DebugInfos.json'
|
||||
* which is generated from 'EngineErrorMap.md'.
|
||||
* You may run cli command
|
||||
* `gulp build-debug-infos` or `npx gulp build-debug-infos` to generate the json file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Engine error maps.
|
||||
* The keys are error codes and their values are format strings.
|
||||
*/
|
||||
declare const $: Record<number, string>;
|
||||
|
||||
export default $;
|
||||
-4098
File diff suppressed because it is too large
Load Diff
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 SUD
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,114 +1 @@
|
||||
<p align="center">
|
||||
<a href="https://www.cocos.com/">
|
||||
<img src="./ui.png"
|
||||
alt="Cocos Creator Logo">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://github.com/cocos/cocos-engine/stargazers">
|
||||
<img src="https://img.shields.io/github/stars/cocos/cocos-engine.svg?style=flat-square&colorB=4183c4"
|
||||
alt="stars">
|
||||
</a>
|
||||
<a href="https://github.com/cocos-creator/engine/network">
|
||||
<img src="https://img.shields.io/github/forks/cocos/cocos-engine.svg?style=flat-square&colorB=4183c4"
|
||||
alt="forks">
|
||||
</a>
|
||||
<a href="./LICENSE">
|
||||
<img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square&colorB=4183c4"
|
||||
alt="license">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# COCOS 4
|
||||
|
||||
COCOS 4 is an open-source, high-performance, cross-platform game and interactive content development engine. Built on a mature C++ architecture, it provides powerful rendering capabilities and flexible script bindings, supporting a "write once, run anywhere" philosophy.
|
||||
|
||||
Previously, _Cocos Creator_ referred to the combined engine and editor, spanning versions 1.x, 2.x, and 3.x. To embrace a purely open-source model and fully integrate AI, we are separating the engine from the editor. This is a significant and necessary evolution. Moving forward:
|
||||
|
||||
**COCOS** will refer solely to the engine, with the major version upgrading to **COCOS 4**. The cross-platform framework and the core components of the editor will be converted to CLI tools and integrated into the engine's core functionality. This represents a major new addition to this open-source release.
|
||||
|
||||
## Features
|
||||
|
||||
1. **Modern Graphics**: The GFX implementation is designed to adapt to the modern graphics APIs, it uses Vulkan on Windows and Android, Metal on Mac OS and iOS, and WebGL on Web platforms.
|
||||
2. **High Performance**: The runtime engine is built with half C++ and half TypeScript, low-level infrastructure, native platform adaptation, renderer, and scene management are all written in C++ to ensure high runtime performance. We continue to move heavy lifting work to native as much as possible.
|
||||
3. **Customizable Render Pipeline**: The render pipeline is designed to be fully customizable, it has supported the builtin forward and deferred render pipeline across all platforms. Developers can customize their render pipeline following the same approach.
|
||||
4. **Extensible Surface Shader**: The material system is built on Coco's effect format which uses GLSL 300, the shader programs will be converted to a suitable runtime format automatically. The surface shader permits to fully customize the surface material while ensuring a universal lighting model.
|
||||
5. **Physically Based Rendering (PBR)**: The standard effect adopts physically based rendering, along with the physically based camera and the lighting based on physical metrics, developers can easily achieve realistic and seamless rendering results across different environments.
|
||||
6. **Easy TypeScript API**: The user-level API set is provided in TypeScript, along with the powerful VSCode editor, development with Cocos Creator is incredibly efficient.
|
||||
|
||||
Besides all these highlights, COCOS 4 also provides a built-in animation system, physics system, particle system, terrain editing support, complex UI system, instant preview, etc.
|
||||
|
||||

|
||||
|
||||
## Development and Contribution Notice
|
||||
|
||||
Cocos Creator engine is open source and welcomes community participation, for open source engine development with Cocos Creator editor, you should fork this repository and setup [custom engine](https://docs.cocos.com/creator/manual/en/advanced-topics/engine-customization.html) in the editor.
|
||||
|
||||
### Prerequisite
|
||||
|
||||
- Install [node.js v9.11.2 +](https://nodejs.org/)
|
||||
- Install [gulp-cli v2.3.0 +](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)
|
||||
|
||||
### Clone
|
||||
|
||||
Clone this repository into your local environment.
|
||||
|
||||
### Install
|
||||
|
||||
In the cloned engine folder, run the following command to set the development environment:
|
||||
|
||||
```bash
|
||||
# download & build engine dependencies
|
||||
npm install
|
||||
```
|
||||
|
||||
This is all you have to do to set up the engine development environment.
|
||||
|
||||
### Build
|
||||
|
||||
- If running inside Cocos Creator, the engine will automatically compile and build after the editor window is opened. For more instructions on modifying the engine in Cocos Creator, please refer to [Engine Customization Workflow](https://docs.cocos.com/creator/manual/en/advanced-topics/engine-customization.html).
|
||||
- Outside the editor, you need to run the following command to build:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Please refer to [native readme](native/README.md) if you want to develop native applications.
|
||||
|
||||
### Contribution
|
||||
|
||||
You can contribute to the Cocos Creator open-source engine in many ways, they are very much appreciated:
|
||||
|
||||
1. Report bugs or feature requests by [creating an issue](https://github.com/cocos/cocos-engine/issues/new/choose).
|
||||
2. Participate in discussions in the [issues](https://github.com/cocos/cocos-engine/issues/).
|
||||
3. Create a pull request if you have fixed or improved anything, or implemented any features.
|
||||
4. Improve the documentation with pull requests to the [usage documentation repository](https://github.com/cocos/cocos-docs).
|
||||
5. Help other developers in our [Forum](https://discuss.cocos2d-x.org/c/creator).
|
||||
|
||||
### Contribution notice
|
||||
|
||||
If you are trying to make a pull request, some requirements must be met so that your pull request can be accepted:
|
||||
|
||||
1. Follow our [Cpp Coding Style Guide](./docs/CPP_CODING_STYLE.md) and [TypeScript Coding Style Reference](./docs/TS_CODING_STYLE.md).
|
||||
2. Try to integrate ESLint and [CPP auto fix tools](./docs/CPP_LINTER_AUTOFIX_GUIDE.md) in your coding environment.
|
||||
3. Link related issues or discussions in your pull request and clearly state the purpose of your pull request.
|
||||
4. Pass all automatic continuous integration tests.
|
||||
5. Request file owners or engine developers to review your pull request.
|
||||
6. Get one valid approval from the engine architects.
|
||||
|
||||
## Example Project
|
||||
|
||||
- [Mind Your Step 3D](https://github.com/cocos/cocos-tutorial-mind-your-step): Beginner's step-by-step tutorial project repo.
|
||||
- [Test Cases](https://github.com/cocos/cocos-test-projects): Unit test scenes for every engine module.
|
||||
- [Example Cases](https://github.com/cocos/cocos-example-projects): Simple yet expressive demo scenes for baseline testing and topic-specific case study.
|
||||
- [Awesome Cocos](https://github.com/cocos/awesome-cocos): You can find out other useful tools and show cases here.
|
||||
|
||||
## Links
|
||||
|
||||
- [Official site](https://www.cocos.com/)
|
||||
- [Download](https://www.cocos.com/en/creator/download)
|
||||
- [Documentation](https://docs.cocos.com/creator/manual/en/)
|
||||
- [API References](https://docs.cocos.com/creator/api/en/)
|
||||
- [Projects and road map](https://github.com/orgs/cocos/projects?query=is%3Aopen&type=new)
|
||||
- [Forum](https://discuss.cocos2d-x.org/c/creator)
|
||||
- Discord community: Search for Cocos in the Discover panel of Discord.
|
||||
# cocos4
|
||||
@@ -1,88 +0,0 @@
|
||||
<p align="center">
|
||||
<a href="https://www.cocos.com/">
|
||||
<img src="./ui.png"
|
||||
alt="Cocos Creator Logo">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://github.com/cocos/cocos-engine/stargazers">
|
||||
<img src="https://img.shields.io/github/stars/cocos/cocos-engine.svg?style=flat-square&colorB=4183c4"
|
||||
alt="stars">
|
||||
</a>
|
||||
<a href="https://github.com/cocos-creator/engine/network">
|
||||
<img src="https://img.shields.io/github/forks/cocos/cocos-engine.svg?style=flat-square&colorB=4183c4"
|
||||
alt="forks">
|
||||
</a>
|
||||
<a href="./LICENSE">
|
||||
<img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square&colorB=4183c4"
|
||||
alt="license">
|
||||
</a>
|
||||
<a href="https://twitter.com/CocosEngine">
|
||||
<img src="https://img.shields.io/twitter/follow/CocosEngine.svg?logo=twitter&label=follow&style=flat-square&colorB=4183c4"
|
||||
alt="twitter">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# COCOS 4
|
||||
|
||||
COCOS 4 是一个开源的、高性能的、跨平台的游戏和交互式内容开发引擎。基于成熟的 C++ 架构,它提供强大的渲染能力和灵活的脚本绑定,支持"一次编写,随处运行"的哲学。
|
||||
|
||||
以前,_Cocos Creator_ 指的是结合了引擎和编辑器的产品,跨越 1.x、2.x 和 3.x 版本。为了采纳纯开源模式并充分整合 AI,我们正在将引擎与编辑器分离。这是一个重大且必要的演进。往后:
|
||||
|
||||
**COCOS** 将专指引擎,主版本号升级到 **COCOS 4**。跨平台框架和编辑器的核心组件将被转换为 CLI 工具并整合到引擎的核心功能中。这代表着这个开源版本的一个重要新增功能。
|
||||
|
||||
## 引擎特性
|
||||
|
||||
1. **现代图形技术**:GFX 实现设计用于适配现代图形 API,在 Windows 和 Android 上使用 Vulkan,在 Mac OS 和 iOS 上使用 Metal,在 Web 平台上使用 WebGL。
|
||||
2. **高性能**:运行时引擎由 C++ 和 TypeScript 各占一半构成,低层基础设施、原生平台适配、渲染器和场景管理都用 C++ 编写以保证高运行时性能。我们不断将更多的繁重工作转移到原生代码中。
|
||||
3. **可定制化渲染管线**:渲染管线被设计为完全可定制的,已在所有平台上支持内置的正向和延迟渲染管线。开发者可以按照相同的方法自定义他们的渲染管线。
|
||||
4. **可扩展的表面着色器**:材质系统建立在 Cocos 的 effect 格式之上,使用 GLSL 300,着色器程序将自动转换为合适的运行时格式。表面着色器允许充分定制表面材质,同时确保通用的光照模型。
|
||||
5. **基于物理的渲染(PBR)**:标准效果采用基于物理的渲染,结合基于物理的摄像机和基于物理参数的光照,开发者可以轻松在不同环境中实现逼真、无缝的渲染效果。
|
||||
6. **易用的 TypeScript API**:用户级 API 集由 TypeScript 提供,加上强大的 VSCode 编辑器,使用 Cocos Creator 开发效率极高。
|
||||
|
||||

|
||||
|
||||
引擎部分主要由 TypeScript 实现,支持用户使用 TypeScript 来编写游戏逻辑。另外在 `native` 目录中则提供了引擎在原生平台上的底层实现。引擎本身大部分是独立的,有成熟的运行时,包括光照、材质、粒子、动画、物理、UI、地形、声音、资源和场景节点管理等模块。同时支持原生和 Web 浏览器,包括 Windows、Mac、iOS、Android、HarmonyOS、Web。更令人兴奋的是,它支持各类小游戏平台,如微信小游戏和 Facebook Instant Games。
|
||||
|
||||
## 开发
|
||||
|
||||
### 环境要求
|
||||
|
||||
- 安装 [node.js v9.11.2 +](https://nodejs.org/)
|
||||
- 安装 [gulp-cli v2.3.0 +](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)
|
||||
|
||||
### 安装
|
||||
|
||||
在本地克隆仓库中,运行以下命令设置开发环境:
|
||||
|
||||
```bash
|
||||
# 下载 & 构建引擎依赖
|
||||
npm install
|
||||
```
|
||||
|
||||
这就完成了引擎开发环境搭建工作。
|
||||
|
||||
### 编译
|
||||
|
||||
- Cocos Creator 将在编辑器窗口打开后自动编译和构建引擎。更多在 Cocos Creator 中修改引擎的说明,请参考 [引擎定制工作流程](https://docs.cocos.com/creator/manual/zh/advanced-topics/engine-customization.html)。
|
||||
- 如果在编辑器之外单独使用,你需要运行以下命令来构建:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
## 范例工程
|
||||
|
||||
- [Example Cases](https://github.com/cocos/cocos-example-projects):简单而富有表现力的演示场景,用于基线测试和特定主题的案例学习
|
||||
- [Mind Your Step 3D](https://github.com/cocos/cocos-tutorial-mind-your-step):初学者的逐步教程项目
|
||||
- [UI Demo](https://github.com/cocos/cocos-example-ui):各种 UI 组件的使用案例
|
||||
- [Test Cases](https://github.com/cocos/cocos-test-projects):引擎各模块的测试场景
|
||||
|
||||
## 链接
|
||||
|
||||
- [官网](https://www.cocos.com/products#CocosCreator)
|
||||
- [下载](https://www.cocos.com/creator)
|
||||
- [文档](https://docs.cocos.com/creator/manual/zh/)
|
||||
- [API 参考](https://docs.cocos.com/creator/api/zh/)
|
||||
- [论坛](http://forum.cocos.org/c/Creator)
|
||||
- [Road Map](https://trello.com/b/JWVRRxMG/cocos-creator-roadmap)
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
module.exports = (api) => {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: [
|
||||
[require('@babel/preset-env'), {
|
||||
targets: { node: 'current', },
|
||||
loose: true,
|
||||
}],
|
||||
[require('@cocos/babel-preset-cc'), {
|
||||
allowDeclareFields: true,
|
||||
}],
|
||||
],
|
||||
};
|
||||
};
|
||||
-909
@@ -1,909 +0,0 @@
|
||||
{
|
||||
"$schema": "./cc.config.schema.json",
|
||||
"features": {
|
||||
"base": {
|
||||
"modules": ["base"],
|
||||
"dependentAssets": [
|
||||
"970b0598-bcb0-4714-91fb-2e81440dccd8",
|
||||
"bcd64cc6-2dd9-43f6-abbe-66318d332032",
|
||||
"d930590d-bb92-4cc8-8bd1-23cd027f9edf",
|
||||
"a3cd009f-0ab0-420d-9278-b9fdab939bbc"
|
||||
]
|
||||
},
|
||||
"gfx-webgl": {
|
||||
"modules": ["gfx-webgl"]
|
||||
},
|
||||
"gfx-webgl2": {
|
||||
"modules": ["gfx-webgl2"]
|
||||
},
|
||||
"gfx-empty": {
|
||||
"modules": ["gfx-empty"]
|
||||
},
|
||||
"gfx-webgpu": {
|
||||
"modules": [
|
||||
"gfx-webgpu"
|
||||
]
|
||||
},
|
||||
"3d": {
|
||||
"modules": ["3d"],
|
||||
"overrideConstants": {
|
||||
"USE_3D": true
|
||||
},
|
||||
"dependentAssets": [
|
||||
"511d2633-09a7-4bdd-ac42-f778032124b3",
|
||||
"5d45aa00-e064-4938-b314-4265f0c2258c",
|
||||
"9361fd90-ba52-4f84-aa93-6e878fd576ca"
|
||||
]
|
||||
},
|
||||
"animation": {
|
||||
"modules": ["animation"]
|
||||
},
|
||||
"skeletal-animation": {
|
||||
"modules": ["animation", "skeletal-animation"]
|
||||
},
|
||||
"2d": {
|
||||
"modules": ["2d", "sorting"],
|
||||
"dependentAssets": [
|
||||
"60f7195c-ec2a-45eb-ba94-8955f60e81d0",
|
||||
"1c02ae6f-4492-4915-b8f8-7492a3b1e4cd",
|
||||
"810e96e4-e456-4468-9b59-f4e8f39732c0",
|
||||
"efe8e2a3-eace-427b-b4f1-cb8a937ec77d",
|
||||
"e9aa9a3e-5b2b-4ac7-a2c7-073de2b2b24f",
|
||||
"8bbdbcdd-5cd4-4100-b6d5-b7c9625b6107",
|
||||
"50f4348b-c883-4e2f-8f11-ce233b859fa1",
|
||||
"fda095cb-831d-4601-ad94-846013963de8",
|
||||
"f92806d7-1768-443f-afe8-12bcde84d0f0",
|
||||
"dd3a144d-ab7f-41f0-82b8-2e43a090d496",
|
||||
"f0416e68-0200-4b77-a926-4f9d16e494da"
|
||||
]
|
||||
},
|
||||
"rich-text": {
|
||||
"modules": ["rich-text"],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"mask": {
|
||||
"modules": ["mask"],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"graphics": {
|
||||
"modules": ["graphics"],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"ui-skew": {
|
||||
"modules": ["ui-skew"],
|
||||
"overrideConstants": {
|
||||
"USE_UI_SKEW": true
|
||||
},
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"ui": {
|
||||
"modules": ["ui", "2d"]
|
||||
},
|
||||
"affine-transform": {
|
||||
"modules": ["affine-transform"]
|
||||
},
|
||||
"sorting-2d": {
|
||||
"modules": ["sorting-2d"],
|
||||
"overrideConstants": {
|
||||
"USE_SORTING_2D": true
|
||||
},
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"particle": {
|
||||
"modules": ["particle"],
|
||||
"dependentAssets": [
|
||||
"d1346436-ac96-4271-b863-1f4fdead95b0",
|
||||
"971bdb23-3ff6-43eb-b422-1c30165a3663",
|
||||
"17debcc3-0a6b-4b8a-b00b-dc58b885581e",
|
||||
"711ebe11-f673-4cd9-9a83-63c60ba54c5b",
|
||||
"c0143906-9aed-447e-9436-2ae8512d1b6e",
|
||||
"14da1725-c4c2-42b4-ab08-ee0aeb6898b3",
|
||||
"081cab31-dccd-428e-8652-f2404cc81c47",
|
||||
"78e0584a-4343-4727-8f37-e14e65c2a2db"
|
||||
]
|
||||
},
|
||||
"particle-2d": {
|
||||
"modules": ["particle-2d"],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"physics-framework": {
|
||||
"modules": ["physics-framework"]
|
||||
},
|
||||
"physics-cannon": {
|
||||
"modules": ["physics-cannon", "physics-framework"],
|
||||
"dependentAssets": ["ba21476f-2866-4f81-9c4d-6e359316e448"]
|
||||
},
|
||||
"physics-physx": {
|
||||
"modules": ["physics-physx", "physics-framework"],
|
||||
"dependentAssets": ["ba21476f-2866-4f81-9c4d-6e359316e448"]
|
||||
},
|
||||
"physics-ammo": {
|
||||
"modules": ["physics-ammo", "physics-framework"],
|
||||
"dependentAssets": ["ba21476f-2866-4f81-9c4d-6e359316e448"]
|
||||
},
|
||||
"physics-builtin": {
|
||||
"modules": ["physics-builtin", "physics-framework"],
|
||||
"dependentAssets": ["ba21476f-2866-4f81-9c4d-6e359316e448"]
|
||||
},
|
||||
"physics-2d-framework": {
|
||||
"modules": ["physics-2d-framework"]
|
||||
},
|
||||
"physics-2d-box2d-jsb": {
|
||||
"modules": ["physics-2d-box2d-jsb", "physics-2d-framework"]
|
||||
},
|
||||
"physics-2d-box2d": {
|
||||
"modules": ["physics-2d-box2d", "physics-2d-framework"]
|
||||
},
|
||||
"physics-2d-builtin": {
|
||||
"modules": ["physics-2d-builtin", "physics-2d-framework"]
|
||||
},
|
||||
"physics-2d-box2d-wasm": {
|
||||
"modules": ["physics-2d-box2d-wasm", "physics-2d-framework"]
|
||||
},
|
||||
"intersection-2d": {
|
||||
"modules": ["intersection-2d"]
|
||||
},
|
||||
"primitive": {
|
||||
"modules": ["primitive"]
|
||||
},
|
||||
"profiler": {
|
||||
"modules": ["profiler"],
|
||||
"dependentAssets": ["871c3b6c-7379-419d-bda3-794b239ab90d"]
|
||||
},
|
||||
"occlusion-query": {
|
||||
"modules": [],
|
||||
"dependentAssets": ["d9937e59-61fe-4ec6-92ab-7ac5a19c89b0"]
|
||||
},
|
||||
"geometry-renderer": {
|
||||
"modules": ["geometry-renderer"],
|
||||
"dependentAssets": ["4bb480dd-8384-4bc9-987f-de67cc53052a"]
|
||||
},
|
||||
"debug-renderer": {
|
||||
"modules": [],
|
||||
"dependentAssets": [
|
||||
"ff9be190-20a4-4e48-b68c-76e3c7cff085",
|
||||
"0835f102-5471-47a3-9a76-01c07ac9cdb2",
|
||||
"b5475517-23b9-4873-bc1a-968d96616081",
|
||||
"0ed97c56-390e-4dd1-96b7-e7f2d93a98ed",
|
||||
"b23391b6-52eb-46a6-8da1-6244d9d315fb"
|
||||
]
|
||||
},
|
||||
"audio": {
|
||||
"modules": ["audio"]
|
||||
},
|
||||
"video": {
|
||||
"modules": ["video"]
|
||||
},
|
||||
"xr": {
|
||||
"modules": ["xr"],
|
||||
"overrideConstants": {
|
||||
"USE_XR": true
|
||||
}
|
||||
},
|
||||
"light-probe": {
|
||||
"modules": [ "light-probe" ]
|
||||
},
|
||||
"terrain": {
|
||||
"modules": ["terrain"],
|
||||
"dependentAssets": ["1d08ef62-a503-4ce2-8b9a-46c90873f7d3"]
|
||||
},
|
||||
"webview": {
|
||||
"modules": ["webview"]
|
||||
},
|
||||
"tween": {
|
||||
"modules": ["tween"]
|
||||
},
|
||||
"tiled-map": {
|
||||
"modules": ["tiled-map"],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"vendor-google": {
|
||||
"modules": ["vendor-google"],
|
||||
"intrinsicFlags": {
|
||||
"USE_VENDOR_GOOGLE": true
|
||||
}
|
||||
},
|
||||
"spine-3.8": {
|
||||
"modules": ["spine"],
|
||||
"dependentAssets": [
|
||||
"c27215d8-6835-4b68-bfbb-bdeac6100c04",
|
||||
"b5d6115f-0370-4d7c-aad3-c194cc71cf98"
|
||||
],
|
||||
"dependentModules": ["2d"],
|
||||
"intrinsicFlags": {
|
||||
"SPINE_3_8": true
|
||||
}
|
||||
},
|
||||
"spine-4.2": {
|
||||
"modules": ["spine"],
|
||||
"dependentAssets": [
|
||||
"c27215d8-6835-4b68-bfbb-bdeac6100c04",
|
||||
"b5d6115f-0370-4d7c-aad3-c194cc71cf98"
|
||||
],
|
||||
"dependentModules": ["2d"],
|
||||
"intrinsicFlags": {
|
||||
"SPINE_4_2": true
|
||||
}
|
||||
},
|
||||
"dragon-bones": {
|
||||
"modules": ["dragon-bones"],
|
||||
"dependentAssets":[
|
||||
"c27215d8-6835-4b68-bfbb-bdeac6100c04",
|
||||
"b5d6115f-0370-4d7c-aad3-c194cc71cf98"
|
||||
],
|
||||
"dependentModules": ["2d"]
|
||||
},
|
||||
"marionette": {
|
||||
"modules": [],
|
||||
"intrinsicFlags": {
|
||||
"MARIONETTE": true
|
||||
}
|
||||
},
|
||||
"procedural-animation": {
|
||||
"modules": [],
|
||||
"intrinsicFlags": {
|
||||
"PROCEDURAL_ANIMATION": true
|
||||
}
|
||||
},
|
||||
"custom-pipeline": {
|
||||
"modules": ["custom-pipeline"],
|
||||
"dependentAssets": [
|
||||
"6a2d0734-bd9e-4ddf-946e-caa52498cb75"
|
||||
]
|
||||
},
|
||||
"custom-pipeline-builtin-scripts": {
|
||||
"modules": [],
|
||||
"dependentScripts": [
|
||||
"ff9b0199-ce04-4cfe-86cc-6c719f08d6e4",
|
||||
"de1c2107-70c8-4021-8459-6399f24d01c6",
|
||||
"cbf30902-517f-40dc-af90-a550bac27cf1",
|
||||
"5c601d96-e4c7-4698-991b-7ee674b11079"
|
||||
]
|
||||
},
|
||||
"custom-pipeline-post-process": {
|
||||
"modules": ["custom-pipeline-post-process"],
|
||||
"dependentAssets":[
|
||||
"15049ccd-4dd7-451e-a8ae-af66735c929e",
|
||||
"521c5f6e-1a26-42e2-8108-4400c912d9bf",
|
||||
"4c3ce6de-e6d1-47f7-aa36-36b9b58f72d3",
|
||||
"4361db28-3f24-44cc-8e51-32ee5fd651ac",
|
||||
"cafd95c9-c558-46f9-9812-1224b65c09ee",
|
||||
"28d6d6b8-3f66-4a73-9795-17a0852ba2d4",
|
||||
"2df0a40b-26c2-47ce-be0d-4d3cd4164737",
|
||||
"dace6a58-1705-48c7-a275-70afc9534e88",
|
||||
"ec8106fe-05bf-4e94-943c-e0d3b7bb5e45",
|
||||
"39f74202-ead5-4a45-b966-273d526adbf1",
|
||||
"8f6ac413-2f1e-4b88-b26f-54556b5dd510",
|
||||
"45e7c0c8-2699-4912-b45f-d42bb8384189",
|
||||
"84ac6f69-3086-455a-86a4-561da8ee710b",
|
||||
"5c601d96-e4c7-4698-991b-7ee674b11079",
|
||||
"bf0a6d94-58f0-4ad2-bdf2-c4a31c7dd856"
|
||||
],
|
||||
"dependentModules": ["custom-pipeline"]
|
||||
},
|
||||
"legacy-pipeline": {
|
||||
"modules": ["legacy-pipeline"],
|
||||
"dependentScripts": [
|
||||
"b2bd1fa7-8d7c-49c5-a158-df29a6d3a594"
|
||||
]
|
||||
},
|
||||
"websocket": {
|
||||
"modules": [],
|
||||
"isNativeOnly": true
|
||||
},
|
||||
"websocket-server": {
|
||||
"modules": [],
|
||||
"isNativeOnly": true
|
||||
},
|
||||
"meshopt": {
|
||||
"modules": [],
|
||||
"overrideConstants": {
|
||||
"CULL_MESHOPT": false
|
||||
}
|
||||
},
|
||||
"worker": {
|
||||
"modules": ["worker"]
|
||||
},
|
||||
"worker-pool": {
|
||||
"modules": ["worker", "worker-pool"],
|
||||
"dependentModules": ["worker"]
|
||||
},
|
||||
"webassembly": {
|
||||
"modules": ["webassembly"]
|
||||
}
|
||||
},
|
||||
"moduleOverrides": [{
|
||||
"test": "true",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"internal:native": "cocos/native-binding/impl.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.mode === 'BUILD'",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {}
|
||||
},
|
||||
{
|
||||
"test": "!context.buildTimeConstants.NATIVE",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/2d/renderer/native-2d.ts": "cocos/2d/renderer/native-2d-empty.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.NATIVE",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/rendering/index.ts": "cocos/rendering/index.jsb.ts",
|
||||
"cocos/rendering/render-pipeline.ts": "cocos/rendering/render-pipeline.jsb.ts",
|
||||
"cocos/rendering/render-stage.ts": "cocos/rendering/render-stage.jsb.ts",
|
||||
"cocos/rendering/geometry-renderer.ts": "cocos/rendering/geometry-renderer.jsb.ts",
|
||||
"cocos/rendering/custom/index.ts": "cocos/rendering/custom/index.jsb.ts",
|
||||
"cocos/rendering/legacy/index.ts": "cocos/rendering/legacy/index.jsb.ts",
|
||||
"cocos/render-scene/core/native-pools.ts": "cocos/render-scene/core/native-pools.jsb.ts",
|
||||
"cocos/render-scene/core/material-instance.ts": "cocos/render-scene/core/material-instance.jsb.ts",
|
||||
"cocos/render-scene/core/pass.ts": "cocos/render-scene/core/pass.jsb.ts",
|
||||
"cocos/render-scene/core/program-lib.ts": "cocos/render-scene/core/program-lib.jsb.ts",
|
||||
"cocos/render-scene/core/render-window.ts": "cocos/render-scene/core/render-window.jsb.ts",
|
||||
"cocos/render-scene/scene/camera.ts": "cocos/render-scene/scene/camera.jsb.ts",
|
||||
"cocos/render-scene/scene/model.ts": "cocos/render-scene/scene/model.jsb.ts",
|
||||
"cocos/render-scene/core/render-scene.ts": "cocos/render-scene/core/render-scene.jsb.ts",
|
||||
"cocos/render-scene/scene/submodel.ts": "cocos/render-scene/scene/submodel.jsb.ts",
|
||||
"cocos/render-scene/scene/index.ts": "cocos/render-scene/scene/index.jsb.ts",
|
||||
"cocos/render-scene/scene/reflection-probe.ts": "cocos/render-scene/scene/reflection-probe.jsb.ts",
|
||||
"cocos/2d/renderer/native-2d.ts": "cocos/2d/renderer/native-2d.jsb.ts",
|
||||
"cocos/gfx/base/pipeline-state.ts": "cocos/gfx/base/pipeline-state.jsb.ts",
|
||||
"cocos/gfx/base/pipeline-sub-state.ts": "cocos/gfx/base/pipeline-sub-state.jsb.ts",
|
||||
"cocos/gfx/index.ts": "cocos/gfx/index.jsb.ts",
|
||||
"cocos/spine/index.ts": "cocos/spine/index.jsb.ts",
|
||||
"cocos/dragon-bones/index.ts": "cocos/dragon-bones/index.jsb.ts",
|
||||
"cocos/physics/physx/instantiate.ts": "cocos/physics/physx/instantiate.jsb.ts",
|
||||
"cocos/scene-graph/node.ts": "cocos/scene-graph/node.jsb.ts",
|
||||
"cocos/scene-graph/scene.ts": "cocos/scene-graph/scene.jsb.ts",
|
||||
"cocos/scene-graph/scene-globals.ts": "cocos/scene-graph/scene-globals.jsb.ts",
|
||||
"cocos/scene-graph/index.ts": "cocos/scene-graph/index.jsb.ts",
|
||||
"cocos/root.ts": "cocos/root.jsb.ts",
|
||||
"cocos/asset/asset-manager/builtin-res-mgr.ts": "cocos/asset/asset-manager/builtin-res-mgr.jsb.ts",
|
||||
"cocos/asset/assets/index.ts": "cocos/asset/assets/index.jsb.ts",
|
||||
"cocos/asset/assets/asset.ts": "cocos/asset/assets/asset.jsb.ts",
|
||||
"cocos/asset/assets/buffer-asset.ts": "cocos/asset/assets/buffer-asset.jsb.ts",
|
||||
"cocos/asset/assets/render-texture.ts": "cocos/asset/assets/render-texture.jsb.ts",
|
||||
"cocos/asset/assets/simple-texture.ts": "cocos/asset/assets/simple-texture.jsb.ts",
|
||||
"cocos/asset/assets/scene-asset.ts": "cocos/asset/assets/scene-asset.jsb.ts",
|
||||
"cocos/asset/assets/effect-asset.ts": "cocos/asset/assets/effect-asset.jsb.ts",
|
||||
"cocos/asset/assets/image-asset.ts": "cocos/asset/assets/image-asset.jsb.ts",
|
||||
"cocos/asset/assets/texture-base.ts": "cocos/asset/assets/texture-base.jsb.ts",
|
||||
"cocos/asset/assets/texture-2d.ts": "cocos/asset/assets/texture-2d.jsb.ts",
|
||||
"cocos/asset/assets/texture-cube.ts": "cocos/asset/assets/texture-cube.jsb.ts",
|
||||
"cocos/asset/assets/material.ts": "cocos/asset/assets/material.jsb.ts",
|
||||
"cocos/asset/assets/rendering-sub-mesh.ts": "cocos/asset/assets/rendering-sub-mesh.jsb.ts",
|
||||
"cocos/3d/assets/mesh.ts": "cocos/3d/assets/mesh.jsb.ts",
|
||||
"cocos/3d/assets/skeleton.ts": "cocos/3d/assets/skeleton.jsb.ts",
|
||||
"cocos/3d/models/morph-model.ts": "cocos/3d/models/morph-model.jsb.ts",
|
||||
"cocos/3d/models/skinning-model.ts": "cocos/3d/models/skinning-model.jsb.ts",
|
||||
"cocos/3d/models/baked-skinning-model.ts": "cocos/3d/models/baked-skinning-model.jsb.ts",
|
||||
"cocos/3d/misc/create-mesh.ts": "cocos/3d/misc/create-mesh.jsb.ts",
|
||||
"cocos/gi/light-probe/light-probe.ts": "cocos/gi/light-probe/light-probe.jsb.ts",
|
||||
"cocos/gi/light-probe/delaunay.ts": "cocos/gi/light-probe/delaunay.jsb.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.HTML5",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"pal/minigame": "pal/minigame/non-minigame.js",
|
||||
"pal/worker": "pal/worker/web/index.js",
|
||||
"pal/audio": "pal/audio/web/player.js",
|
||||
"pal/system-info": "pal/system-info/web/system-info.js",
|
||||
"pal/screen-adapter": "pal/screen-adapter/web/screen-adapter.js",
|
||||
"pal/input": "pal/input/web/index.js",
|
||||
"pal/env": "pal/env/web/env.js",
|
||||
"pal/pacer": "pal/pacer/pacer-web.js",
|
||||
"pal/wasm": "pal/wasm/wasm-web.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.NATIVE",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"pal/minigame": "pal/minigame/non-minigame.js",
|
||||
"pal/worker": "pal/worker/native/index.js",
|
||||
"pal/audio": "pal/audio/native/player.js",
|
||||
"pal/system-info": "pal/system-info/native/system-info.js",
|
||||
"pal/screen-adapter": "pal/screen-adapter/native/screen-adapter.js",
|
||||
"pal/input": "pal/input/native/index.js",
|
||||
"pal/env": "pal/env/native/env.js",
|
||||
"pal/pacer": "pal/pacer/pacer-native.js",
|
||||
"pal/wasm": "pal/wasm/wasm-native.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.MINIGAME",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"pal/minigame": "pal/minigame/{{context.platform.toLowerCase()}}.js",
|
||||
"pal/worker": "pal/worker/minigame/index.js",
|
||||
"pal/audio": "pal/audio/minigame/player.js",
|
||||
"pal/system-info": "pal/system-info/minigame/system-info.js",
|
||||
"pal/screen-adapter": "pal/screen-adapter/minigame/screen-adapter.js",
|
||||
"pal/input": "pal/input/minigame/index.js",
|
||||
"pal/env": "pal/env/minigame/env.js",
|
||||
"pal/pacer": "pal/pacer/pacer-minigame.js",
|
||||
"pal/wasm": "pal/wasm/wasm-minigame.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.RUNTIME_BASED",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"pal/minigame": "pal/minigame/runtime.js",
|
||||
"pal/worker": "pal/worker/minigame/index.js",
|
||||
"pal/audio": "pal/audio/minigame/player.js",
|
||||
"pal/system-info": "pal/system-info/minigame/system-info.js",
|
||||
"pal/screen-adapter": "pal/screen-adapter/minigame/screen-adapter.js",
|
||||
"pal/input": "pal/input/minigame/index.js",
|
||||
"pal/env": "pal/env/runtime/env.js",
|
||||
"pal/pacer": "pal/pacer/pacer-minigame.js",
|
||||
"pal/wasm": "pal/wasm/wasm-minigame.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.NODEJS",
|
||||
"isVirtualModule": true,
|
||||
"overrides": {
|
||||
"pal/minigame": "pal/minigame/non-minigame.js",
|
||||
"pal/worker": "pal/worker/nodejs/index.js",
|
||||
"pal/audio": "pal/audio/nodejs/player.js",
|
||||
"pal/system-info": "pal/system-info/nodejs/system-info.js",
|
||||
"pal/screen-adapter": "pal/screen-adapter/nodejs/screen-adapter.js",
|
||||
"pal/input": "pal/input/nodejs/index.js",
|
||||
"pal/env": "pal/env/nodejs/env.js",
|
||||
"pal/pacer": "pal/pacer/pacer-nodejs.js",
|
||||
"pal/wasm": "pal/wasm/wasm-nodejs.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.NOT_PACK_PHYSX_LIBS",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/physics/physx/physx.asmjs.ts": "cocos/physics/physx/physx.null.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "!context.buildTimeConstants.MARIONETTE",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/animation/marionette/runtime-exports.ts": "cocos/animation/marionette/index-empty.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "!context.buildTimeConstants.PROCEDURAL_ANIMATION",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/animation/marionette/pose-graph/runtime-exports.ts": "cocos/animation/marionette/pose-graph/runtime-exports-empty.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_3_8 && context.buildTimeConstants.SPINE_4_2",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-dynamic.ts",
|
||||
"cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-dynamic.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_3_8 && !context.buildTimeConstants.SPINE_4_2",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-3.8.ts",
|
||||
"cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-3.8.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_4_2 && !context.buildTimeConstants.SPINE_3_8",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-4.2.ts",
|
||||
"cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-4.2.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.USE_VENDOR_GOOGLE",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"vendor/google/index.ts": "vendor/google/impl.ts"
|
||||
}
|
||||
}
|
||||
],
|
||||
"includes": [
|
||||
"./exports/**/*.{ts,js,json}",
|
||||
"./editor/exports/**/*.{ts,js,json}",
|
||||
"./cocos/**/*.{ts,js,json}",
|
||||
"./pal/**/*.{ts,js,json}"
|
||||
],
|
||||
|
||||
"constants": {
|
||||
"HTML5": {
|
||||
"comment": "Running in Web platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"NATIVE": {
|
||||
"comment": "Running in native platform (mobile app, desktop app, or simulator).",
|
||||
"type": "boolean",
|
||||
"value": "$ANDROID || $IOS || $MAC || $WINDOWS || $LINUX || $OHOS || $OPEN_HARMONY",
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"ANDROID": {
|
||||
"comment": "Running in ANDROID platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"IOS": {
|
||||
"comment": "Running in IOS platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"MAC": {
|
||||
"comment": "Running in MAC platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"WINDOWS": {
|
||||
"comment": "Running in WINDOWS platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"LINUX": {
|
||||
"comment": "Running in LINUX platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"OHOS": {
|
||||
"comment": "Running in OHOS platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"OPEN_HARMONY": {
|
||||
"comment": "Running in OPEN_HARMONY platform",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false,
|
||||
"dynamic": false
|
||||
},
|
||||
"WECHAT": {
|
||||
"comment": "Running in the Wechat's mini game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"WECHAT_MINI_PROGRAM": {
|
||||
"comment": "Running in the Wechat's mini program.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false
|
||||
},
|
||||
"XIAOMI": {
|
||||
"comment": "Running in the xiaomi's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"ALIPAY": {
|
||||
"comment": "Running in the alipay's mini game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"TAOBAO": {
|
||||
"comment": "Running in the taobao creative app.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false
|
||||
},
|
||||
"TAOBAO_MINIGAME": {
|
||||
"comment": "Running in the taobao mini game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": false
|
||||
},
|
||||
"BYTEDANCE": {
|
||||
"comment": "Running in the ByteDance's mini game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"OPPO": {
|
||||
"comment": "Running in the oppo's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"VIVO": {
|
||||
"comment": "Running in the vivo's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"HUAWEI": {
|
||||
"comment": "Running in the huawei's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"MIGU": {
|
||||
"comment": "Running in the migu's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"HONOR": {
|
||||
"comment": "Running in the honor's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"COCOS_RUNTIME": {
|
||||
"comment": "Running in the cocos runtime.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"SUD": {
|
||||
"comment": "Running in the sud's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"SUDV2": {
|
||||
"comment": "Running in the sud v2's quick game.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"NODEJS": {
|
||||
"comment": "Running in the Node.js environment.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"EDITOR": {
|
||||
"comment": "Running in the editor.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"EDITOR_NOT_IN_PREVIEW" : {
|
||||
"comment": "Run in editor but not in editor preview.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": false,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"PREVIEW": {
|
||||
"comment": "Preview in browser or simulator.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"BUILD": {
|
||||
"comment": "Running in published project.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"TEST": {
|
||||
"comment": "Running in the engine's unit test.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"ccGlobal": true,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
|
||||
"DEBUG": {
|
||||
"comment": "Running debug mode.",
|
||||
"type": "boolean",
|
||||
"value": true,
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
|
||||
"SERVER_MODE": {
|
||||
"comment": "Running in the server mode.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"DEV": {
|
||||
"comment": "Running in the editor or preview.",
|
||||
"type": "boolean",
|
||||
"value": "$EDITOR || $PREVIEW || $TEST",
|
||||
"ccGlobal": true,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"MINIGAME": {
|
||||
"comment": "Running in mini game.",
|
||||
"type": "boolean",
|
||||
"value": "$WECHAT || $WECHAT_MINI_PROGRAM || $XIAOMI || $ALIPAY || $TAOBAO || $TAOBAO_MINIGAME || $BYTEDANCE",
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"RUNTIME_BASED": {
|
||||
"comment": "Running in runtime based environment.",
|
||||
"type": "boolean",
|
||||
"value": "$OPPO || $VIVO || $HUAWEI || $MIGU || $HONOR || $COCOS_RUNTIME || $SUD || $SUDV2",
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"SUPPORT_JIT": {
|
||||
"comment": "Support JIT.",
|
||||
"type": "boolean",
|
||||
"value": "!(($PREVIEW && !$NATIVE) || $MINIGAME || $RUNTIME_BASED || $OPEN_HARMONY)",
|
||||
"ccGlobal": true,
|
||||
"internal": false
|
||||
},
|
||||
"JSB": {
|
||||
"comment": "Running in environment where using JSB as the JavaScript interface binding scheme.",
|
||||
"type": "boolean",
|
||||
"value": "$NATIVE",
|
||||
"ccGlobal": true,
|
||||
"internal": false,
|
||||
"dynamic": true
|
||||
},
|
||||
"NOT_PACK_PHYSX_LIBS": {
|
||||
"comment": "This is an internal constant to determine whether pack physx libs.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"NET_MODE": {
|
||||
"comment": "The network access mode.\n- 0 Client\n- 1 ListenServer\n- 2 HostServer",
|
||||
"type": "number",
|
||||
"value": 0,
|
||||
"internal": false
|
||||
},
|
||||
"WEBGPU": {
|
||||
"comment": "Running with webgpu rendering backend.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"NATIVE_CODE_BUNDLE_MODE": {
|
||||
"comment": "Native code (wasm/asmjs) bundle mode, 0: asmjs, 1: wasm, 2: both",
|
||||
"type": "number",
|
||||
"value": 2,
|
||||
"internal": true
|
||||
},
|
||||
"WASM_SUBPACKAGE": {
|
||||
"comment": "An internal constant to indicate whether we use wasm assets as minigame subpackage.\nThis is useful when we need to reduce code size.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"CULL_MESHOPT": {
|
||||
"comment": "An internal constant to indicate whether we cull the meshopt wasm module and asm.js module.",
|
||||
"type": "boolean",
|
||||
"value": true,
|
||||
"internal": true
|
||||
},
|
||||
"LOAD_SPINE_MANUALLY": {
|
||||
"comment": "An internal constant to indicate whether we need to load spine wasm/asmjs module manually.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"LOAD_BOX2D_MANUALLY": {
|
||||
"comment": "An internal constant to indicate whether we need to load box2d wasm/asmjs module manually.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"LOAD_BULLET_MANUALLY": {
|
||||
"comment": "An internal constant to indicate whether we need to load bullet wasm/asmjs module manually.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"LOAD_PHYSX_MANUALLY": {
|
||||
"comment": "An internal constant to indicate whether we need to load physx wasm/asmjs module manually.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"USE_3D": {
|
||||
"comment": "An internal constant to indicate whether we're using 3d module.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"USE_UI_SKEW": {
|
||||
"comment": "An internal constant to indicate whether we're using ui-skew module.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"USE_XR": {
|
||||
"comment": "An internal constant to indicate whether we're using xr module.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
},
|
||||
"USE_SORTING_2D": {
|
||||
"comment": "An internal constant to indicate whether we're using sorting-2d module.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
}
|
||||
},
|
||||
|
||||
"optimizeDecorators": {
|
||||
"fieldDecorators": [
|
||||
"property", "serializable", "formerlySerializedAs", "editorOnly", "uniquelyReferenced",
|
||||
"type", "override", "executeInEditMode", "menu", "playOnFocus", "inspector", "icon", "help",
|
||||
"editable", "visible", "readOnly", "displayName", "tooltip", "group", "range", "rangeMin",
|
||||
"rangeMax", "rangeStep", "slide", "displayOrder", "unit", "radian", "multiline", "disallowAnimation",
|
||||
"requireComponent", "executionOrder", "disallowMultiple", "allowReplicated", "ccclass"
|
||||
],
|
||||
|
||||
"editorDecorators": [
|
||||
"executeInEditMode", "menu", "playOnFocus", "inspector", "icon", "help", "editable", "visible",
|
||||
"readOnly", "displayName", "tooltip", "group", "range", "rangeMin", "rangeMax", "rangeStep", "slide",
|
||||
"displayOrder", "unit", "radian", "multiline", "disallowAnimation"
|
||||
]
|
||||
},
|
||||
|
||||
"treeShake": {
|
||||
"noSideEffectFiles": [
|
||||
"cocos/sorting/sorting-layers.ts",
|
||||
"cocos/xr/event/xr-event-handle.ts",
|
||||
"cocos/xr/xr-enums.ts",
|
||||
"cocos/serialization/instantiate-jit.ts",
|
||||
"cocos/game/splash-screen.ts",
|
||||
"cocos/core/utils/jsb-utils.ts",
|
||||
"cocos/asset/asset-manager/weak-cache.ts",
|
||||
"cocos/2d/framework/ui-skew-utils.ts",
|
||||
"cocos/spine/lib/spine-binary.ts",
|
||||
"pal/input/minigame/gamepad-input.js",
|
||||
"pal/input/minigame/handheld-input.js",
|
||||
"pal/input/minigame/handle-input.js",
|
||||
"pal/input/minigame/hmd-input.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
{
|
||||
"$ref": "#/definitions/Config",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"Config": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"constants": {
|
||||
"$ref": "#/definitions/IConstantConfig",
|
||||
"description": "The constants config for engine and user."
|
||||
},
|
||||
"features": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/Feature"
|
||||
},
|
||||
"description": "Engine features. Keys are feature IDs.",
|
||||
"type": "object"
|
||||
},
|
||||
"includes": {
|
||||
"description": "Included files for quick-compiler.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"index": {
|
||||
"$ref": "#/definitions/IndexConfig",
|
||||
"description": "Describe how to generate the index module `'cc'`. Currently not used."
|
||||
},
|
||||
"moduleOverrides": {
|
||||
"items": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"isVirtualModule": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"overrides": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"test": {
|
||||
"$ref": "#/definitions/Test"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"test",
|
||||
"overrides",
|
||||
"isVirtualModule"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"optimizeDecorators": {
|
||||
"$ref": "#/definitions/IOptimizeDecorators",
|
||||
"description": "The decorators to be optimize when build engine."
|
||||
},
|
||||
"treeShake": {
|
||||
"$ref": "#/definitions/ITreeShakeConfig",
|
||||
"description": "The TreeShake config"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"features",
|
||||
"includes",
|
||||
"constants",
|
||||
"optimizeDecorators"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ConstantTypeName": {
|
||||
"enum": [
|
||||
"boolean",
|
||||
"number"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"Feature": {
|
||||
"additionalProperties": false,
|
||||
"description": "An engine feature.",
|
||||
"properties": {
|
||||
"dependentAssets": {
|
||||
"description": "List of uuid that the feature depends on.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"dependentModules": {
|
||||
"description": "List of module that the feature depends on.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"dependentScripts": {
|
||||
"description": "List of script uuid that the feature depends on.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"intrinsicFlags": {
|
||||
"additionalProperties": {},
|
||||
"description": "Flags to set when this feature is enabled.",
|
||||
"type": "object"
|
||||
},
|
||||
"isNativeOnly": {
|
||||
"default": false,
|
||||
"description": "Whether it is a native only feature, default is false.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"modules": {
|
||||
"description": "Modules to be included in this feature in their IDs. The ID of a module is its relative path(no extension) under /exports/.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"overrideConstants": {
|
||||
"additionalProperties": {
|
||||
"type": [
|
||||
"number",
|
||||
"boolean"
|
||||
]
|
||||
},
|
||||
"description": "Constants to override when this feature is enabled. The overridden constants should be defined in cc.config.json.",
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"modules"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"IConstantConfig": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/IConstantInfo"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"IConstantInfo": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"ccGlobal": {
|
||||
"default": false,
|
||||
"description": "Whether exported to global as a `CC_XXXX` constant. eg. WECHAT is exported to global.CC_WECHAT NOTE: this is a feature of compatibility with Cocos 2.x engine. Default is false.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"comment": {
|
||||
"description": "The comment of the constant. Which is used to generate the consts.d.ts file.",
|
||||
"type": "string"
|
||||
},
|
||||
"dynamic": {
|
||||
"default": false,
|
||||
"description": "Some constant can't specify the value in the Editor, Preview or Test environment, so we need to dynamically judge them in runtime. These values are specified in a helper called `helper-dynamic-constants.ts`. Default is false.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"internal": {
|
||||
"description": "Whether exported to developer. If true, it's only exported to engine.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/ConstantTypeName",
|
||||
"description": "The type of the constant for generating consts.d.ts file."
|
||||
},
|
||||
"value": {
|
||||
"description": "The default value of the constant. It can be a boolean, number or string. When it's a string type, the value is the result of eval().",
|
||||
"type": [
|
||||
"boolean",
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"comment",
|
||||
"type",
|
||||
"value",
|
||||
"internal"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"IOptimizeDecorators": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"editorDecorators": {
|
||||
"description": "The decorators which should be removed directly when they only work in Cocos Creator editor.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"fieldDecorators": {
|
||||
"description": "The decorators which should be optimized when they only decorate class fields.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"fieldDecorators",
|
||||
"editorDecorators"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ITreeShakeConfig": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"noSideEffectFiles": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"noSideEffectFiles"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"IndexConfig": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"modules": {
|
||||
"additionalProperties": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"deprecated": {
|
||||
"description": "If `true`, accesses the exports of this module from `'cc'` will be marked as deprecated.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"ns": {
|
||||
"description": "If specified, export contents of the module into a namespace specified by `ns` and then export that namespace into `'cc'`. If not specified, contents of the module will be directly exported into `'cc'`.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"Test": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Vertex/index capacity limits of the graphics geometry.
|
||||
|
||||
// Uint16 can address 65536 vertices (indices 0-65535), and a single fill()/stroke() batch is not
|
||||
// split, so the buffers have to cover this count.
|
||||
export const MAX_VERTEX_COUNT = 65536;
|
||||
// Fill and stroke both emit at most 3 indices per vertex, see GraphicsAssembler.
|
||||
export const INDICES_PER_VERTEX = 3;
|
||||
export const MAX_INDEX_COUNT = MAX_VERTEX_COUNT * INDICES_PER_VERTEX;
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { PointFlags } from './types';
|
||||
import { Impl } from './webgl/impl';
|
||||
|
||||
const PI = Math.PI;
|
||||
const min = Math.min;
|
||||
const max = Math.max;
|
||||
const cos = Math.cos;
|
||||
const sin = Math.sin;
|
||||
const abs = Math.abs;
|
||||
const sign = Math.sign;
|
||||
|
||||
const KAPPA90 = 0.5522847493;
|
||||
|
||||
export function arc (ctx: Impl, cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise: boolean): void {
|
||||
counterclockwise = counterclockwise || false;
|
||||
|
||||
let a = 0;
|
||||
let da = 0;
|
||||
let hda = 0;
|
||||
let kappa = 0;
|
||||
let dx = 0;
|
||||
let dy = 0;
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let tanx = 0;
|
||||
let tany = 0;
|
||||
let px = 0;
|
||||
let py = 0;
|
||||
let ptanx = 0;
|
||||
let ptany = 0;
|
||||
let i = 0;
|
||||
let ndivs = 0;
|
||||
|
||||
// Clamp angles
|
||||
da = endAngle - startAngle;
|
||||
if (counterclockwise) {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = PI * 2;
|
||||
} else {
|
||||
while (da < 0) { da += PI * 2; }
|
||||
}
|
||||
} else if (abs(da) >= PI * 2) {
|
||||
da = -PI * 2;
|
||||
} else {
|
||||
while (da > 0) { da -= PI * 2; }
|
||||
}
|
||||
|
||||
// Split arc into max 90 degree segments.
|
||||
ndivs = max(1, min(abs(da) / (PI * 0.5) + 0.5, 5)) | 0;
|
||||
hda = da / ndivs / 2.0;
|
||||
kappa = abs(4.0 / 3.0 * (1 - cos(hda)) / sin(hda));
|
||||
|
||||
if (!counterclockwise) { kappa = -kappa; }
|
||||
|
||||
for (i = 0; i <= ndivs; i++) {
|
||||
a = startAngle + da * (i / ndivs);
|
||||
dx = cos(a);
|
||||
dy = sin(a);
|
||||
x = cx + dx * r;
|
||||
y = cy + dy * r;
|
||||
tanx = -dy * r * kappa;
|
||||
tany = dx * r * kappa;
|
||||
|
||||
if (i === 0) {
|
||||
ctx.moveTo(x, y);
|
||||
} else {
|
||||
ctx.bezierCurveTo(px + ptanx, py + ptany, x - tanx, y - tany, x, y);
|
||||
}
|
||||
px = x;
|
||||
py = y;
|
||||
ptanx = tanx;
|
||||
ptany = tany;
|
||||
}
|
||||
}
|
||||
|
||||
export function ellipse (ctx: Impl, cx: number, cy: number, rx: number, ry: number): void {
|
||||
ctx.moveTo(cx - rx, cy);
|
||||
ctx.bezierCurveTo(cx - rx, cy + ry * KAPPA90, cx - rx * KAPPA90, cy + ry, cx, cy + ry);
|
||||
ctx.bezierCurveTo(cx + rx * KAPPA90, cy + ry, cx + rx, cy + ry * KAPPA90, cx + rx, cy);
|
||||
ctx.bezierCurveTo(cx + rx, cy - ry * KAPPA90, cx + rx * KAPPA90, cy - ry, cx, cy - ry);
|
||||
ctx.bezierCurveTo(cx - rx * KAPPA90, cy - ry, cx - rx, cy - ry * KAPPA90, cx - rx, cy);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
export function roundRect (ctx: Impl, x: number, y: number, w: number, h: number, r: number): void {
|
||||
if (r < 0.1) {
|
||||
ctx.rect(x, y, w, h);
|
||||
} else {
|
||||
const rx = min(r, abs(w) * 0.5) * sign(w);
|
||||
const ry = min(r, abs(h) * 0.5) * sign(h);
|
||||
|
||||
ctx.moveTo(x, y + ry);
|
||||
ctx.lineTo(x, y + h - ry);
|
||||
ctx.bezierCurveTo(x, y + h - ry * (1 - KAPPA90), x + rx * (1 - KAPPA90), y + h, x + rx, y + h);
|
||||
ctx.lineTo(x + w - rx, y + h);
|
||||
ctx.bezierCurveTo(x + w - rx * (1 - KAPPA90), y + h, x + w, y + h - ry * (1 - KAPPA90), x + w, y + h - ry);
|
||||
ctx.lineTo(x + w, y + ry);
|
||||
ctx.bezierCurveTo(x + w, y + ry * (1 - KAPPA90), x + w - rx * (1 - KAPPA90), y, x + w - rx, y);
|
||||
ctx.lineTo(x + rx, y);
|
||||
ctx.bezierCurveTo(x + rx * (1 - KAPPA90), y, x, y + ry * (1 - KAPPA90), x, y + ry);
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
export function tesselateBezier (
|
||||
ctx: Impl,
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
x3: number,
|
||||
y3: number,
|
||||
x4: number,
|
||||
y4: number,
|
||||
level: number,
|
||||
type: number,
|
||||
): void {
|
||||
let x12 = 0;
|
||||
let y12 = 0;
|
||||
let x23 = 0;
|
||||
let y23 = 0;
|
||||
let x34 = 0;
|
||||
let y34 = 0;
|
||||
let x123 = 0;
|
||||
let y123 = 0;
|
||||
let x234 = 0;
|
||||
let y234 = 0;
|
||||
let x1234 = 0;
|
||||
let y1234 = 0;
|
||||
let dx = 0;
|
||||
let dy = 0;
|
||||
let d2 = 0;
|
||||
let d3 = 0;
|
||||
|
||||
if (level > 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
x12 = (x1 + x2) * 0.5;
|
||||
y12 = (y1 + y2) * 0.5;
|
||||
x23 = (x2 + x3) * 0.5;
|
||||
y23 = (y2 + y3) * 0.5;
|
||||
x34 = (x3 + x4) * 0.5;
|
||||
y34 = (y3 + y4) * 0.5;
|
||||
x123 = (x12 + x23) * 0.5;
|
||||
y123 = (y12 + y23) * 0.5;
|
||||
|
||||
dx = x4 - x1;
|
||||
dy = y4 - y1;
|
||||
d2 = abs((x2 - x4) * dy - (y2 - y4) * dx);
|
||||
d3 = abs((x3 - x4) * dy - (y3 - y4) * dx);
|
||||
|
||||
if ((d2 + d3) * (d2 + d3) < ctx.tessTol * (dx * dx + dy * dy)) {
|
||||
ctx.addPoint(x4, y4, type === 0 ? type | PointFlags.PT_BEVEL : type);
|
||||
return;
|
||||
}
|
||||
|
||||
x234 = (x23 + x34) * 0.5;
|
||||
y234 = (y23 + y34) * 0.5;
|
||||
x1234 = (x123 + x234) * 0.5;
|
||||
y1234 = (y123 + y234) * 0.5;
|
||||
|
||||
tesselateBezier(ctx, x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1, 0);
|
||||
tesselateBezier(ctx, x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1, type);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from './webgl';
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ccenum } from '../../../core';
|
||||
|
||||
/**
|
||||
* @en Enum for LineCap.
|
||||
* @zh 线段末端属性
|
||||
* @enum Graphics.LineCap
|
||||
*/
|
||||
export enum LineCap {
|
||||
/**
|
||||
* @en The ends of lines are squared off at the endpoints.
|
||||
* @zh 线段末端以方形结束。
|
||||
*/
|
||||
BUTT = 0,
|
||||
|
||||
/**
|
||||
* @en The ends of lines are rounded.
|
||||
* @zh 线段末端以圆形结束。
|
||||
*/
|
||||
ROUND = 1,
|
||||
|
||||
/**
|
||||
* @en The ends of lines are squared off by adding a box with an equal width and half the height of the line's thickness.
|
||||
* @zh 线段末端以方形结束,但是增加了一个宽度和线段相同,高度是线段厚度一半的矩形区域。
|
||||
*/
|
||||
SQUARE = 2,
|
||||
}
|
||||
|
||||
ccenum(LineCap);
|
||||
|
||||
/**
|
||||
* @en Enum for LineJoin.
|
||||
* @zh 线段拐角属性
|
||||
* @enum Graphics.LineJoin
|
||||
*/
|
||||
export enum LineJoin {
|
||||
/**
|
||||
* @en Fills an additional triangular area between the common endpoint of connected segments, and the separate outside rectangular corners of each segment.
|
||||
* @zh 在相连部分的末端填充一个额外的以三角形为底的区域, 每个部分都有各自独立的矩形拐角。
|
||||
*/
|
||||
BEVEL = 0,
|
||||
|
||||
/**
|
||||
* @en Rounds off the corners of a shape by filling an additional sector of disc centered at the common endpoint of connected segments.
|
||||
* The radius for these rounded corners is equal to the line width.
|
||||
* @zh 通过填充一个额外的,圆心在相连部分末端的扇形,绘制拐角的形状。 圆角的半径是线段的宽度。
|
||||
*/
|
||||
ROUND = 1,
|
||||
|
||||
/**
|
||||
* @en Connected segments are joined by extending their outside edges to connect at a single point,
|
||||
* with the effect of filling an additional lozenge-shaped area.
|
||||
* @zh 通过延伸相连部分的外边缘,使其相交于一点,形成一个额外的菱形区域。
|
||||
*/
|
||||
MITER = 2,
|
||||
}
|
||||
|
||||
ccenum(LineJoin);
|
||||
|
||||
// PointFlags
|
||||
export enum PointFlags {
|
||||
PT_CORNER = 0x01,
|
||||
PT_LEFT = 0x02,
|
||||
PT_BEVEL = 0x04,
|
||||
PT_INNERBEVEL = 0x08,
|
||||
}
|
||||
|
||||
ccenum(PointFlags);
|
||||
@@ -1,734 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/** @mangle */
|
||||
class Aim {
|
||||
// vertex index in coordinates array
|
||||
public declare i: number;
|
||||
|
||||
// vertex coordinates
|
||||
public declare x: number;
|
||||
public declare y: number;
|
||||
|
||||
// previous and next vertex nodes in a polygon ring
|
||||
public prev: Aim | null = null;
|
||||
public next: Aim | null = null;
|
||||
|
||||
// z-order curve value
|
||||
public z: number = null as any;
|
||||
|
||||
// previous and next nodes in z-order
|
||||
public prevZ: Aim | null = null;
|
||||
public nextZ: Aim | null = null;
|
||||
|
||||
// indicates whether this is a steiner point
|
||||
public steiner = false;
|
||||
|
||||
constructor (i: number, x: number, y: number) {
|
||||
this.i = i;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
// create a circular doubly linked list from polygon points in the specified winding order
|
||||
function linkedList (datas: number[], start: number, end: number, dim: number, clockwise: boolean): Aim | null {
|
||||
let i = 0;
|
||||
let last: Aim | null = null;
|
||||
|
||||
if (clockwise === (signedArea(datas, start, end, dim) > 0)) {
|
||||
for (i = start; i < end; i += dim) {
|
||||
last = insertNode(i, datas[i], datas[i + 1], last);
|
||||
}
|
||||
} else {
|
||||
for (i = end - dim; i >= start; i -= dim) {
|
||||
last = insertNode(i, datas[i], datas[i + 1], last);
|
||||
}
|
||||
}
|
||||
|
||||
if (last && equals(last, last.next!)) {
|
||||
removeNode(last);
|
||||
last = last.next;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
// eliminate colinear or duplicate points
|
||||
function filterPoints (start: Aim | null, end: Aim | null = null): Aim | null {
|
||||
if (!start) {
|
||||
return start;
|
||||
}
|
||||
|
||||
if (!end) {
|
||||
end = start;
|
||||
}
|
||||
|
||||
let p = start;
|
||||
let again = false;
|
||||
do {
|
||||
again = false;
|
||||
|
||||
if (!p.steiner && (equals(p, p.next!) || area(p.prev!, p, p.next!) === 0)) {
|
||||
removeNode(p);
|
||||
p = end = p.prev!;
|
||||
if (p === p.next) {
|
||||
return null;
|
||||
}
|
||||
again = true;
|
||||
} else {
|
||||
p = p.next!;
|
||||
}
|
||||
} while (again || p !== end);
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
// main ear slicing loop which triangulates a polygon (given as a linked list)
|
||||
function earcutLinked (ear: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number, pass = 0): void {
|
||||
if (!ear) {
|
||||
return;
|
||||
}
|
||||
|
||||
// interlink polygon nodes in z-order
|
||||
if (!pass && size) {
|
||||
indexCurve(ear, minX, minY, size);
|
||||
}
|
||||
|
||||
let stop: Aim | null = ear;
|
||||
let prev: Aim | null = null;
|
||||
let next: Aim | null = null;
|
||||
|
||||
// iterate through ears, slicing them one by one
|
||||
while (ear!.prev !== ear!.next) {
|
||||
prev = ear!.prev!;
|
||||
next = ear!.next!;
|
||||
|
||||
if (size ? isEarHashed(ear!, minX, minY, size) : isEar(ear!)) {
|
||||
// cut off the triangle
|
||||
triangles.push(prev.i / dim);
|
||||
triangles.push(ear!.i / dim);
|
||||
triangles.push(next.i / dim);
|
||||
|
||||
removeNode(ear!);
|
||||
|
||||
// skipping the next vertices leads to less sliver triangles
|
||||
ear = next.next;
|
||||
stop = next.next;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ear = next;
|
||||
|
||||
// if we looped through the whole remaining polygon and can't find any more ears
|
||||
if (ear === stop) {
|
||||
// try filtering points and slicing again
|
||||
if (!pass) {
|
||||
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
|
||||
|
||||
// if this didn't work, try curing all small self-intersections locally
|
||||
} else if (pass === 1) {
|
||||
ear = cureLocalIntersections(ear, triangles, dim);
|
||||
earcutLinked(ear, triangles, dim, minX, minY, size, 2);
|
||||
|
||||
// as a last resort, try splitting the remaining polygon into two
|
||||
} else if (pass === 2) {
|
||||
splitEarcut(ear, triangles, dim, minX, minY, size);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check whether a polygon node forms a valid ear with adjacent nodes
|
||||
function isEar (ear: Aim): boolean {
|
||||
const a = ear.prev!;
|
||||
const b = ear;
|
||||
const c = ear.next!;
|
||||
|
||||
if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
|
||||
|
||||
// now make sure we don't have other points inside the potential ear
|
||||
let p = ear.next!.next!;
|
||||
|
||||
while (p !== ear.prev) {
|
||||
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y)
|
||||
&& area(p.prev!, p, p.next!) >= 0) { return false; }
|
||||
p = p.next!;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isEarHashed (ear: Aim, minX: number, minY: number, size: number): boolean {
|
||||
const a = ear.prev!;
|
||||
const b = ear;
|
||||
const c = ear.next!;
|
||||
|
||||
if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
|
||||
|
||||
// triangle bbox; min & max are calculated like this for speed
|
||||
const minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x);
|
||||
const minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y);
|
||||
const maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x);
|
||||
const maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
|
||||
|
||||
// z-order range for the current triangle bbox;
|
||||
const minZ = zOrder(minTX, minTY, minX, minY, size);
|
||||
const maxZ = zOrder(maxTX, maxTY, minX, minY, size);
|
||||
|
||||
// first look for points inside the triangle in increasing z-order
|
||||
let p = ear.nextZ;
|
||||
|
||||
while (p && p.z <= maxZ) {
|
||||
if (p !== ear.prev && p !== ear.next
|
||||
&& pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y)
|
||||
&& area(p.prev!, p, p.next!) >= 0) { return false; }
|
||||
p = p.nextZ;
|
||||
}
|
||||
|
||||
// then look for points in decreasing z-order
|
||||
p = ear.prevZ;
|
||||
|
||||
while (p && p.z >= minZ) {
|
||||
if (p !== ear.prev && p !== ear.next
|
||||
&& pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y)
|
||||
&& area(p.prev!, p, p.next!) >= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
p = p.prevZ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// go through all polygon nodes and cure small local self-intersections
|
||||
function cureLocalIntersections (start: Aim, triangles: number[], dim: number): Aim {
|
||||
let p = start;
|
||||
do {
|
||||
const a = p.prev!;
|
||||
const b = p.next!.next!;
|
||||
|
||||
if (!equals(a, b) && intersects(a, p, p.next!, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
||||
triangles.push(a.i / dim);
|
||||
triangles.push(p.i / dim);
|
||||
triangles.push(b.i / dim);
|
||||
|
||||
// remove two nodes involved
|
||||
removeNode(p);
|
||||
removeNode(p.next!);
|
||||
|
||||
p = start = b;
|
||||
}
|
||||
p = p.next!;
|
||||
} while (p !== start);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
// try splitting polygon into two and triangulate them independently
|
||||
function splitEarcut (start: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number): void {
|
||||
// look for a valid diagonal that divides the polygon into two
|
||||
let a = start!;
|
||||
do {
|
||||
let b = a.next!.next;
|
||||
while (b !== a.prev) {
|
||||
if (a.i !== b!.i && isValidDiagonal(a, b!)) {
|
||||
// split the polygon in two by the diagonal
|
||||
let c = splitPolygon(a, b!);
|
||||
|
||||
// filter colinear points around the cuts
|
||||
a = filterPoints(a, a.next)!;
|
||||
c = filterPoints(c, c.next)!;
|
||||
|
||||
// run earcut on each half
|
||||
earcutLinked(a, triangles, dim, minX, minY, size);
|
||||
earcutLinked(c, triangles, dim, minX, minY, size);
|
||||
return;
|
||||
}
|
||||
b = b!.next;
|
||||
}
|
||||
a = a.next!;
|
||||
} while (a !== start);
|
||||
}
|
||||
|
||||
// link every hole into the outer loop, producing a single-ring polygon without holes
|
||||
function eliminateHoles (datas: number[], holeIndices: number[], outerNode: Aim | null, dim: number): Aim | null {
|
||||
const queue: Aim[] = [];
|
||||
let i = 0;
|
||||
let len = 0;
|
||||
let start = 0;
|
||||
let end = 0;
|
||||
let list: Aim | null = null;
|
||||
|
||||
for (i = 0, len = holeIndices.length; i < len; i++) {
|
||||
start = holeIndices[i] * dim;
|
||||
end = i < len - 1 ? holeIndices[i + 1] * dim : datas.length;
|
||||
list = linkedList(datas, start, end, dim, false);
|
||||
if (!list) {
|
||||
continue;
|
||||
}
|
||||
if (list === list.next) {
|
||||
list.steiner = true;
|
||||
}
|
||||
|
||||
queue.push(getLeftmost(list));
|
||||
}
|
||||
|
||||
queue.sort(compareX);
|
||||
|
||||
if (!outerNode) {
|
||||
return outerNode;
|
||||
}
|
||||
|
||||
// process holes from left to right
|
||||
for (i = 0; i < queue.length; i++) {
|
||||
eliminateHole(queue[i], outerNode);
|
||||
outerNode = filterPoints(outerNode, outerNode!.next);
|
||||
}
|
||||
|
||||
return outerNode;
|
||||
}
|
||||
|
||||
function compareX (a, b): number {
|
||||
return a.x - b.x;
|
||||
}
|
||||
|
||||
// find a bridge between vertices that connects hole with an outer ring and link it
|
||||
function eliminateHole (hole: Aim, outerNode: Aim | null): void {
|
||||
outerNode = findHoleBridge(hole, outerNode!);
|
||||
if (outerNode) {
|
||||
const b = splitPolygon(outerNode, hole);
|
||||
filterPoints(b, b.next);
|
||||
}
|
||||
}
|
||||
|
||||
// David Eberly's algorithm for finding a bridge between hole and outer polygon
|
||||
function findHoleBridge (hole: Aim, outerNode: Aim): Aim | null {
|
||||
let p = outerNode;
|
||||
const hx = hole.x;
|
||||
const hy = hole.y;
|
||||
let qx = -Infinity;
|
||||
let m: Aim | null = null;
|
||||
|
||||
// find a segment intersected by a ray from the hole's leftmost point to the left;
|
||||
// segment's endpoint with lesser x will be potential connection point
|
||||
do {
|
||||
if (hy <= p.y && hy >= p.next!.y) {
|
||||
const x = p.x + (hy - p.y) * (p.next!.x - p.x) / (p.next!.y - p.y);
|
||||
if (x <= hx && x > qx) {
|
||||
qx = x;
|
||||
if (x === hx) {
|
||||
if (hy === p.y) { return p; }
|
||||
if (hy === p.next!.y) { return p.next; }
|
||||
}
|
||||
m = p.x < p.next!.x ? p : p.next!;
|
||||
}
|
||||
}
|
||||
p = p.next!;
|
||||
} while (p !== outerNode);
|
||||
|
||||
if (!m) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hx === qx) {
|
||||
return m.prev;
|
||||
} // hole touches outer segment; pick lower endpoint
|
||||
|
||||
// look for points inside the triangle of hole point, segment intersection and endpoint;
|
||||
// if there are no points found, we have a valid connection;
|
||||
// otherwise choose the point of the minimum angle with the ray as connection point
|
||||
|
||||
const stop = m;
|
||||
const mx = m.x;
|
||||
const my = m.y;
|
||||
let tanMin = Infinity;
|
||||
let tan;
|
||||
|
||||
p = m.next!;
|
||||
|
||||
while (p !== stop) {
|
||||
if (hx >= p.x && p.x >= mx
|
||||
&& pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
||||
tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
||||
|
||||
if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
|
||||
m = p;
|
||||
tanMin = tan;
|
||||
}
|
||||
}
|
||||
|
||||
p = p.next!;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
// interlink polygon nodes in z-order
|
||||
function indexCurve (start: Aim, minX: number, minY: number, size: number): void {
|
||||
let p = start;
|
||||
do {
|
||||
if (p.z === null) {
|
||||
p.z = zOrder(p.x, p.y, minX, minY, size);
|
||||
}
|
||||
|
||||
p.prevZ = p.prev;
|
||||
p.nextZ = p.next;
|
||||
p = p.next!;
|
||||
} while (p !== start);
|
||||
|
||||
p.prevZ!.nextZ = null;
|
||||
p.prevZ = null;
|
||||
|
||||
sortLinked(p);
|
||||
}
|
||||
|
||||
// Simon Tatham's linked list merge sort algorithm
|
||||
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
||||
function sortLinked (list: Aim | null): Aim | null {
|
||||
let i = 0;
|
||||
let p: Aim | null = null;
|
||||
let q: Aim | null = null;
|
||||
let e: Aim | null = null;
|
||||
let tail: Aim | null = null;
|
||||
let numMerges = 0;
|
||||
let pSize = 0;
|
||||
let qSize = 0;
|
||||
let inSize = 1;
|
||||
|
||||
do {
|
||||
p = list;
|
||||
list = null;
|
||||
tail = null;
|
||||
numMerges = 0;
|
||||
|
||||
while (p) {
|
||||
numMerges++;
|
||||
q = p;
|
||||
pSize = 0;
|
||||
for (i = 0; i < inSize; i++) {
|
||||
pSize++;
|
||||
q = q.nextZ;
|
||||
if (!q) { break; }
|
||||
}
|
||||
|
||||
qSize = inSize;
|
||||
|
||||
while (pSize > 0 || (qSize > 0 && q)) {
|
||||
if (pSize === 0) {
|
||||
e = q;
|
||||
q = q!.nextZ;
|
||||
qSize--;
|
||||
} else if (qSize === 0 || !q) {
|
||||
e = p;
|
||||
p = p!.nextZ;
|
||||
pSize--;
|
||||
} else if (p!.z <= q.z) {
|
||||
e = p;
|
||||
p = p!.nextZ;
|
||||
pSize--;
|
||||
} else {
|
||||
e = q;
|
||||
q = q.nextZ;
|
||||
qSize--;
|
||||
}
|
||||
|
||||
if (tail) { tail.nextZ = e; } else { list = e; }
|
||||
|
||||
e!.prevZ = tail;
|
||||
tail = e;
|
||||
}
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
tail!.nextZ = null;
|
||||
inSize *= 2;
|
||||
} while (numMerges > 1);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// z-order of a point given coords and size of the data bounding box
|
||||
function zOrder (x: number, y: number, minX: number, minY: number, size: number): number {
|
||||
// coords are transformed into non-negative 15-bit integer range
|
||||
x = 32767 * (x - minX) / size;
|
||||
y = 32767 * (y - minY) / size;
|
||||
|
||||
x = (x | (x << 8)) & 0x00FF00FF;
|
||||
x = (x | (x << 4)) & 0x0F0F0F0F;
|
||||
x = (x | (x << 2)) & 0x33333333;
|
||||
x = (x | (x << 1)) & 0x55555555;
|
||||
|
||||
y = (y | (y << 8)) & 0x00FF00FF;
|
||||
y = (y | (y << 4)) & 0x0F0F0F0F;
|
||||
y = (y | (y << 2)) & 0x33333333;
|
||||
y = (y | (y << 1)) & 0x55555555;
|
||||
|
||||
return x | (y << 1);
|
||||
}
|
||||
|
||||
// find the leftmost node of a polygon ring
|
||||
function getLeftmost (start: Aim): Aim {
|
||||
let p = start;
|
||||
let leftmost = start;
|
||||
do {
|
||||
if (p.x < leftmost.x) {
|
||||
leftmost = p;
|
||||
}
|
||||
|
||||
p = p.next!;
|
||||
} while (p !== start);
|
||||
|
||||
return leftmost;
|
||||
}
|
||||
|
||||
// check if a point lies within a convex triangle
|
||||
function pointInTriangle (ax: number, ay: number, bx: number, by: number, cx: number, cy: number, px: number, py: number): boolean {
|
||||
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0
|
||||
&& (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0
|
||||
&& (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
||||
}
|
||||
|
||||
// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
||||
function isValidDiagonal (a: Aim, b: Aim): boolean {
|
||||
return a.next!.i !== b.i && a.prev!.i !== b.i && !intersectsPolygon(a, b)
|
||||
&& locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
|
||||
}
|
||||
|
||||
// signed area of a triangle
|
||||
function area (p: Aim, q: Aim, r: Aim): number {
|
||||
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
||||
}
|
||||
|
||||
// check if two points are equal
|
||||
function equals (p1: Aim, p2: Aim): boolean {
|
||||
return p1.x === p2.x && p1.y === p2.y;
|
||||
}
|
||||
|
||||
// check if two segments intersect
|
||||
function intersects (p1: Aim, q1: Aim, p2: Aim, q2: Aim): boolean {
|
||||
if ((equals(p1, q1) && equals(p2, q2))
|
||||
|| (equals(p1, q2) && equals(p2, q1))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0
|
||||
&& area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
|
||||
}
|
||||
|
||||
// check if a polygon diagonal intersects any polygon segments
|
||||
function intersectsPolygon (a: Aim, b: Aim): boolean {
|
||||
let p = a;
|
||||
do {
|
||||
if (p.i !== a.i && p.next!.i !== a.i && p.i !== b.i && p.next!.i !== b.i
|
||||
&& intersects(p, p.next!, a, b)) { return true; }
|
||||
p = p.next!;
|
||||
} while (p !== a);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if a polygon diagonal is locally inside the polygon
|
||||
function locallyInside (a: Aim, b: Aim): boolean {
|
||||
return area(a.prev!, a, a.next!) < 0
|
||||
? area(a, b, a.next!) >= 0 && area(a, a.prev!, b) >= 0
|
||||
: area(a, b, a.prev!) < 0 || area(a, a.next!, b) < 0;
|
||||
}
|
||||
|
||||
// check if the middle point of a polygon diagonal is inside the polygon
|
||||
function middleInside (a: Aim, b: Aim): boolean {
|
||||
let p = a;
|
||||
let inside = false;
|
||||
const px = (a.x + b.x) / 2;
|
||||
const py = (a.y + b.y) / 2;
|
||||
do {
|
||||
if (((p.y > py) !== (p.next!.y > py)) && (px < (p.next!.x - p.x) * (py - p.y) / (p.next!.y - p.y) + p.x)) {
|
||||
inside = !inside;
|
||||
}
|
||||
p = p.next!;
|
||||
} while (p !== a);
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
|
||||
// if one belongs to the outer ring and another to a hole, it merges it into a single ring
|
||||
function splitPolygon (a: Aim, b: Aim): Aim {
|
||||
const a2 = new Aim(a.i, a.x, a.y);
|
||||
const b2 = new Aim(b.i, b.x, b.y);
|
||||
const an = a.next!;
|
||||
const bp = b.prev!;
|
||||
|
||||
a.next = b;
|
||||
b.prev = a;
|
||||
|
||||
a2.next = an;
|
||||
an.prev = a2;
|
||||
|
||||
b2.next = a2;
|
||||
a2.prev = b2;
|
||||
|
||||
bp.next = b2;
|
||||
b2.prev = bp;
|
||||
|
||||
return b2;
|
||||
}
|
||||
|
||||
// create a node and optionally link it with previous one (in a circular doubly linked list)
|
||||
function insertNode (i: number, x: number, y: number, last: Aim | null): Aim {
|
||||
const p = new Aim(i, x, y);
|
||||
|
||||
if (!last) {
|
||||
p.prev = p;
|
||||
p.next = p;
|
||||
} else {
|
||||
p.next = last.next;
|
||||
p.prev = last;
|
||||
last.next!.prev = p;
|
||||
last.next = p;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
function removeNode (p: Aim): void {
|
||||
p.next!.prev = p.prev;
|
||||
p.prev!.next = p.next;
|
||||
|
||||
if (p.prevZ) {
|
||||
p.prevZ.nextZ = p.nextZ;
|
||||
}
|
||||
|
||||
if (p.nextZ) {
|
||||
p.nextZ.prevZ = p.prevZ;
|
||||
}
|
||||
}
|
||||
|
||||
function signedArea (datas: number[], start: number, end: number, dim: number): number {
|
||||
let sum = 0;
|
||||
for (let i = start, j = end - dim; i < end; i += dim) {
|
||||
sum += (datas[j] - datas[i]) * (datas[i + 1] + datas[j + 1]);
|
||||
j = i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
export function earcut (datas: number[], holeIndices: number[] | null, dim: number): number[] {
|
||||
dim = dim || 3;
|
||||
|
||||
const hasHoles = holeIndices ? holeIndices.length : 0;
|
||||
const outerLen = hasHoles ? holeIndices![0] * dim : datas.length;
|
||||
let outerNode = linkedList(datas, 0, outerLen, dim, true);
|
||||
const triangles: number[] = [];
|
||||
|
||||
if (!outerNode) {
|
||||
return triangles;
|
||||
}
|
||||
|
||||
let minX = 0;
|
||||
let minY = 0;
|
||||
let maxX = 0;
|
||||
let maxY = 0;
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let size = 0;
|
||||
|
||||
if (hasHoles) {
|
||||
outerNode = eliminateHoles(datas, holeIndices!, outerNode, dim);
|
||||
}
|
||||
|
||||
// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
|
||||
if (datas.length > 80 * dim) {
|
||||
minX = maxX = datas[0];
|
||||
minY = maxY = datas[1];
|
||||
|
||||
for (let i = dim; i < outerLen; i += dim) {
|
||||
x = datas[i];
|
||||
y = datas[i + 1];
|
||||
if (x < minX) { minX = x; }
|
||||
if (y < minY) { minY = y; }
|
||||
if (x > maxX) { maxX = x; }
|
||||
if (y > maxY) { maxY = y; }
|
||||
}
|
||||
|
||||
// minX, minY and size are later used to transform coords into integers for z-order calculation
|
||||
size = Math.max(maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
earcutLinked(outerNode, triangles, dim, minX, minY, size);
|
||||
|
||||
return triangles;
|
||||
}
|
||||
|
||||
// // return a percentage difference between the polygon area and its triangulation area;
|
||||
// // used to verify correctness of triangulation
|
||||
// earcut.deviation = function (data, holeIndices, dim, triangles) {
|
||||
// const hasHoles = holeIndices && holeIndices.length;
|
||||
// const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
||||
|
||||
// let polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
|
||||
// if (hasHoles) {
|
||||
// for (let i = 0, len = holeIndices.length; i < len; i++) {
|
||||
// const start = holeIndices[i] * dim;
|
||||
// const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
||||
// polygonArea -= Math.abs(signedArea(data, start, end, dim));
|
||||
// }
|
||||
// }
|
||||
|
||||
// let trianglesArea = 0;
|
||||
// for (i = 0; i < triangles.length; i += 3) {
|
||||
// const a = triangles[i] * dim;
|
||||
// const b = triangles[i + 1] * dim;
|
||||
// const c = triangles[i + 2] * dim;
|
||||
// trianglesArea += Math.abs(
|
||||
// (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
|
||||
// (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
|
||||
// }
|
||||
|
||||
// return polygonArea === 0 && trianglesArea === 0 ? 0 :
|
||||
// Math.abs((trianglesArea - polygonArea) / polygonArea);
|
||||
// };
|
||||
|
||||
// // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
|
||||
// earcut.flatten = function (data) {
|
||||
// let dim = data[0][0].length,
|
||||
// result = {vertices: [], holes: [], dimensions: dim},
|
||||
// holeIndex = 0;
|
||||
|
||||
// for (let i = 0; i < data.length; i++) {
|
||||
// for (let j = 0; j < data[i].length; j++) {
|
||||
// for (let d = 0; d < dim; d++) { result.vertices.push(data[i][j][d]); }
|
||||
// }
|
||||
// if (i > 0) {
|
||||
// holeIndex += data[i - 1].length;
|
||||
// result.holes.push(holeIndex);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// };
|
||||
@@ -1,677 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
import { JSB } from 'internal:constants';
|
||||
import { Color, Vec3 } from '../../../../core';
|
||||
import { IAssembler } from '../../../renderer/base';
|
||||
import { MeshRenderData } from '../../../renderer/render-data';
|
||||
import { IBatcher } from '../../../renderer/i-batcher';
|
||||
import { Graphics } from '../../../components/graphics';
|
||||
import { LineCap, LineJoin, PointFlags } from '../types';
|
||||
import { MAX_VERTEX_COUNT, INDICES_PER_VERTEX } from '../constants';
|
||||
import { earcut as Earcut } from './earcut';
|
||||
import { Impl, Point } from './impl';
|
||||
|
||||
const PI = Math.PI;
|
||||
const min = Math.min;
|
||||
const max = Math.max;
|
||||
const ceil = Math.ceil;
|
||||
const acos = Math.acos;
|
||||
const cos = Math.cos;
|
||||
const sin = Math.sin;
|
||||
const atan2 = Math.atan2;
|
||||
|
||||
const attrBytes = 8;
|
||||
|
||||
let _renderData: MeshRenderData | null = null;
|
||||
let _impl: Impl | null = null;
|
||||
const _curColor = new Color();
|
||||
|
||||
const vec3_temps: Vec3[] = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
vec3_temps.push(new Vec3());
|
||||
}
|
||||
|
||||
function curveDivs (r: number, arc: number, tol: number): number {
|
||||
const da = acos(r / (r + tol)) * 2.0;
|
||||
return max(2, ceil(arc / da));
|
||||
}
|
||||
|
||||
function clamp (v: number, minNum: number, maxNum: number): number {
|
||||
if (v < minNum) {
|
||||
return minNum;
|
||||
} else if (v > maxNum) {
|
||||
return maxNum;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* graphics 组装器
|
||||
* 可通过 `UI.graphicsAssembler` 获取该组装器。
|
||||
*/
|
||||
export class GraphicsAssembler implements IAssembler {
|
||||
updateRenderData (graphics: Graphics): void {
|
||||
if (JSB) {
|
||||
if (graphics.renderData) {
|
||||
graphics.renderData.material = graphics.getMaterialInstance(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getRenderData (graphics: Graphics, vertexCount: number): MeshRenderData | null {
|
||||
if (!_impl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const renderDataList = _impl.getRenderDataList();
|
||||
let renderData = renderDataList[_impl.dataOffset];
|
||||
if (!renderData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let meshBuffer = renderData;
|
||||
|
||||
const maxVertexCount = meshBuffer ? meshBuffer.vertexStart + vertexCount : 0;
|
||||
if (maxVertexCount > MAX_VERTEX_COUNT) {
|
||||
++_impl.dataOffset;
|
||||
|
||||
if (_impl.dataOffset < renderDataList.length) {
|
||||
renderData = renderDataList[_impl.dataOffset];
|
||||
} else {
|
||||
renderData = _impl.requestRenderData();
|
||||
renderDataList[_impl.dataOffset] = renderData;
|
||||
}
|
||||
|
||||
meshBuffer = renderData;
|
||||
}
|
||||
|
||||
if (meshBuffer && meshBuffer.vertexCount < maxVertexCount) {
|
||||
meshBuffer.request(vertexCount, vertexCount * INDICES_PER_VERTEX);
|
||||
}
|
||||
|
||||
return renderData;
|
||||
}
|
||||
|
||||
stroke (graphics: Graphics): void {
|
||||
Color.copy(_curColor, graphics.strokeColor);
|
||||
// graphics.node.getWorldMatrix(_currMatrix);
|
||||
if (!graphics.impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._flattenPaths(graphics.impl);
|
||||
this._expandStroke(graphics);
|
||||
|
||||
graphics.impl.updatePathOffset = true;
|
||||
|
||||
this.end(graphics);
|
||||
}
|
||||
|
||||
fill (graphics: Graphics): void {
|
||||
Color.copy(_curColor, graphics.fillColor);
|
||||
// graphics.node.getWorldMatrix(_currMatrix);
|
||||
|
||||
this._expandFill(graphics);
|
||||
if (graphics.impl) {
|
||||
graphics.impl.updatePathOffset = true;
|
||||
}
|
||||
|
||||
this.end(graphics);
|
||||
}
|
||||
|
||||
end (graphics: Graphics): void {
|
||||
graphics._markForUpdateRenderData();
|
||||
}
|
||||
|
||||
private _expandStroke (graphics: Graphics): void {
|
||||
const w = graphics.lineWidth * 0.5;
|
||||
const lineCap = graphics.lineCap;
|
||||
const lineJoin = graphics.lineJoin;
|
||||
const miterLimit = graphics.miterLimit;
|
||||
|
||||
_impl = graphics.impl;
|
||||
|
||||
if (!_impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nCap = curveDivs(w, PI, _impl.tessTol);
|
||||
|
||||
this._calculateJoins(_impl, w, lineJoin, miterLimit);
|
||||
|
||||
const paths = _impl.paths;
|
||||
|
||||
// Calculate max vertex usage.
|
||||
let vertexCount = 0;
|
||||
for (let i = _impl.pathOffset, l = _impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
const pointsLength = path.points.length;
|
||||
|
||||
if (lineJoin === LineJoin.ROUND) {
|
||||
vertexCount += (pointsLength + path.bevel * (nCap + 2) + 1) * 2;
|
||||
} else {
|
||||
vertexCount += (pointsLength + path.bevel * 5 + 1) * 2;
|
||||
} // plus one for loop
|
||||
|
||||
if (!path.closed) {
|
||||
// space for caps
|
||||
if (lineCap === LineCap.ROUND) {
|
||||
vertexCount += (nCap * 2 + 2) * 2;
|
||||
} else {
|
||||
vertexCount += (3 + 3) * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const meshBuffer: MeshRenderData | null = _renderData = this.getRenderData(graphics, vertexCount);
|
||||
if (!meshBuffer) {
|
||||
return;
|
||||
}
|
||||
const vData = meshBuffer.vData;
|
||||
const iData = meshBuffer.iData;
|
||||
|
||||
for (let i = _impl.pathOffset, l = _impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
const pts = path.points;
|
||||
const pointsLength = pts.length;
|
||||
const offset = meshBuffer.vertexStart;
|
||||
|
||||
let p0: Point;
|
||||
let p1: Point;
|
||||
let start = 0;
|
||||
let end = 0;
|
||||
const loop = path.closed;
|
||||
if (loop) {
|
||||
// Looping
|
||||
p0 = pts[pointsLength - 1];
|
||||
p1 = pts[0];
|
||||
start = 0;
|
||||
end = pointsLength;
|
||||
} else {
|
||||
// Add cap
|
||||
p0 = pts[0];
|
||||
p1 = pts[1];
|
||||
start = 1;
|
||||
end = pointsLength - 1;
|
||||
}
|
||||
|
||||
p1 = p1 || p0;
|
||||
|
||||
if (!loop) {
|
||||
// Add cap
|
||||
const dPos = new Point(p1.x, p1.y);
|
||||
dPos.subtract(p0);
|
||||
dPos.normalize();
|
||||
|
||||
const dx = dPos.x;
|
||||
const dy = dPos.y;
|
||||
|
||||
if (lineCap === LineCap.BUTT) {
|
||||
this._buttCapStart(p0, dx, dy, w, 0);
|
||||
} else if (lineCap === LineCap.SQUARE) {
|
||||
this._buttCapStart(p0, dx, dy, w, w);
|
||||
} else if (lineCap === LineCap.ROUND) {
|
||||
this._roundCapStart(p0, dx, dy, w, nCap);
|
||||
}
|
||||
}
|
||||
|
||||
for (let j = start; j < end; ++j) {
|
||||
if (lineJoin === LineJoin.ROUND) {
|
||||
this._roundJoin(p0, p1, w, w, nCap);
|
||||
} else if ((p1.flags & (PointFlags.PT_BEVEL | PointFlags.PT_INNERBEVEL)) !== 0) {
|
||||
this._bevelJoin(p0, p1, w, w);
|
||||
} else {
|
||||
this._vSet(p1.x + p1.dmx * w, p1.y + p1.dmy * w, 1);
|
||||
this._vSet(p1.x - p1.dmx * w, p1.y - p1.dmy * w, -1);
|
||||
}
|
||||
|
||||
p0 = p1;
|
||||
p1 = pts[j + 1];
|
||||
}
|
||||
|
||||
if (loop) {
|
||||
// Loop it
|
||||
const vDataOffset = offset * attrBytes;
|
||||
this._vSet(vData[vDataOffset], vData[vDataOffset + 1], 1);
|
||||
this._vSet(vData[vDataOffset + attrBytes], vData[vDataOffset + attrBytes + 1], -1);
|
||||
} else {
|
||||
// Add cap
|
||||
const dPos = new Point(p1.x, p1.y);
|
||||
dPos.subtract(p0);
|
||||
dPos.normalize();
|
||||
|
||||
const dx = dPos.x;
|
||||
const dy = dPos.y;
|
||||
|
||||
if (lineCap === LineCap.BUTT) {
|
||||
this._buttCapEnd(p1, dx, dy, w, 0);
|
||||
} else if (lineCap === LineCap.SQUARE) {
|
||||
this._buttCapEnd(p1, dx, dy, w, w);
|
||||
} else if (lineCap === LineCap.ROUND) {
|
||||
this._roundCapEnd(p1, dx, dy, w, nCap);
|
||||
}
|
||||
}
|
||||
|
||||
// stroke indices
|
||||
let indicesOffset = meshBuffer.indexStart;
|
||||
for (let begin = offset + 2, over = meshBuffer.vertexStart; begin < over; begin++) {
|
||||
iData[indicesOffset++] = begin - 2;
|
||||
iData[indicesOffset++] = begin - 1;
|
||||
iData[indicesOffset++] = begin;
|
||||
}
|
||||
|
||||
meshBuffer.indexStart = indicesOffset;
|
||||
}
|
||||
_renderData = null;
|
||||
_impl = null;
|
||||
}
|
||||
|
||||
private _expandFill (graphics: Graphics): void {
|
||||
_impl = graphics.impl;
|
||||
if (!_impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const paths = _impl.paths;
|
||||
|
||||
// Calculate max vertex usage.
|
||||
let vertexCount = 0;
|
||||
for (let i = _impl.pathOffset, l = _impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
const pointsLength = path.points.length;
|
||||
|
||||
vertexCount += pointsLength;
|
||||
}
|
||||
|
||||
const renderData: MeshRenderData | null = _renderData = this.getRenderData(graphics, vertexCount);
|
||||
if (!renderData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const meshBuffer = renderData;
|
||||
const vData = meshBuffer.vData;
|
||||
const iData = meshBuffer.iData;
|
||||
|
||||
for (let i = _impl.pathOffset, l = _impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
const pts = path.points;
|
||||
const pointsLength = pts.length;
|
||||
|
||||
if (pointsLength === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate shape vertices.
|
||||
const vertexOffset = renderData.vertexStart;
|
||||
|
||||
for (let j = 0; j < pointsLength; ++j) {
|
||||
this._vSet(pts[j].x, pts[j].y);
|
||||
}
|
||||
|
||||
let indicesOffset = renderData.indexStart;
|
||||
|
||||
if (path.complex) {
|
||||
const earcutData: number[] = [];
|
||||
for (let j = vertexOffset, end = renderData.vertexStart; j < end; j++) {
|
||||
let vDataOffset = j * attrBytes;
|
||||
earcutData.push(vData[vDataOffset++]);
|
||||
earcutData.push(vData[vDataOffset++]);
|
||||
earcutData.push(vData[vDataOffset++]);
|
||||
}
|
||||
|
||||
const newIndices = Earcut(earcutData, null, 3);
|
||||
|
||||
if (!newIndices || newIndices.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let j = 0, nIndices = newIndices.length; j < nIndices; j++) {
|
||||
iData[indicesOffset++] = newIndices[j] + vertexOffset;
|
||||
}
|
||||
} else {
|
||||
const first = vertexOffset;
|
||||
for (let start = vertexOffset + 2, end = meshBuffer.vertexStart; start < end; start++) {
|
||||
iData[indicesOffset++] = first;
|
||||
iData[indicesOffset++] = start - 1;
|
||||
iData[indicesOffset++] = start;
|
||||
}
|
||||
}
|
||||
|
||||
meshBuffer.indexStart = indicesOffset;
|
||||
}
|
||||
|
||||
_renderData = null;
|
||||
_impl = null;
|
||||
}
|
||||
|
||||
private _calculateJoins (impl: Impl, w: number, lineJoin: LineJoin, miterLimit: number): void {
|
||||
let iw = 0.0;
|
||||
|
||||
if (w > 0.0) {
|
||||
iw = 1 / w;
|
||||
}
|
||||
|
||||
// Calculate which joins needs extra vertices to append, and gather vertex count.
|
||||
const paths = impl.paths;
|
||||
for (let i = impl.pathOffset, l = impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
|
||||
const pts = path.points;
|
||||
const ptsLength = pts.length;
|
||||
let p0 = pts[ptsLength - 1];
|
||||
let p1 = pts[0];
|
||||
let nLeft = 0;
|
||||
|
||||
path.bevel = 0;
|
||||
|
||||
for (let j = 0; j < ptsLength; j++) {
|
||||
let dmr2 = 0;
|
||||
let cross = 0;
|
||||
let limit = 0;
|
||||
|
||||
// perp normals
|
||||
const dlx0 = p0.dy;
|
||||
const dly0 = -p0.dx;
|
||||
const dlx1 = p1.dy;
|
||||
const dly1 = -p1.dx;
|
||||
|
||||
// Calculate extrusions
|
||||
p1.dmx = (dlx0 + dlx1) * 0.5;
|
||||
p1.dmy = (dly0 + dly1) * 0.5;
|
||||
dmr2 = p1.dmx * p1.dmx + p1.dmy * p1.dmy;
|
||||
if (dmr2 > 0.000001) {
|
||||
let scale = 1 / dmr2;
|
||||
if (scale > 600) {
|
||||
scale = 600;
|
||||
}
|
||||
p1.dmx *= scale;
|
||||
p1.dmy *= scale;
|
||||
}
|
||||
|
||||
// Keep track of left turns.
|
||||
cross = p1.dx * p0.dy - p0.dx * p1.dy;
|
||||
if (cross > 0) {
|
||||
nLeft++;
|
||||
p1.flags |= PointFlags.PT_LEFT;
|
||||
}
|
||||
|
||||
// Calculate if we should use bevel or miter for inner join.
|
||||
limit = max(11, min(p0.len, p1.len) * iw);
|
||||
if (dmr2 * limit * limit < 1) {
|
||||
p1.flags |= PointFlags.PT_INNERBEVEL;
|
||||
}
|
||||
|
||||
// Check to see if the corner needs to be beveled.
|
||||
if (p1.flags & PointFlags.PT_CORNER) {
|
||||
if (dmr2 * miterLimit * miterLimit < 1
|
||||
|| lineJoin === LineJoin.BEVEL
|
||||
|| lineJoin === LineJoin.ROUND) {
|
||||
p1.flags |= PointFlags.PT_BEVEL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((p1.flags & (PointFlags.PT_BEVEL | PointFlags.PT_INNERBEVEL)) !== 0) {
|
||||
path.bevel++;
|
||||
}
|
||||
|
||||
p0 = p1;
|
||||
p1 = pts[j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _flattenPaths (impl: Impl): void {
|
||||
const paths = impl.paths;
|
||||
for (let i = impl.pathOffset, l = impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
const pts = path.points;
|
||||
|
||||
let p0 = pts[pts.length - 1];
|
||||
let p1 = pts[0];
|
||||
|
||||
if (pts.length > 2 && p0.equals(p1)) {
|
||||
path.closed = true;
|
||||
pts.pop();
|
||||
p0 = pts[pts.length - 1];
|
||||
}
|
||||
|
||||
for (let j = 0, size = pts.length; j < size; j++) {
|
||||
// Calculate segment direction and length
|
||||
const dPos = new Point(p1.x, p1.y);
|
||||
dPos.subtract(p0);
|
||||
p0.len = dPos.length();
|
||||
if (dPos.x || dPos.y) {
|
||||
dPos.normalize();
|
||||
}
|
||||
p0.dx = dPos.x;
|
||||
p0.dy = dPos.y;
|
||||
// Advance
|
||||
p0 = p1;
|
||||
p1 = pts[j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _chooseBevel (bevel: number, p0: Point, p1: Point, w: number): [number, number, number, number] {
|
||||
const x = p1.x;
|
||||
const y = p1.y;
|
||||
let x0 = 0;
|
||||
let y0 = 0;
|
||||
let x1 = 0;
|
||||
let y1 = 0;
|
||||
|
||||
if (bevel !== 0) {
|
||||
x0 = x + p0.dy * w;
|
||||
y0 = y - p0.dx * w;
|
||||
x1 = x + p1.dy * w;
|
||||
y1 = y - p1.dx * w;
|
||||
} else {
|
||||
x0 = x1 = x + p1.dmx * w;
|
||||
y0 = y1 = y + p1.dmy * w;
|
||||
}
|
||||
|
||||
return [x0, y0, x1, y1];
|
||||
}
|
||||
|
||||
private _buttCapStart (p: Point, dx: number, dy: number, w: number, d: number): void {
|
||||
const px = p.x - dx * d;
|
||||
const py = p.y - dy * d;
|
||||
const dlx = dy;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet(px - dlx * w, py - dly * w, -1);
|
||||
}
|
||||
|
||||
private _buttCapEnd (p: Point, dx: number, dy: number, w: number, d: number): void {
|
||||
const px = p.x + dx * d;
|
||||
const py = p.y + dy * d;
|
||||
const dlx = dy;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet(px - dlx * w, py - dly * w, -1);
|
||||
}
|
||||
|
||||
private _roundCapStart (p: Point, dx: number, dy: number, w: number, nCap: number): void {
|
||||
const px = p.x;
|
||||
const py = p.y;
|
||||
const dlx = dy;
|
||||
const dly = -dx;
|
||||
|
||||
for (let i = 0; i < nCap; i++) {
|
||||
const a = i / (nCap - 1) * PI;
|
||||
const ax = cos(a) * w;
|
||||
const ay = sin(a) * w;
|
||||
this._vSet(px - dlx * ax - dx * ay, py - dly * ax - dy * ay, 1);
|
||||
this._vSet(px, py, 0);
|
||||
}
|
||||
this._vSet(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet(px - dlx * w, py - dly * w, -1);
|
||||
}
|
||||
|
||||
private _roundCapEnd (p: Point, dx: number, dy: number, w: number, nCap: number): void {
|
||||
const px = p.x;
|
||||
const py = p.y;
|
||||
const dlx = dy;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet(px - dlx * w, py - dly * w, -1);
|
||||
for (let i = 0; i < nCap; i++) {
|
||||
const a = i / (nCap - 1) * PI;
|
||||
const ax = cos(a) * w;
|
||||
const ay = sin(a) * w;
|
||||
this._vSet(px, py, 0);
|
||||
this._vSet(px - dlx * ax + dx * ay, py - dly * ax + dy * ay, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private _roundJoin (p0: Point, p1: Point, lw: number, rw: number, nCap: number): void {
|
||||
const dlx0 = p0.dy;
|
||||
const dly0 = -p0.dx;
|
||||
const dlx1 = p1.dy;
|
||||
const dly1 = -p1.dx;
|
||||
|
||||
const p1x = p1.x;
|
||||
const p1y = p1.y;
|
||||
|
||||
if ((p1.flags & PointFlags.PT_LEFT) !== 0) {
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
const lx0 = out[0];
|
||||
const ly0 = out[1];
|
||||
const lx1 = out[2];
|
||||
const ly1 = out[3];
|
||||
|
||||
const a0 = atan2(-dly0, -dlx0);
|
||||
let a1 = atan2(-dly1, -dlx1);
|
||||
if (a1 > a0) { a1 -= PI * 2; }
|
||||
|
||||
this._vSet(lx0, ly0, 1);
|
||||
this._vSet(p1x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
|
||||
const n = clamp(ceil((a0 - a1) / PI) * nCap, 2, nCap);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const u = i / (n - 1);
|
||||
const a = a0 + u * (a1 - a0);
|
||||
const rx = p1x + cos(a) * rw;
|
||||
const ry = p1y + sin(a) * rw;
|
||||
this._vSet(p1x, p1y, 0);
|
||||
this._vSet(rx, ry, -1);
|
||||
}
|
||||
|
||||
this._vSet(lx1, ly1, 1);
|
||||
this._vSet(p1x - dlx1 * rw, p1y - dly1 * rw, -1);
|
||||
} else {
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
const rx0 = out[0];
|
||||
const ry0 = out[1];
|
||||
const rx1 = out[2];
|
||||
const ry1 = out[3];
|
||||
|
||||
const a0 = atan2(dly0, dlx0);
|
||||
let a1 = atan2(dly1, dlx1);
|
||||
if (a1 < a0) { a1 += PI * 2; }
|
||||
|
||||
this._vSet(p1x + dlx0 * rw, p1y + dly0 * rw, 1);
|
||||
this._vSet(rx0, ry0, -1);
|
||||
|
||||
const n = clamp(ceil((a1 - a0) / PI) * nCap, 2, nCap);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const u = i / (n - 1);
|
||||
const a = a0 + u * (a1 - a0);
|
||||
const lx = p1x + cos(a) * lw;
|
||||
const ly = p1y + sin(a) * lw;
|
||||
this._vSet(lx, ly, 1);
|
||||
this._vSet(p1x, p1y, 0);
|
||||
}
|
||||
|
||||
this._vSet(p1x + dlx1 * rw, p1y + dly1 * rw, 1);
|
||||
this._vSet(rx1, ry1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private _bevelJoin (p0: Point, p1: Point, lw: number, rw: number): void {
|
||||
let rx0 = 0;
|
||||
let ry0 = 0;
|
||||
let rx1 = 0;
|
||||
let ry1 = 0;
|
||||
let lx0 = 0;
|
||||
let ly0 = 0;
|
||||
let lx1 = 0;
|
||||
let ly1 = 0;
|
||||
const dlx0 = p0.dy;
|
||||
const dly0 = -p0.dx;
|
||||
const dlx1 = p1.dy;
|
||||
const dly1 = -p1.dx;
|
||||
|
||||
if (p1.flags & PointFlags.PT_LEFT) {
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
lx0 = out[0];
|
||||
ly0 = out[1];
|
||||
lx1 = out[2];
|
||||
ly1 = out[3];
|
||||
|
||||
this._vSet(lx0, ly0, 1);
|
||||
this._vSet(p1.x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
|
||||
this._vSet(lx1, ly1, 1);
|
||||
this._vSet(p1.x - dlx1 * rw, p1.y - dly1 * rw, -1);
|
||||
} else {
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
rx0 = out[0];
|
||||
ry0 = out[1];
|
||||
rx1 = out[2];
|
||||
ry1 = out[3];
|
||||
|
||||
this._vSet(p1.x + dlx0 * lw, p1.y + dly0 * lw, 1);
|
||||
this._vSet(rx0, ry0, -1);
|
||||
|
||||
this._vSet(p1.x + dlx1 * lw, p1.y + dly1 * lw, 1);
|
||||
this._vSet(rx1, ry1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private _vSet (x: number, y: number, distance = 0): void {
|
||||
if (!_renderData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const meshBuffer = _renderData;
|
||||
let dataOffset = meshBuffer.vertexStart * attrBytes;
|
||||
const vData = meshBuffer.vData;
|
||||
// vec3.set(_tempVec3, x, y, 0);
|
||||
// vec3.transformMat4(_tempVec3, _tempVec3, _currMatrix);
|
||||
|
||||
vData[dataOffset++] = x;
|
||||
vData[dataOffset++] = y;
|
||||
vData[dataOffset++] = 0;
|
||||
Color.toArray(vData, _curColor, dataOffset);
|
||||
dataOffset += 4;
|
||||
vData[dataOffset++] = distance;
|
||||
meshBuffer.vertexStart++;
|
||||
}
|
||||
}
|
||||
|
||||
export const graphicsAssembler = new GraphicsAssembler();
|
||||
@@ -1,266 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { Color, Vec2 } from '../../../../core';
|
||||
import { Graphics } from '../../../components/graphics';
|
||||
import { RenderData, MeshRenderData } from '../../../renderer/render-data';
|
||||
import { RenderDrawInfoType } from '../../../renderer/render-draw-info';
|
||||
import { arc, ellipse, roundRect, tesselateBezier } from '../helper';
|
||||
import { LineCap, LineJoin, PointFlags } from '../types';
|
||||
|
||||
export class Point extends Vec2 {
|
||||
public dx = 0;
|
||||
public dy = 0;
|
||||
public dmx = 0;
|
||||
public dmy = 0;
|
||||
public flags = 0;
|
||||
public len = 0;
|
||||
|
||||
constructor (x: number, y: number) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public reset (): void {
|
||||
this.dx = 0;
|
||||
this.dy = 0;
|
||||
this.dmx = 0;
|
||||
this.dmy = 0;
|
||||
this.flags = 0;
|
||||
this.len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class Path {
|
||||
public closed = false;
|
||||
public bevel = 0;
|
||||
public complex = true;
|
||||
public points: Point[] = [];
|
||||
|
||||
public reset (): void {
|
||||
this.closed = false;
|
||||
this.bevel = 0;
|
||||
this.complex = true;
|
||||
this.points.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** @mangle */
|
||||
export class Impl {
|
||||
public dataOffset = 0;
|
||||
public updatePathOffset = false;
|
||||
|
||||
public pathLength = 0;
|
||||
public pathOffset = 0;
|
||||
|
||||
public paths: Path[] = [];
|
||||
// inner properties
|
||||
public tessTol = 0.25;
|
||||
public distTol = 0.01;
|
||||
public fillColor = Color.WHITE.clone();
|
||||
public lineCap = LineCap.BUTT;
|
||||
public strokeColor = Color.BLACK.clone();
|
||||
public lineJoin = LineJoin.MITER;
|
||||
public lineWidth = 0;
|
||||
|
||||
public pointsOffset = 0;
|
||||
|
||||
private _commandX = 0;
|
||||
private _commandY = 0;
|
||||
private _points: Point[] = [];
|
||||
private _renderDataList: MeshRenderData[] = [];
|
||||
private _curPath: Path | null = null;
|
||||
private declare _comp: Graphics;
|
||||
|
||||
constructor (comp: Graphics) {
|
||||
this._comp = comp;
|
||||
}
|
||||
|
||||
public moveTo (x: number, y: number): void {
|
||||
if (this.updatePathOffset) {
|
||||
this.pathOffset = this.pathLength;
|
||||
this.updatePathOffset = false;
|
||||
}
|
||||
|
||||
this._addPath();
|
||||
this.addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandX = x;
|
||||
this._commandY = y;
|
||||
}
|
||||
|
||||
public lineTo (x: number, y: number): void {
|
||||
this.addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandX = x;
|
||||
this._commandY = y;
|
||||
}
|
||||
|
||||
public bezierCurveTo (c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): void {
|
||||
const path = this._curPath!;
|
||||
const last = path.points[path.points.length - 1];
|
||||
if (!last) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (last.x === c1x && last.y === c1y && c2x === x && c2y === y) {
|
||||
this.lineTo(x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
tesselateBezier(this, last.x, last.y, c1x, c1y, c2x, c2y, x, y, 0, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandX = x;
|
||||
this._commandY = y;
|
||||
}
|
||||
|
||||
public quadraticCurveTo (cx: number, cy: number, x: number, y: number): void {
|
||||
const x0 = this._commandX;
|
||||
const y0 = this._commandY;
|
||||
this.bezierCurveTo(x0 + 2.0 / 3.0 * (cx - x0), y0 + 2.0 / 3.0 * (cy - y0), x + 2.0 / 3.0 * (cx - x), y + 2.0 / 3.0 * (cy - y), x, y);
|
||||
}
|
||||
|
||||
public arc (cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise: boolean): void {
|
||||
arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
}
|
||||
|
||||
public ellipse (cx: number, cy: number, rx: number, ry: number): void {
|
||||
ellipse(this, cx, cy, rx, ry);
|
||||
this._curPath!.complex = false;
|
||||
}
|
||||
|
||||
public circle (cx: number, cy: number, r: number): void {
|
||||
ellipse(this, cx, cy, r, r);
|
||||
this._curPath!.complex = false;
|
||||
}
|
||||
|
||||
public rect (x: number, y: number, w: number, h: number): void {
|
||||
this.moveTo(x, y);
|
||||
this.lineTo(x + w, y);
|
||||
this.lineTo(x + w, y + h);
|
||||
this.lineTo(x, y + h);
|
||||
|
||||
this.close();
|
||||
this._curPath!.complex = false;
|
||||
}
|
||||
|
||||
public roundRect (x: number, y: number, w: number, h: number, r: number): void {
|
||||
roundRect(this, x, y, w, h, r);
|
||||
this._curPath!.complex = false;
|
||||
}
|
||||
|
||||
public clear (): void {
|
||||
this.pathLength = 0;
|
||||
this.pathOffset = 0;
|
||||
this.pointsOffset = 0;
|
||||
this.dataOffset = 0;
|
||||
this._curPath = null;
|
||||
this.paths.length = 0;
|
||||
this._points.length = 0;
|
||||
|
||||
const dataList = this._renderDataList;
|
||||
for (let i = 0, l = dataList.length; i < l; i++) {
|
||||
const data = dataList[i];
|
||||
if (!data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MeshRenderData.remove(data);
|
||||
if (JSB) {
|
||||
this._comp.renderEntity.clearRenderDrawInfos();
|
||||
}
|
||||
}
|
||||
|
||||
this._renderDataList.length = 0;
|
||||
}
|
||||
|
||||
public close (): void {
|
||||
this._curPath!.closed = true;
|
||||
}
|
||||
|
||||
public requestRenderData (): MeshRenderData {
|
||||
const renderData = MeshRenderData.add();
|
||||
this._renderDataList.push(renderData);
|
||||
if (JSB) {
|
||||
renderData.initRenderDrawInfo(this._comp, RenderDrawInfoType.MODEL);
|
||||
// TODO: MeshRenderData and RenderData are both sub class of BaseRenderData, here we weirdly use MeshRenderData as RenderData
|
||||
// please fix the type @holycanvas
|
||||
// issue: https://github.com/cocos/cocos-engine/issues/14637
|
||||
renderData.material = this._comp.getMaterialInstance(0)!;// hack
|
||||
this._comp.setRenderData(renderData as unknown as RenderData);
|
||||
}
|
||||
|
||||
return renderData;
|
||||
}
|
||||
|
||||
public getRenderDataList (): MeshRenderData[] {
|
||||
if (this._renderDataList.length === 0) {
|
||||
this.requestRenderData();
|
||||
}
|
||||
|
||||
return this._renderDataList;
|
||||
}
|
||||
|
||||
public addPoint (x: number, y: number, flags: PointFlags): void {
|
||||
const path = this._curPath;
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
const points = this._points;
|
||||
const pathPoints = path.points;
|
||||
|
||||
const offset = this.pointsOffset++;
|
||||
let pt: Point = points[offset];
|
||||
|
||||
if (!pt) {
|
||||
pt = new Point(x, y);
|
||||
points.push(pt);
|
||||
} else {
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
}
|
||||
|
||||
pt.flags = flags;
|
||||
pathPoints.push(pt);
|
||||
}
|
||||
|
||||
private _addPath (): Path {
|
||||
const offset = this.pathLength;
|
||||
let path = this.paths[offset];
|
||||
|
||||
if (!path) {
|
||||
path = new Path();
|
||||
|
||||
this.paths.push(path);
|
||||
} else {
|
||||
path.reset();
|
||||
}
|
||||
|
||||
this.pathLength++;
|
||||
this._curPath = path;
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { UIRenderer } from '../../../framework/ui-renderer';
|
||||
import { IAssembler, IAssemblerManager } from '../../../renderer/base';
|
||||
import { Graphics } from '../../../components/graphics';
|
||||
import { graphicsAssembler as graphics } from './graphics-assembler';
|
||||
|
||||
const graphicsAssemblerManager: IAssemblerManager = {
|
||||
getAssembler (sprite: UIRenderer): IAssembler {
|
||||
return graphics;
|
||||
},
|
||||
};
|
||||
|
||||
Graphics.Assembler = graphicsAssemblerManager;
|
||||
export {
|
||||
graphics,
|
||||
graphicsAssemblerManager as graphicsAssembler,
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import './utils';
|
||||
|
||||
export * from './label';
|
||||
export * from './sprite';
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Color } from '../../../core';
|
||||
import type { IBatcher } from '../../renderer/i-batcher';
|
||||
import type { Label } from '../../components/label';
|
||||
import type { IAssembler } from '../../renderer/base';
|
||||
import { fillMeshVertices3D } from '../utils';
|
||||
import { BmfontUtils } from './bmfontUtils';
|
||||
import type { RenderData } from '../../renderer/render-data';
|
||||
|
||||
const tempColor = new Color(255, 255, 255, 255);
|
||||
|
||||
/**
|
||||
* bmfont 组装器
|
||||
* 可通过 `UI.bmfont` 获取该组装器。
|
||||
*/
|
||||
class Bmfont extends BmfontUtils implements IAssembler {
|
||||
createData (comp: Label): RenderData {
|
||||
const renderData = comp.requestRenderData();
|
||||
renderData.resize(0, 0);
|
||||
return renderData;
|
||||
}
|
||||
|
||||
fillBuffers (comp: Label, renderer: IBatcher): void {
|
||||
const node = comp.node;
|
||||
tempColor.set(comp.color);
|
||||
tempColor.a = node._uiProps.opacity * 255;
|
||||
// Fill All
|
||||
fillMeshVertices3D(node, renderer, comp.renderData, tempColor);
|
||||
}
|
||||
}
|
||||
|
||||
export const bmfont = new Bmfont();
|
||||
@@ -1,334 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { IConfig, FontAtlas, type BitmapFont } from '../../assets/bitmap-font';
|
||||
import { SpriteFrame } from '../../assets/sprite-frame';
|
||||
import { Rect, errorID } from '../../../core';
|
||||
import { Label, Overflow, CacheMode } from '../../components/label';
|
||||
import { UITransform } from '../../framework/ui-transform';
|
||||
import { LetterAtlas, shareLabelInfo } from './font-utils';
|
||||
import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager';
|
||||
import { TextProcessing } from './text-processing';
|
||||
import { TextOutputLayoutData, TextOutputRenderData } from './text-output-data';
|
||||
import { TextStyle } from './text-style';
|
||||
import { TextLayout } from './text-layout';
|
||||
import { view } from '../../../ui/view';
|
||||
|
||||
const _defaultLetterAtlas = new LetterAtlas(64, 64);
|
||||
const _defaultFontAtlas = new FontAtlas(null);
|
||||
|
||||
let _comp: Label | null = null;
|
||||
let _uiTrans: UITransform | null = null;
|
||||
|
||||
let _fntConfig: IConfig | null = null;
|
||||
let _spriteFrame: SpriteFrame | null = null;
|
||||
let QUAD_INDICES: Uint16Array | null = null;
|
||||
|
||||
export class BmfontUtils {
|
||||
updateProcessingData (
|
||||
style: TextStyle,
|
||||
layout: TextLayout,
|
||||
outputLayoutData: TextOutputLayoutData,
|
||||
outputRenderData: TextOutputRenderData,
|
||||
comp: Label,
|
||||
trans: UITransform,
|
||||
): void {
|
||||
style.fontSize = comp.fontSize;
|
||||
style.actualFontSize = comp.fontSize;
|
||||
style.originFontSize = _fntConfig ? _fntConfig.fontSize : comp.fontSize;
|
||||
layout.horizontalAlign = comp.horizontalAlign;
|
||||
layout.verticalAlign = comp.verticalAlign;
|
||||
layout.spacingX = comp.spacingX;
|
||||
const overflow = comp.overflow;
|
||||
layout.overFlow = overflow;
|
||||
layout.lineHeight = comp.lineHeight;
|
||||
|
||||
const nodeContentSize = outputLayoutData.nodeContentSize;
|
||||
nodeContentSize.width = trans.width;
|
||||
nodeContentSize.height = trans.height;
|
||||
|
||||
// should wrap text
|
||||
if (overflow === Overflow.NONE) {
|
||||
layout.wrapping = false;
|
||||
nodeContentSize.width += shareLabelInfo.margin * 2;
|
||||
nodeContentSize.height += shareLabelInfo.margin * 2;
|
||||
} else if (overflow === Overflow.RESIZE_HEIGHT) {
|
||||
layout.wrapping = true;
|
||||
nodeContentSize.height += shareLabelInfo.margin * 2;
|
||||
} else {
|
||||
layout.wrapping = comp.enableWrapText;
|
||||
}
|
||||
outputRenderData.uiTransAnchorX = trans.anchorX;
|
||||
outputRenderData.uiTransAnchorY = trans.anchorY;
|
||||
|
||||
shareLabelInfo.lineHeight = comp.lineHeight;
|
||||
shareLabelInfo.fontSize = comp.fontSize;
|
||||
|
||||
style.spriteFrame = _spriteFrame;
|
||||
style.fntConfig = _fntConfig;
|
||||
style.fontFamily = shareLabelInfo.fontFamily;
|
||||
|
||||
style.color.set(comp.color);
|
||||
}
|
||||
|
||||
updateRenderData (comp: Label): void {
|
||||
if (!comp.renderData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_comp === comp) { return; }
|
||||
|
||||
if (comp.renderData.vertDirty) {
|
||||
_comp = comp;
|
||||
_uiTrans = _comp.node._getUITransformComp()!;
|
||||
const renderData = comp.renderData;
|
||||
|
||||
const processing = TextProcessing.instance;
|
||||
const style = comp.textStyle;
|
||||
const layout = comp.textLayout;
|
||||
const outputLayoutData = comp.textLayoutData;
|
||||
const outputRenderData = comp.textRenderData;
|
||||
style.fontScale = view.getScaleX();
|
||||
this._updateFontFamily(comp);
|
||||
|
||||
this.updateProcessingData(style, layout, outputLayoutData, outputRenderData, comp, _uiTrans);
|
||||
|
||||
this._updateLabelInfo(comp);
|
||||
|
||||
style.fontDesc = shareLabelInfo.fontDesc;
|
||||
|
||||
// TextProcessing
|
||||
processing.processingString(true, style, layout, outputLayoutData, comp.string);
|
||||
// generateVertex
|
||||
outputRenderData.quadCount = 0;
|
||||
processing.generateRenderInfo(
|
||||
true,
|
||||
style,
|
||||
layout,
|
||||
outputLayoutData,
|
||||
outputRenderData,
|
||||
comp.string,
|
||||
this.generateVertexData,
|
||||
);
|
||||
let isResized = false;
|
||||
if (renderData.dataLength !== outputRenderData.quadCount) {
|
||||
this.resetRenderData(comp);
|
||||
renderData.dataLength = outputRenderData.quadCount;
|
||||
renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3);
|
||||
isResized = true;
|
||||
}
|
||||
const datalist = renderData.data;
|
||||
for (let i = 0, l = outputRenderData.quadCount; i < l; i++) {
|
||||
datalist[i] = outputRenderData.vertexBuffer[i];
|
||||
}
|
||||
|
||||
const indexCount = renderData.indexCount;
|
||||
this.createQuadIndices(indexCount);
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES!);
|
||||
|
||||
_comp.actualFontSize = style.actualFontSize;
|
||||
_uiTrans.setContentSize(outputLayoutData.nodeContentSize);
|
||||
this.updateUVs(comp);// dirty need
|
||||
// It is reasonable that the '_comp.node._uiProps.colorDirty' interface should be used.
|
||||
// But this function is not called when just modifying the opacity.
|
||||
// So the value of '_comp.node._uiProps.colorDirty' does not change.
|
||||
// And _uiProps.colorDirty is synchronized with renderEntity.colorDirty.
|
||||
if (JSB && (_comp.renderEntity.colorDirty || isResized)) {
|
||||
this.updateColor(comp); // dirty need
|
||||
_comp.node._uiProps.colorDirty = false;
|
||||
}
|
||||
|
||||
renderData.vertDirty = false;
|
||||
_comp = null;
|
||||
|
||||
this._resetProperties();
|
||||
}
|
||||
|
||||
if (comp.spriteFrame) {
|
||||
const renderData = comp.renderData;
|
||||
renderData.updateRenderData(comp, comp.spriteFrame);
|
||||
}
|
||||
}
|
||||
|
||||
updateUVs (label: Label): void {
|
||||
const renderData = label.renderData;
|
||||
if (!renderData) return;
|
||||
const vData = renderData.chunk.vb;
|
||||
const vertexCount = renderData.vertexCount;
|
||||
const stride = renderData.floatStride;
|
||||
const dataList = renderData.data;
|
||||
let vertexOffset = 3;
|
||||
for (let i = 0; i < vertexCount; i++) {
|
||||
const vert = dataList[i];
|
||||
vData[vertexOffset] = vert.u;
|
||||
vData[vertexOffset + 1] = vert.v;
|
||||
vertexOffset += stride;
|
||||
}
|
||||
}
|
||||
|
||||
updateColor (label: Label): void {
|
||||
const renderData = label.renderData;
|
||||
if (JSB && renderData) {
|
||||
const vertexCount = renderData.vertexCount;
|
||||
if (vertexCount === 0) return;
|
||||
const vData = renderData.chunk.vb;
|
||||
const stride = renderData.floatStride;
|
||||
let colorOffset = 5;
|
||||
const color = label.color;
|
||||
const colorR = color.r / 255;
|
||||
const colorG = color.g / 255;
|
||||
const colorB = color.b / 255;
|
||||
const colorA = color.a / 255;
|
||||
for (let i = 0; i < vertexCount; i++) {
|
||||
vData[colorOffset] = colorR;
|
||||
vData[colorOffset + 1] = colorG;
|
||||
vData[colorOffset + 2] = colorB;
|
||||
vData[colorOffset + 3] = colorA;
|
||||
colorOffset += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected resetRenderData (comp: Label): void {
|
||||
const renderData = comp.renderData;
|
||||
if (!renderData) return;
|
||||
renderData.dataLength = 0;
|
||||
renderData.resize(0, 0);
|
||||
}
|
||||
|
||||
// callBack function
|
||||
protected generateVertexData (
|
||||
style: TextStyle,
|
||||
outputLayoutData: TextOutputLayoutData,
|
||||
outputRenderData: TextOutputRenderData,
|
||||
offset: number,
|
||||
spriteFrame: SpriteFrame,
|
||||
rect: Rect,
|
||||
rotated: boolean,
|
||||
x: number,
|
||||
y: number,
|
||||
): void {
|
||||
const dataOffset = offset;
|
||||
const scale = style.bmfontScale;
|
||||
|
||||
const dataList = outputRenderData.vertexBuffer;
|
||||
const texW = spriteFrame.width;
|
||||
const texH = spriteFrame.height;
|
||||
|
||||
const rectWidth = rect.width;
|
||||
const rectHeight = rect.height;
|
||||
|
||||
let l = 0;
|
||||
let b = 0;
|
||||
let t = 0;
|
||||
let r = 0;
|
||||
if (!rotated) {
|
||||
l = (rect.x) / texW;
|
||||
r = (rect.x + rectWidth) / texW;
|
||||
b = (rect.y + rectHeight) / texH;
|
||||
t = (rect.y) / texH;
|
||||
|
||||
dataList[dataOffset].u = l;
|
||||
dataList[dataOffset].v = b;
|
||||
dataList[dataOffset + 1].u = r;
|
||||
dataList[dataOffset + 1].v = b;
|
||||
dataList[dataOffset + 2].u = l;
|
||||
dataList[dataOffset + 2].v = t;
|
||||
dataList[dataOffset + 3].u = r;
|
||||
dataList[dataOffset + 3].v = t;
|
||||
} else {
|
||||
l = (rect.x) / texW;
|
||||
r = (rect.x + rectHeight) / texW;
|
||||
b = (rect.y + rectWidth) / texH;
|
||||
t = (rect.y) / texH;
|
||||
|
||||
dataList[dataOffset].u = l;
|
||||
dataList[dataOffset].v = t;
|
||||
dataList[dataOffset + 1].u = l;
|
||||
dataList[dataOffset + 1].v = b;
|
||||
dataList[dataOffset + 2].u = r;
|
||||
dataList[dataOffset + 2].v = t;
|
||||
dataList[dataOffset + 3].u = r;
|
||||
dataList[dataOffset + 3].v = b;
|
||||
}
|
||||
|
||||
dataList[dataOffset].x = x;
|
||||
dataList[dataOffset].y = y - rectHeight * scale;
|
||||
dataList[dataOffset + 1].x = x + rectWidth * scale;
|
||||
dataList[dataOffset + 1].y = y - rectHeight * scale;
|
||||
dataList[dataOffset + 2].x = x;
|
||||
dataList[dataOffset + 2].y = y;
|
||||
dataList[dataOffset + 3].x = x + rectWidth * scale;
|
||||
dataList[dataOffset + 3].y = y;
|
||||
}
|
||||
|
||||
protected _updateFontFamily (comp: Label): void {
|
||||
const fontAsset = comp.font as BitmapFont;
|
||||
_spriteFrame = fontAsset.spriteFrame;
|
||||
_fntConfig = fontAsset.fntConfig;
|
||||
shareLabelInfo.fontAtlas = fontAsset.fontDefDictionary;
|
||||
if (!shareLabelInfo.fontAtlas) {
|
||||
if (comp.cacheMode === CacheMode.CHAR) {
|
||||
shareLabelInfo.fontAtlas = _defaultLetterAtlas;
|
||||
} else {
|
||||
shareLabelInfo.fontAtlas = _defaultFontAtlas;
|
||||
}
|
||||
}
|
||||
|
||||
dynamicAtlasManager.packToDynamicAtlas(comp, _spriteFrame);
|
||||
// TODO update material and uv
|
||||
}
|
||||
|
||||
protected _updateLabelInfo (comp: Label): void {
|
||||
// clear
|
||||
shareLabelInfo.hash = '';
|
||||
shareLabelInfo.margin = 0;
|
||||
}
|
||||
|
||||
protected _resetProperties (): void {
|
||||
_fntConfig = null;
|
||||
_spriteFrame = null;
|
||||
shareLabelInfo.hash = '';
|
||||
shareLabelInfo.margin = 0;
|
||||
}
|
||||
|
||||
protected createQuadIndices (indexCount: number): void {
|
||||
if (indexCount % 6 !== 0) {
|
||||
errorID(16308);
|
||||
return;
|
||||
}
|
||||
const quadCount = indexCount / 6;
|
||||
QUAD_INDICES = new Uint16Array(indexCount);
|
||||
let offset = 0;
|
||||
for (let i = 0; i < quadCount; i++) {
|
||||
QUAD_INDICES[offset++] = 0 + i * 4;
|
||||
QUAD_INDICES[offset++] = 1 + i * 4;
|
||||
QUAD_INDICES[offset++] = 2 + i * 4;
|
||||
QUAD_INDICES[offset++] = 1 + i * 4;
|
||||
QUAD_INDICES[offset++] = 3 + i * 4;
|
||||
QUAD_INDICES[offset++] = 2 + i * 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,460 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { FontAtlas, FontLetterDefinition } from '../../assets/bitmap-font';
|
||||
import { Color, macro, warnID } from '../../../core';
|
||||
import { ImageAsset, Texture2D } from '../../../asset/assets';
|
||||
import { PixelFormat } from '../../../asset/assets/asset-enum';
|
||||
import { BufferTextureCopy } from '../../../gfx';
|
||||
import { safeMeasureText, BASELINE_RATIO, MIDDLE_RATIO, getBaselineOffset, getSymbolCodeAt } from '../../utils/text-utils';
|
||||
import { director, DirectorEvent } from '../../../game/director';
|
||||
import { ccwindow } from '../../../core/global-exports';
|
||||
import { TextureBase } from '../../../asset/assets/texture-base';
|
||||
import { buildFontDesc, CssFontFamily, DEFAULT_FONT_FAMILY } from '../../utils/font-family';
|
||||
|
||||
export interface ISharedLabelData {
|
||||
canvas: HTMLCanvasElement;
|
||||
context: CanvasRenderingContext2D | null;
|
||||
}
|
||||
|
||||
let _canvasPool: CanvasPool;
|
||||
|
||||
export class CanvasPool {
|
||||
static getInstance (): CanvasPool {
|
||||
if (!_canvasPool) {
|
||||
_canvasPool = new CanvasPool();
|
||||
}
|
||||
return _canvasPool;
|
||||
}
|
||||
|
||||
private constructor () {}
|
||||
|
||||
public pool: ISharedLabelData[] = [];
|
||||
public get (): ISharedLabelData {
|
||||
let data = this.pool.pop();
|
||||
|
||||
if (!data) {
|
||||
const canvas = ccwindow.document.createElement('canvas');
|
||||
const context = canvas.getContext('2d');
|
||||
data = {
|
||||
canvas,
|
||||
context,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public put (canvas: ISharedLabelData): void {
|
||||
if (this.pool.length >= macro.MAX_LABEL_CANVAS_POOL_SIZE) {
|
||||
if (JSB) {
|
||||
const c = canvas.canvas as any;
|
||||
if (c && c._destroy) {
|
||||
c._destroy();
|
||||
}
|
||||
canvas.canvas = null!;
|
||||
canvas.context = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.pool.push(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
// export function packToDynamicAtlas(comp, frame) {
|
||||
// // TODO: Material API design and export from editor could affect the material activation process
|
||||
// // need to update the logic here
|
||||
// if (frame && !TEST) {
|
||||
// if (!frame._original && dynamicAtlasManager) {
|
||||
// let packedFrame = dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
// if (packedFrame) {
|
||||
// frame._setDynamicAtlasFrame(packedFrame);
|
||||
// }
|
||||
// }
|
||||
// if (comp.sharedMaterials[0].getProperty('texture') !== frame._texture) {
|
||||
// comp._activateMaterial();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
interface ILabelInfo {
|
||||
fontSize: number;
|
||||
lineHeight: number;
|
||||
hash: string;
|
||||
fontFamily: CssFontFamily;
|
||||
fontDesc: string;
|
||||
hAlign: number;
|
||||
vAlign: number;
|
||||
color: Color;
|
||||
isOutlined: boolean;
|
||||
out: Color;
|
||||
margin: number;
|
||||
fontScale: number;
|
||||
}
|
||||
|
||||
const WHITE = Color.WHITE.clone();
|
||||
const space = 0;
|
||||
const bleed = 2;
|
||||
|
||||
const _backgroundStyle = `rgba(255, 255, 255, ${(1 / 255).toFixed(3)})`;
|
||||
const BASELINE_OFFSET = getBaselineOffset();
|
||||
|
||||
class LetterTexture {
|
||||
public image: ImageAsset | null = null;
|
||||
public declare labelInfo: ILabelInfo;
|
||||
public declare char: string;
|
||||
public data: ISharedLabelData | null = null;
|
||||
public canvas: HTMLCanvasElement | null = null;
|
||||
public context: CanvasRenderingContext2D | null = null;
|
||||
public width = 0;
|
||||
public height = 0;
|
||||
public offsetY = 0;
|
||||
public declare hash: string;
|
||||
constructor (char: string, labelInfo: ILabelInfo) {
|
||||
this.char = char;
|
||||
this.labelInfo = labelInfo;
|
||||
this.hash = `${getSymbolCodeAt(char, 0)}${labelInfo.hash}`;
|
||||
}
|
||||
|
||||
public updateRenderData (): void {
|
||||
this._updateProperties();
|
||||
this._updateTexture();
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
this.image = null;
|
||||
CanvasPool.getInstance().put(this.data as ISharedLabelData);
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
private _updateProperties (): void {
|
||||
this.data = CanvasPool.getInstance().get();
|
||||
this.canvas = this.data.canvas;
|
||||
this.context = this.data.context;
|
||||
if (this.context) {
|
||||
const fontScale = this.labelInfo.fontScale;
|
||||
this.context.font = this.labelInfo.fontDesc;
|
||||
const width = safeMeasureText(this.context, this.char, this.labelInfo.fontDesc);
|
||||
const blank = this.labelInfo.margin * 2 + bleed;
|
||||
this.width = parseFloat(width.toFixed(2)) * fontScale + blank;
|
||||
this.height = (1 + BASELINE_RATIO) * this.labelInfo.fontSize * fontScale + blank;
|
||||
this.offsetY = -(this.labelInfo.fontSize * BASELINE_RATIO) * fontScale / 2;
|
||||
}
|
||||
|
||||
if (this.canvas.width !== this.width) {
|
||||
this.canvas.width = this.width;
|
||||
}
|
||||
|
||||
if (this.canvas.height !== this.height) {
|
||||
this.canvas.height = this.height;
|
||||
}
|
||||
|
||||
if (!this.image) {
|
||||
this.image = new ImageAsset();
|
||||
}
|
||||
|
||||
this.image.reset(this.canvas);
|
||||
}
|
||||
|
||||
private _updateTexture (): void {
|
||||
if (!this.context || !this.canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
const context = this.context;
|
||||
const labelInfo = this.labelInfo;
|
||||
const width = this.canvas.width;
|
||||
const height = this.canvas.height;
|
||||
const fontScale = labelInfo.fontScale;
|
||||
|
||||
context.textAlign = 'center';
|
||||
context.textBaseline = 'alphabetic';
|
||||
context.clearRect(0, 0, width, height);
|
||||
// Add a white background to avoid black edges.
|
||||
context.fillStyle = _backgroundStyle;
|
||||
context.fillRect(0, 0, width, height);
|
||||
context.font = buildFontDesc(labelInfo.fontSize * fontScale, labelInfo.fontFamily);
|
||||
|
||||
const fontSize = labelInfo.fontSize * fontScale;
|
||||
const startX = width / 2;
|
||||
const startY = height / 2 + fontSize * MIDDLE_RATIO + fontSize * BASELINE_OFFSET;
|
||||
const color = labelInfo.color;
|
||||
// use round for line join to avoid sharp intersect point
|
||||
context.lineJoin = 'round';
|
||||
context.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${1})`;
|
||||
if (labelInfo.isOutlined) {
|
||||
const strokeColor = labelInfo.out || WHITE;
|
||||
context.strokeStyle = `rgba(${strokeColor.r}, ${strokeColor.g}, ${strokeColor.b}, ${strokeColor.a / 255})`;
|
||||
context.lineWidth = labelInfo.margin * 2 * fontScale;
|
||||
context.strokeText(this.char, startX, startY);
|
||||
}
|
||||
context.fillText(this.char, startX, startY);
|
||||
|
||||
// this.texture.handleLoadedTexture();
|
||||
// (this.image as Texture2D).updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
export class LetterRenderTexture extends Texture2D {
|
||||
/**
|
||||
* @en
|
||||
* Init the render texture with size.
|
||||
* @zh
|
||||
* 初始化 render texture。
|
||||
* @param [width]
|
||||
* @param [height]
|
||||
* @param [string]
|
||||
*/
|
||||
public initWithSize (width: number, height: number, format: number = PixelFormat.RGBA8888): void {
|
||||
this.reset({
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Draw a texture to the specified position
|
||||
* @zh 将指定的图片渲染到指定的位置上。
|
||||
* @param {Texture2D} image
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
public drawTextureAt (image: ImageAsset, x: number, y: number): void {
|
||||
const gfxTexture = this.getGFXTexture();
|
||||
if (!image || !gfxTexture) {
|
||||
return;
|
||||
}
|
||||
|
||||
const gfxDevice = this._getGFXDevice();
|
||||
if (!gfxDevice) {
|
||||
warnID(16363);
|
||||
return;
|
||||
}
|
||||
|
||||
const region = new BufferTextureCopy();
|
||||
region.texOffset.x = x;
|
||||
region.texOffset.y = y;
|
||||
region.texExtent.width = image.width;
|
||||
region.texExtent.height = image.height;
|
||||
gfxDevice.copyTexImagesToTexture([image.data as HTMLCanvasElement], gfxTexture, [region]);
|
||||
}
|
||||
}
|
||||
|
||||
export class LetterAtlas {
|
||||
get width (): number {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
get height (): number {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
private _x = space;
|
||||
private _y = space;
|
||||
private _nextY = space;
|
||||
private _width = 0;
|
||||
private _height = 0;
|
||||
private _halfBleed = 0;
|
||||
public declare fontDefDictionary: FontAtlas;
|
||||
private _dirty = false;
|
||||
|
||||
constructor (width: number, height: number) {
|
||||
const texture = new LetterRenderTexture();
|
||||
texture.initWithSize(width, height);
|
||||
|
||||
this.fontDefDictionary = new FontAtlas(texture);
|
||||
this._halfBleed = bleed / 2;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
director.on(DirectorEvent.BEFORE_SCENE_LAUNCH, this.beforeSceneLoad, this);
|
||||
}
|
||||
|
||||
public insertLetterTexture (letterTexture: LetterTexture): FontLetterDefinition | null {
|
||||
const img = letterTexture.image;
|
||||
const device = director.root!.device;
|
||||
if (!img || !this.fontDefDictionary || !device) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const width = img.width;
|
||||
const height = img.height;
|
||||
|
||||
if ((this._x + width + space) > this._width) {
|
||||
this._x = space;
|
||||
this._y = this._nextY;
|
||||
}
|
||||
|
||||
if ((this._y + height) > this._nextY) {
|
||||
this._nextY = this._y + height + space;
|
||||
}
|
||||
|
||||
if (this._nextY > this._height) {
|
||||
warnID(12100);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.fontDefDictionary.texture) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rt = this.fontDefDictionary.texture as LetterRenderTexture;
|
||||
rt.drawTextureAt(img, this._x, this._y);
|
||||
|
||||
this._dirty = true;
|
||||
|
||||
const letterDefinition = new FontLetterDefinition();
|
||||
letterDefinition.u = this._x + this._halfBleed;
|
||||
letterDefinition.v = this._y + this._halfBleed;
|
||||
letterDefinition.valid = true;
|
||||
letterDefinition.w = letterTexture.width - bleed;
|
||||
letterDefinition.h = letterTexture.height - bleed;
|
||||
letterDefinition.xAdvance = letterDefinition.w;
|
||||
letterDefinition.offsetY = letterTexture.offsetY;
|
||||
|
||||
this._x += width + space;
|
||||
this.fontDefDictionary.addLetterDefinitions(letterTexture.hash, letterDefinition);
|
||||
/*
|
||||
const region = new BufferTextureCopy();
|
||||
region.texOffset.x = letterDefinition.offsetX;
|
||||
region.texOffset.y = letterDefinition.offsetY;
|
||||
region.texExtent.width = letterDefinition.w;
|
||||
region.texExtent.height = letterDefinition.h;
|
||||
*/
|
||||
|
||||
return letterDefinition;
|
||||
}
|
||||
|
||||
public update (): void {
|
||||
if (!this._dirty) {
|
||||
return;
|
||||
}
|
||||
// this.texture.update();
|
||||
this._dirty = false;
|
||||
}
|
||||
|
||||
public reset (): void {
|
||||
this._x = space;
|
||||
this._y = space;
|
||||
this._nextY = space;
|
||||
|
||||
// const chars = this.letterDefinitions;
|
||||
// for (let i = 0, l = (Object.keys(chars)).length; i < l; i++) {
|
||||
// const char = chars[i];
|
||||
// if (!char.valid) {
|
||||
// continue;
|
||||
// }
|
||||
// char.destroy();
|
||||
// }
|
||||
|
||||
// this.letterDefinitions = createMap();
|
||||
this.fontDefDictionary.clear();
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
this.reset();
|
||||
const dict = this.fontDefDictionary;
|
||||
if (dict && dict.texture) {
|
||||
dict.texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
getTexture (): TextureBase | null {
|
||||
return this.fontDefDictionary.getTexture();
|
||||
}
|
||||
|
||||
public beforeSceneLoad (): void {
|
||||
this.clearAllCache();
|
||||
}
|
||||
|
||||
public clearAllCache (): void {
|
||||
this.destroy();
|
||||
|
||||
const texture = new LetterRenderTexture();
|
||||
texture.initWithSize(this._width, this._height);
|
||||
|
||||
this.fontDefDictionary.texture = texture;
|
||||
}
|
||||
|
||||
public getLetter (key: string): FontLetterDefinition {
|
||||
return this.fontDefDictionary.letterDefinitions[key];
|
||||
}
|
||||
|
||||
public getLetterDefinitionForChar (char: string, labelInfo: ILabelInfo): FontLetterDefinition | null {
|
||||
const hash = getSymbolCodeAt(char, 0) + labelInfo.hash;
|
||||
let letter: FontLetterDefinition | null = this.fontDefDictionary.letterDefinitions[hash];
|
||||
if (!letter) {
|
||||
const temp = new LetterTexture(char, labelInfo);
|
||||
temp.updateRenderData();
|
||||
letter = this.insertLetterTexture(temp);
|
||||
temp.destroy();
|
||||
}
|
||||
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IShareLabelInfo {
|
||||
fontAtlas: FontAtlas | LetterAtlas | null;
|
||||
fontSize: number;
|
||||
lineHeight: number;
|
||||
hAlign: number;
|
||||
vAlign: number;
|
||||
hash: string;
|
||||
fontFamily: CssFontFamily;
|
||||
fontDesc: string;
|
||||
color: Color;
|
||||
isOutlined: boolean;
|
||||
out: Color;
|
||||
margin: number;
|
||||
fontScale: number;
|
||||
}
|
||||
|
||||
export const shareLabelInfo: IShareLabelInfo = {
|
||||
fontAtlas: null,
|
||||
fontSize: 0,
|
||||
lineHeight: 0,
|
||||
hAlign: 0,
|
||||
vAlign: 0,
|
||||
hash: '',
|
||||
fontFamily: DEFAULT_FONT_FAMILY,
|
||||
fontDesc: 'Arial',
|
||||
color: Color.WHITE.clone(),
|
||||
isOutlined: false,
|
||||
out: Color.WHITE.clone(),
|
||||
margin: 0,
|
||||
fontScale: 1,
|
||||
};
|
||||
|
||||
export function computeHash (labelInfo): string {
|
||||
const hashData = '';
|
||||
const color = labelInfo.color.toHEX();
|
||||
let out = '';
|
||||
if (labelInfo.isOutlined && labelInfo.margin > 0) {
|
||||
out = out + labelInfo.margin + labelInfo.out.toHEX();
|
||||
}
|
||||
|
||||
return hashData + labelInfo.fontSize + labelInfo.fontFamily + color + out;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { BitmapFont } from '../../assets';
|
||||
import { CacheMode, Label } from '../../components';
|
||||
import type { IAssembler, IAssemblerManager } from '../../renderer/base';
|
||||
import { bmfont } from './bmfont';
|
||||
import { letter } from './letter';
|
||||
import { ttf } from './ttf';
|
||||
import { TextProcessing } from './text-processing';
|
||||
|
||||
const labelAssembler: IAssemblerManager = {
|
||||
getAssembler (comp: Label): IAssembler {
|
||||
let assembler: IAssembler = ttf;
|
||||
|
||||
if (comp.font instanceof BitmapFont) {
|
||||
assembler = bmfont;
|
||||
} else if (comp.cacheMode === CacheMode.CHAR) {
|
||||
assembler = letter;
|
||||
}
|
||||
|
||||
return assembler;
|
||||
},
|
||||
|
||||
// Skip invalid labels (without own _assembler)
|
||||
// updateRenderData(label) {
|
||||
// return label.__allocedDatas;
|
||||
// }
|
||||
};
|
||||
|
||||
export {
|
||||
labelAssembler,
|
||||
ttf,
|
||||
bmfont,
|
||||
letter,
|
||||
TextProcessing,
|
||||
};
|
||||
|
||||
Label.Assembler = labelAssembler;
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2018-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type { Label } from '../../components';
|
||||
import { IAssembler } from '../../renderer/base';
|
||||
import { BmfontUtils } from './bmfontUtils';
|
||||
import { shareLabelInfo, LetterAtlas, computeHash, LetterRenderTexture } from './font-utils';
|
||||
import { buildFontDesc, CssFontFamily, getCanvasFontFamily } from '../../utils/font-family';
|
||||
|
||||
const _atlasWidth = 1024;
|
||||
const _atlasHeight = 1024;
|
||||
const _isBold = false;
|
||||
|
||||
let _shareAtlas: LetterAtlas | null = null;
|
||||
|
||||
export class LetterFont extends BmfontUtils {
|
||||
getAssemblerData (): LetterRenderTexture | null {
|
||||
if (!_shareAtlas) {
|
||||
_shareAtlas = new LetterAtlas(_atlasWidth, _atlasHeight);
|
||||
}
|
||||
|
||||
return _shareAtlas.getTexture() as LetterRenderTexture | null;
|
||||
}
|
||||
|
||||
protected _updateFontFamily (comp: Label): void {
|
||||
shareLabelInfo.fontAtlas = _shareAtlas;
|
||||
shareLabelInfo.fontFamily = this._getFontFamily(comp);
|
||||
|
||||
// outline
|
||||
const isOutlined = comp.enableOutline && comp.outlineWidth > 0;
|
||||
if (isOutlined) {
|
||||
shareLabelInfo.isOutlined = true;
|
||||
shareLabelInfo.margin = comp.outlineWidth;
|
||||
shareLabelInfo.out = comp.outlineColor.clone();
|
||||
shareLabelInfo.out.a = comp.outlineColor.a * comp.color.a / 255.0;
|
||||
} else {
|
||||
shareLabelInfo.isOutlined = false;
|
||||
shareLabelInfo.margin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected _getFontFamily (comp: Label): CssFontFamily {
|
||||
return getCanvasFontFamily(comp);
|
||||
}
|
||||
|
||||
protected _updateLabelInfo (comp: Label): void {
|
||||
shareLabelInfo.fontDesc = this._getFontDesc();
|
||||
shareLabelInfo.color.set(comp.color);
|
||||
shareLabelInfo.hash = computeHash(shareLabelInfo);
|
||||
}
|
||||
|
||||
protected _getFontDesc (): string {
|
||||
return buildFontDesc(shareLabelInfo.fontSize, shareLabelInfo.fontFamily, _isBold);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { Color } from '../../../core';
|
||||
import type { IBatcher } from '../../renderer/i-batcher';
|
||||
import type { Label } from '../../components/label';
|
||||
import { fillMeshVertices3D } from '../utils';
|
||||
import { LetterFont } from './letter-font';
|
||||
import type { RenderData } from '../../renderer/render-data';
|
||||
import type { IAssembler } from '../../renderer/base';
|
||||
|
||||
const tempColor = new Color(255, 255, 255, 255);
|
||||
|
||||
/**
|
||||
* letter 组装器
|
||||
* 可通过 `UI.letter` 获取该组装器。
|
||||
*/
|
||||
class Letter extends LetterFont implements IAssembler {
|
||||
createData (comp: Label): RenderData {
|
||||
const renderData = comp.requestRenderData();
|
||||
renderData.resize(0, 0);
|
||||
return renderData;
|
||||
}
|
||||
|
||||
fillBuffers (comp: Label, renderer: IBatcher): void {
|
||||
if (!comp.renderData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = comp.node;
|
||||
tempColor.a = node._uiProps.opacity * 255;
|
||||
// Fill All
|
||||
fillMeshVertices3D(node, renderer, comp.renderData, tempColor);
|
||||
}
|
||||
|
||||
updateColor (label: Label): void {
|
||||
const renderData = label.renderData;
|
||||
if (JSB && renderData) {
|
||||
const vertexCount = renderData.vertexCount;
|
||||
if (vertexCount === 0) return;
|
||||
const vData = renderData.chunk.vb;
|
||||
const stride = renderData.floatStride;
|
||||
let colorOffset = 5;
|
||||
for (let i = 0; i < vertexCount; i++) {
|
||||
vData[colorOffset] = 1;
|
||||
vData[colorOffset + 1] = 1;
|
||||
vData[colorOffset + 2] = 1;
|
||||
vData[colorOffset + 3] = 1;
|
||||
colorOffset += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const letter = new Letter();
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Size } from '../../../core';
|
||||
|
||||
export class TextLayout {
|
||||
// Layout common
|
||||
// alignment
|
||||
public horizontalAlign = 0;// Enum // both
|
||||
public verticalAlign = 0;// Enum // both
|
||||
|
||||
public wrapping = true; // both
|
||||
public overFlow = 0;// Enum // both
|
||||
|
||||
public lineHeight = 10; // both
|
||||
|
||||
// bmfont extra part
|
||||
public maxLineWidth = 0; // bmfont
|
||||
public spacingX = 0; // bmfont
|
||||
|
||||
// bmfont used temp value
|
||||
public textWidthTemp = 0;
|
||||
public textHeightTemp = 0;
|
||||
public textDimensions = new Size();
|
||||
|
||||
public horizontalKerning: number[] = [];
|
||||
public numberOfLines = 1;
|
||||
|
||||
public linesOffsetX: number[] = []; // layout
|
||||
public letterOffsetY = 0;
|
||||
|
||||
public tailoredTopY = 0;
|
||||
public tailoredBottomY = 0;
|
||||
|
||||
public textDesiredHeight = 0;
|
||||
public linesWidth: number[] = [];
|
||||
|
||||
public reset (): void {
|
||||
this.horizontalAlign = 0;
|
||||
this.verticalAlign = 0;
|
||||
this.wrapping = true;
|
||||
this.overFlow = 0;
|
||||
this.lineHeight = 10;
|
||||
this.maxLineWidth = 0;
|
||||
this.spacingX = 0;
|
||||
this.textWidthTemp = 0;
|
||||
this.textHeightTemp = 0;
|
||||
this.textDimensions.set();
|
||||
this.horizontalKerning.length = 0;
|
||||
this.numberOfLines = 1;
|
||||
this.linesOffsetX.length = 0;
|
||||
this.letterOffsetY = 0;
|
||||
this.tailoredTopY = 0;
|
||||
this.tailoredBottomY = 0;
|
||||
this.textDesiredHeight = 0;
|
||||
this.linesWidth.length = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Texture2D } from '../../../asset/assets';
|
||||
import { Rect, Size, Vec2 } from '../../../core';
|
||||
import { SpriteFrame } from '../../assets';
|
||||
import { IRenderData } from './text-processing';
|
||||
|
||||
export class TextOutputLayoutData {
|
||||
// public parsedStringStyle; // Prepare for merging richtext
|
||||
// string after process
|
||||
public parsedString: string[] = [];
|
||||
|
||||
// node part
|
||||
public nodeContentSize = Size.ZERO.clone(); // both
|
||||
|
||||
// Node info
|
||||
public canvasSize = new Size(); // ttf
|
||||
|
||||
public canvasPadding = new Rect(); // ttf
|
||||
public contentSizeExtend = Size.ZERO.clone(); // ttf
|
||||
|
||||
public startPosition = Vec2.ZERO.clone(); // ttf
|
||||
|
||||
public reset (): void {
|
||||
this.parsedString.length = 0;
|
||||
this.nodeContentSize.set(0, 0);
|
||||
this.canvasSize.set();
|
||||
this.canvasPadding.set();
|
||||
this.contentSizeExtend.set();
|
||||
this.startPosition.set();
|
||||
}
|
||||
}
|
||||
|
||||
export class TextOutputRenderData {
|
||||
// Process Output
|
||||
public quadCount = 0; // both
|
||||
public vertexBuffer: IRenderData[] = []; // both
|
||||
public texture: Texture2D | SpriteFrame | null = null; // both
|
||||
|
||||
// anchor
|
||||
public uiTransAnchorX = 0.5; // both
|
||||
public uiTransAnchorY = 0.5; // both
|
||||
|
||||
public reset (): void {
|
||||
this.quadCount = 0;
|
||||
this.vertexBuffer.length = 0;
|
||||
this.texture = null;
|
||||
this.uiTransAnchorX = 0.5;
|
||||
this.uiTransAnchorY = 0.5;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Color } from '../../../core';
|
||||
import { IConfig } from '../../assets/bitmap-font';
|
||||
import { SpriteFrame } from '../../assets/sprite-frame';
|
||||
import { CssFontFamily, DEFAULT_FONT_FAMILY } from '../../utils/font-family';
|
||||
|
||||
export class TextStyle {
|
||||
// ---------------ttf extra part-----------------
|
||||
// bold // style
|
||||
public isBold = false; // ttf
|
||||
// Italic // style
|
||||
public isItalic = false; // ttf
|
||||
// under line // style
|
||||
public isUnderline = false; // ttf
|
||||
public underlineHeight = 1; // ttf
|
||||
// outline style
|
||||
public isOutlined = false; // both // ttf & char
|
||||
public outlineColor = Color.WHITE.clone(); // both // ttf & char
|
||||
public outlineWidth = 1; // both // ttf & char
|
||||
// shadowStyle
|
||||
public hasShadow = false; // ttf
|
||||
public shadowColor = Color.BLACK.clone(); // ttf
|
||||
public shadowBlur = 2; // ttf
|
||||
public shadowOffsetX = 0; // ttf
|
||||
public shadowOffsetY = 0; // ttf
|
||||
|
||||
public color = Color.WHITE.clone(); // both
|
||||
|
||||
public fontSize = 40; // input fonSize // both
|
||||
public actualFontSize = 0; // both
|
||||
|
||||
public isSystemFontUsed = false; // both // ttf & char
|
||||
|
||||
// -----------------------bitMap extra part-------------------------
|
||||
|
||||
public originFontSize = 0; //Layout // both
|
||||
public bmfontScale = 1.0;// both
|
||||
|
||||
// font info // todo merge to font
|
||||
public fontFamily: CssFontFamily = DEFAULT_FONT_FAMILY; // Serialized CSS family, both TTF and CHAR.
|
||||
public fontDesc = ''; // both
|
||||
|
||||
// -----------------------bitMap extra part-------------------------
|
||||
|
||||
// font info // todo remove
|
||||
public fntConfig: IConfig | null = null; // For char mode,not have asset
|
||||
public spriteFrame: SpriteFrame | null = null; // For char mode,not have spriteFrame in asset
|
||||
|
||||
public fontScale = 1;
|
||||
|
||||
public reset (): void {
|
||||
this.isBold = false;
|
||||
this.isItalic = false;
|
||||
this.isUnderline = false;
|
||||
this.underlineHeight = 1;
|
||||
this.isOutlined = false;
|
||||
this.outlineColor.set();
|
||||
this.outlineWidth = 1;
|
||||
this.hasShadow = false;
|
||||
this.shadowColor.set();
|
||||
this.shadowBlur = 2;
|
||||
this.shadowOffsetX = 0;
|
||||
this.shadowOffsetY = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ui-assembler 相关模块
|
||||
* @module ui-assembler
|
||||
*/
|
||||
|
||||
import { Color } from '../../../core';
|
||||
import type { IBatcher } from '../../renderer/i-batcher';
|
||||
import type { Label } from '../../components/label';
|
||||
import type { IAssembler } from '../../renderer/base';
|
||||
import { TTFUtils } from './ttfUtils';
|
||||
import type { IRenderData, RenderData } from '../../renderer/render-data';
|
||||
|
||||
const WHITE = Color.WHITE.clone();
|
||||
const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]);
|
||||
|
||||
/**
|
||||
* ttf 组装器
|
||||
* 可通过 `UI.ttf` 获取该组装器。
|
||||
*/
|
||||
export class TTF extends TTFUtils implements IAssembler {
|
||||
createData (comp: Label): RenderData {
|
||||
const renderData = comp.requestRenderData()!;
|
||||
|
||||
renderData.dataLength = 4;
|
||||
renderData.resize(4, 6);
|
||||
|
||||
// hard code
|
||||
comp.textRenderData.quadCount = 4;
|
||||
|
||||
const vData = renderData.chunk.vb;
|
||||
|
||||
const stride = renderData.floatStride;
|
||||
const uvs = [
|
||||
{ u: 0, v: 1 },
|
||||
{ u: 1, v: 1 },
|
||||
{ u: 0, v: 0 },
|
||||
{ u: 1, v: 0 },
|
||||
];
|
||||
let uvOffset = 3;
|
||||
for (let i = 0, len = renderData.dataLength; i < len; ++i) {
|
||||
vData[uvOffset] = uvs[i].u;
|
||||
vData[uvOffset + 1] = uvs[i].v;
|
||||
uvOffset += stride;
|
||||
}
|
||||
let offset = 5;
|
||||
for (let i = 0; i < renderData.dataLength; i++) {
|
||||
Color.toArray(vData, WHITE, offset);
|
||||
offset += stride;
|
||||
}
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES);
|
||||
return renderData;
|
||||
}
|
||||
|
||||
fillBuffers (comp: Label, renderer: IBatcher): void {
|
||||
const renderData = comp.renderData;
|
||||
if (!renderData) return;
|
||||
const chunk = renderData.chunk;
|
||||
const dataList: IRenderData[] = renderData.data;
|
||||
const node = comp.node;
|
||||
|
||||
const vData = chunk.vb;
|
||||
|
||||
// normal version
|
||||
const m = node.worldMatrix;
|
||||
const stride = renderData.floatStride;
|
||||
let offset = 0;
|
||||
const length = dataList.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const curData = dataList[i];
|
||||
const x = curData.x;
|
||||
const y = curData.y;
|
||||
let rhw = m.m03 * x + m.m07 * y + m.m15;
|
||||
rhw = rhw ? 1 / rhw : 1;
|
||||
|
||||
offset = i * stride;
|
||||
vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
|
||||
vData[offset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw;
|
||||
vData[offset + 2] = (m.m02 * x + m.m06 * y + m.m14) * rhw;
|
||||
}
|
||||
|
||||
// quick version
|
||||
const vid = chunk.vertexOffset;
|
||||
const meshBuffer = chunk.meshBuffer;
|
||||
const ib = chunk.meshBuffer.iData;
|
||||
let indexOffset = meshBuffer.indexOffset;
|
||||
ib[indexOffset++] = vid;
|
||||
ib[indexOffset++] = vid + 1;
|
||||
ib[indexOffset++] = vid + 2;
|
||||
ib[indexOffset++] = vid + 2;
|
||||
ib[indexOffset++] = vid + 1;
|
||||
ib[indexOffset++] = vid + 3;
|
||||
meshBuffer.indexOffset += 6;
|
||||
// slow version
|
||||
// const chunk = renderData.chunk;
|
||||
// renderer.getBufferAccessor().appendIndices(chunk);
|
||||
}
|
||||
|
||||
updateVertexData (comp: Label): void {
|
||||
const renderData = comp.renderData;
|
||||
if (!renderData) {
|
||||
return;
|
||||
}
|
||||
const uiTrans = comp.node._getUITransformComp()!;
|
||||
const width = uiTrans.width;
|
||||
const height = uiTrans.height;
|
||||
const appX = uiTrans.anchorX * width;
|
||||
const appY = uiTrans.anchorY * height;
|
||||
|
||||
const data = renderData.data;
|
||||
data[0].x = -appX; // l
|
||||
data[0].y = -appY; // b
|
||||
data[1].x = width - appX; // r
|
||||
data[1].y = -appY; // b
|
||||
data[2].x = -appX; // l
|
||||
data[2].y = height - appY; // t
|
||||
data[3].x = width - appX; // r
|
||||
data[3].y = height - appY; // t
|
||||
}
|
||||
|
||||
updateUVs (comp: Label): void {
|
||||
const renderData = comp.renderData;
|
||||
if (!renderData || !comp.ttfSpriteFrame) {
|
||||
return;
|
||||
}
|
||||
const vData = renderData.chunk.vb;
|
||||
const uv = comp.ttfSpriteFrame.uv;
|
||||
const stride = renderData.floatStride;
|
||||
let uvOffset = 3;
|
||||
for (let i = 0; i < renderData.dataLength; ++i) {
|
||||
const index = i * 2;
|
||||
vData[uvOffset] = uv[index];
|
||||
vData[uvOffset + 1] = uv[index + 1];
|
||||
uvOffset += stride;
|
||||
}
|
||||
}
|
||||
|
||||
updateColor (comp: Label): void {
|
||||
// no needs to update color
|
||||
}
|
||||
}
|
||||
|
||||
export const ttf = new TTF();
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
import { CacheMode, Label } from '../../components';
|
||||
import type { ISharedLabelData } from './font-utils';
|
||||
import type { UITransform } from '../../framework/ui-transform';
|
||||
import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager';
|
||||
import { TextProcessing } from './text-processing';
|
||||
import type { TextOutputLayoutData, TextOutputRenderData } from './text-output-data';
|
||||
import type { TextStyle } from './text-style';
|
||||
import type { TextLayout } from './text-layout';
|
||||
import { view } from '../../../ui/view';
|
||||
import { approx } from '../../../core';
|
||||
import { CssFontFamily, getCanvasFontFamily } from '../../utils/font-family';
|
||||
|
||||
const Overflow = Label.Overflow;
|
||||
|
||||
export class TTFUtils {
|
||||
updateProcessingData (
|
||||
style: TextStyle,
|
||||
layout: TextLayout,
|
||||
outputLayoutData: TextOutputLayoutData,
|
||||
outputRenderData: TextOutputRenderData,
|
||||
comp: Label,
|
||||
trans: UITransform,
|
||||
): void {
|
||||
// font info // both
|
||||
style.isSystemFontUsed = comp.useSystemFont;
|
||||
style.fontSize = comp.fontSize;
|
||||
|
||||
// node info // both
|
||||
outputLayoutData.nodeContentSize.width = outputLayoutData.canvasSize.width = trans.width;
|
||||
outputLayoutData.nodeContentSize.height = outputLayoutData.canvasSize.height = trans.height;
|
||||
// layout info
|
||||
layout.lineHeight = comp.lineHeight; // both
|
||||
layout.overFlow = comp.overflow; // layout only // but change render
|
||||
if (comp.overflow === Overflow.NONE) {
|
||||
layout.wrapping = false;
|
||||
} else if (comp.overflow === Overflow.RESIZE_HEIGHT) {
|
||||
layout.wrapping = true;
|
||||
} else {
|
||||
layout.wrapping = comp.enableWrapText; // layout only // but change render
|
||||
}
|
||||
|
||||
// effect info // both
|
||||
style.isBold = comp.isBold;
|
||||
style.isItalic = comp.isItalic;
|
||||
style.isUnderline = comp.isUnderline;
|
||||
style.underlineHeight = comp.underlineHeight;
|
||||
|
||||
// outline// both
|
||||
const isOutlined = comp.enableOutline && comp.outlineWidth > 0;
|
||||
if (isOutlined) {
|
||||
style.isOutlined = true;
|
||||
style.outlineColor.set(comp.outlineColor);
|
||||
style.outlineWidth = comp.outlineWidth;
|
||||
} else {
|
||||
style.isOutlined = false;
|
||||
}
|
||||
|
||||
// shadow// both
|
||||
const isShadow = comp.enableShadow && (comp.shadowBlur > 0 || !approx(comp.shadowOffset.x, 0) || !approx(comp.shadowOffset.y, 0));
|
||||
if (isShadow) {
|
||||
style.hasShadow = true;
|
||||
style.shadowColor.set(comp.shadowColor);
|
||||
style.shadowBlur = comp.shadowBlur;
|
||||
style.shadowOffsetX = comp.shadowOffset.x;
|
||||
style.shadowOffsetY = comp.shadowOffset.y;
|
||||
} else {
|
||||
style.hasShadow = false;
|
||||
}
|
||||
|
||||
// render info
|
||||
style.color.set(comp.color);// may opacity bug // render Only
|
||||
outputRenderData.texture = comp.spriteFrame; // render Only
|
||||
outputRenderData.uiTransAnchorX = trans.anchorX; // render Only
|
||||
outputRenderData.uiTransAnchorY = trans.anchorY; // render Only
|
||||
|
||||
layout.horizontalAlign = comp.horizontalAlign; // render Only
|
||||
layout.verticalAlign = comp.verticalAlign; // render Only
|
||||
}
|
||||
|
||||
getAssemblerData (): ISharedLabelData {
|
||||
const sharedLabelData = Label._canvasPool.get();
|
||||
sharedLabelData.canvas.width = sharedLabelData.canvas.height = 1;
|
||||
return sharedLabelData;
|
||||
}
|
||||
|
||||
resetAssemblerData (assemblerData: ISharedLabelData): void {
|
||||
if (assemblerData) {
|
||||
Label._canvasPool.put(assemblerData);
|
||||
}
|
||||
}
|
||||
|
||||
updateRenderData (comp: Label): void {
|
||||
const renderData = comp.renderData;
|
||||
if (!renderData) { return; }
|
||||
|
||||
if (renderData.vertDirty) {
|
||||
const trans = comp.node._getUITransformComp()!;
|
||||
const processing = TextProcessing.instance;
|
||||
const style = comp.textStyle;
|
||||
const layout = comp.textLayout;
|
||||
const outputLayoutData = comp.textLayoutData;
|
||||
const outputRenderData = comp.textRenderData;
|
||||
style.fontScale = view.getScaleX();
|
||||
this.updateProcessingData(style, layout, outputLayoutData, outputRenderData, comp, trans);
|
||||
// use canvas in assemblerData // to do to optimize
|
||||
processing.setCanvasUsed(comp.assemblerData!.canvas, comp.assemblerData!.context);
|
||||
style.fontFamily = this._updateFontFamily(comp);
|
||||
this._resetDynamicAtlas(comp);
|
||||
|
||||
// TextProcessing
|
||||
processing.processingString(false, style, layout, outputLayoutData, comp.string);
|
||||
processing.generateRenderInfo(
|
||||
false,
|
||||
style,
|
||||
layout,
|
||||
outputLayoutData,
|
||||
outputRenderData,
|
||||
comp.string,
|
||||
this.generateVertexData,
|
||||
);
|
||||
|
||||
renderData.textureDirty = true;
|
||||
this._calDynamicAtlas(comp, outputLayoutData);
|
||||
|
||||
comp.actualFontSize = style.actualFontSize;
|
||||
trans.setContentSize(outputLayoutData.nodeContentSize);
|
||||
|
||||
const datalist = renderData.data;
|
||||
const vertexBuffer = outputRenderData.vertexBuffer;
|
||||
datalist[0] = vertexBuffer[0];
|
||||
datalist[1] = vertexBuffer[1];
|
||||
datalist[2] = vertexBuffer[2];
|
||||
datalist[3] = vertexBuffer[3];
|
||||
|
||||
this.updateUVs(comp);
|
||||
renderData.vertDirty = false;
|
||||
comp.contentWidth = outputLayoutData.nodeContentSize.width;
|
||||
}
|
||||
|
||||
if (comp.spriteFrame) {
|
||||
const renderData = comp.renderData;
|
||||
renderData.updateRenderData(comp, comp.spriteFrame);
|
||||
}
|
||||
}
|
||||
|
||||
// callBack function
|
||||
generateVertexData (style: TextStyle, outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData): void {
|
||||
const data = outputRenderData.vertexBuffer;
|
||||
const nodeContentSize = outputLayoutData.nodeContentSize;
|
||||
const width = nodeContentSize.width;
|
||||
const height = nodeContentSize.height;
|
||||
const appX = outputRenderData.uiTransAnchorX * width;
|
||||
const appY = outputRenderData.uiTransAnchorY * height;
|
||||
|
||||
data[0].x = -appX; // l
|
||||
data[0].y = -appY; // b
|
||||
data[1].x = width - appX; // r
|
||||
data[1].y = -appY; // b
|
||||
data[2].x = -appX; // l
|
||||
data[2].y = height - appY; // t
|
||||
data[3].x = width - appX; // r
|
||||
data[3].y = height - appY; // t
|
||||
}
|
||||
|
||||
updateVertexData (comp: Label): void {
|
||||
// no needs to update vertex data
|
||||
}
|
||||
|
||||
updateUVs (comp: Label): void {
|
||||
// no needs to update uv data
|
||||
}
|
||||
|
||||
_updateFontFamily (comp: Label): CssFontFamily {
|
||||
return getCanvasFontFamily(comp);
|
||||
}
|
||||
|
||||
_calDynamicAtlas (comp: Label, outputLayoutData: TextOutputLayoutData): void {
|
||||
if (comp.cacheMode !== CacheMode.BITMAP || outputLayoutData.canvasSize.width <= 0 || outputLayoutData.canvasSize.height <= 0) return;
|
||||
const frame = comp.ttfSpriteFrame!;
|
||||
dynamicAtlasManager.packToDynamicAtlas(comp, frame);
|
||||
// TODO update material and uv
|
||||
}
|
||||
|
||||
_resetDynamicAtlas (comp: Label): void {
|
||||
if (comp.cacheMode !== CacheMode.BITMAP) return;
|
||||
const frame = comp.ttfSpriteFrame!;
|
||||
dynamicAtlasManager.deleteAtlasSpriteFrame(frame);
|
||||
frame._resetDynamicAtlasFrame();
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Mat4, errorID } from '../../../core';
|
||||
import type { IRenderData, RenderData } from '../../renderer/render-data';
|
||||
import type { IBatcher } from '../../renderer/i-batcher';
|
||||
import { Sprite } from '../../components';
|
||||
import type { IAssembler } from '../../renderer/base';
|
||||
import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager';
|
||||
import type { StaticVBChunk } from '../../renderer/static-vb-accessor';
|
||||
|
||||
const FillType = Sprite.FillType;
|
||||
const m = new Mat4();
|
||||
const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]);
|
||||
|
||||
/**
|
||||
* barFilled 组装器
|
||||
* 可通过 `UI.barFilled` 获取该组装器。
|
||||
*/
|
||||
class BarFilled implements IAssembler {
|
||||
updateRenderData (sprite: Sprite): void {
|
||||
const frame = sprite.spriteFrame;
|
||||
dynamicAtlasManager.packToDynamicAtlas(sprite, frame);
|
||||
// TODO update material and uv
|
||||
|
||||
const renderData = sprite.renderData;
|
||||
if (renderData && frame) {
|
||||
const vertDirty = renderData.vertDirty;
|
||||
|
||||
if (!vertDirty) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fillStart = sprite.fillStart;
|
||||
let fillRange = sprite.fillRange;
|
||||
if (fillRange < 0) {
|
||||
fillStart += fillRange;
|
||||
fillRange = -fillRange;
|
||||
}
|
||||
fillRange = fillStart + fillRange;
|
||||
fillStart = fillStart > 1.0 ? 1.0 : fillStart;
|
||||
fillStart = fillStart < 0.0 ? 0.0 : fillStart;
|
||||
fillRange = fillRange > 1.0 ? 1.0 : fillRange;
|
||||
fillRange = fillRange < 0.0 ? 0.0 : fillRange;
|
||||
fillRange -= fillStart;
|
||||
fillRange = fillRange < 0 ? 0 : fillRange;
|
||||
let fillEnd = fillStart + fillRange;
|
||||
fillEnd = fillEnd > 1 ? 1 : fillEnd;
|
||||
|
||||
this.updateUVs(sprite, fillStart, fillEnd); // need Dirty
|
||||
this.updateVertexData(sprite, fillStart, fillEnd);
|
||||
renderData.updateRenderData(sprite, frame);
|
||||
}
|
||||
}
|
||||
|
||||
updateUVs (sprite: Sprite, fillStart: number, fillEnd: number): void {
|
||||
const spriteFrame = sprite.spriteFrame!;
|
||||
const renderData = sprite.renderData;
|
||||
if (!renderData) return;
|
||||
const vData = renderData.chunk.vb;
|
||||
|
||||
// build uvs
|
||||
const atlasWidth = spriteFrame.width;
|
||||
const atlasHeight = spriteFrame.height;
|
||||
const textureRect = spriteFrame.rect;
|
||||
// uv computation should take spriteSheet into account.
|
||||
let ul = 0;
|
||||
let vb = 0;
|
||||
let ur = 0;
|
||||
let vt = 0;
|
||||
let quadUV0 = 0;
|
||||
let quadUV1 = 0;
|
||||
let quadUV2 = 0;
|
||||
let quadUV3 = 0;
|
||||
let quadUV4 = 0;
|
||||
let quadUV5 = 0;
|
||||
let quadUV6 = 0;
|
||||
let quadUV7 = 0;
|
||||
if (spriteFrame.isRotated()) {
|
||||
ul = (textureRect.x) / atlasWidth;
|
||||
vb = (textureRect.y + textureRect.width) / atlasHeight;
|
||||
ur = (textureRect.x + textureRect.height) / atlasWidth;
|
||||
vt = (textureRect.y) / atlasHeight;
|
||||
|
||||
quadUV0 = quadUV2 = ul;
|
||||
quadUV4 = quadUV6 = ur;
|
||||
quadUV3 = quadUV7 = vb;
|
||||
quadUV1 = quadUV5 = vt;
|
||||
} else {
|
||||
ul = (textureRect.x) / atlasWidth;
|
||||
vb = (textureRect.y + textureRect.height) / atlasHeight;
|
||||
ur = (textureRect.x + textureRect.width) / atlasWidth;
|
||||
vt = (textureRect.y) / atlasHeight;
|
||||
|
||||
quadUV0 = quadUV4 = ul;
|
||||
quadUV2 = quadUV6 = ur;
|
||||
quadUV1 = quadUV3 = vb;
|
||||
quadUV5 = quadUV7 = vt;
|
||||
}
|
||||
|
||||
const stride = renderData.floatStride;
|
||||
let uvOffset = 3;
|
||||
switch (sprite.fillType) {
|
||||
case FillType.HORIZONTAL:
|
||||
vData[uvOffset] = quadUV0 + (quadUV2 - quadUV0) * fillStart;
|
||||
vData[uvOffset + 1] = quadUV1 + (quadUV3 - quadUV1) * fillStart;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV0 + (quadUV2 - quadUV0) * fillEnd;
|
||||
vData[uvOffset + 1] = quadUV1 + (quadUV3 - quadUV1) * fillEnd;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV4 + (quadUV6 - quadUV4) * fillStart;
|
||||
vData[uvOffset + 1] = quadUV5 + (quadUV7 - quadUV5) * fillStart;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV4 + (quadUV6 - quadUV4) * fillEnd;
|
||||
vData[uvOffset + 1] = quadUV5 + (quadUV7 - quadUV5) * fillEnd;
|
||||
break;
|
||||
case FillType.VERTICAL:
|
||||
vData[uvOffset] = quadUV0 + (quadUV4 - quadUV0) * fillStart;
|
||||
vData[uvOffset + 1] = quadUV1 + (quadUV5 - quadUV1) * fillStart;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV2 + (quadUV6 - quadUV2) * fillStart;
|
||||
vData[uvOffset + 1] = quadUV3 + (quadUV7 - quadUV3) * fillStart;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV0 + (quadUV4 - quadUV0) * fillEnd;
|
||||
vData[uvOffset + 1] = quadUV1 + (quadUV5 - quadUV1) * fillEnd;
|
||||
uvOffset += stride;
|
||||
vData[uvOffset] = quadUV2 + (quadUV6 - quadUV2) * fillEnd;
|
||||
vData[uvOffset + 1] = quadUV3 + (quadUV7 - quadUV3) * fillEnd;
|
||||
break;
|
||||
default:
|
||||
errorID(2626);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private updateVertexData (sprite: Sprite, fillStart: number, fillEnd: number): void {
|
||||
const renderData: RenderData | null = sprite.renderData;
|
||||
if (!renderData) return;
|
||||
const dataList: IRenderData[] = renderData.data;
|
||||
const uiTrans = sprite.node._getUITransformComp()!;
|
||||
const width = uiTrans.width;
|
||||
const height = uiTrans.height;
|
||||
const appX = uiTrans.anchorX * width;
|
||||
const appY = uiTrans.anchorY * height;
|
||||
|
||||
let l = -appX;
|
||||
let b = -appY;
|
||||
let r = width - appX;
|
||||
let t = height - appY;
|
||||
|
||||
let progressStart = 0;
|
||||
let progressEnd = 0;
|
||||
switch (sprite.fillType) {
|
||||
case FillType.HORIZONTAL:
|
||||
progressStart = l + (r - l) * fillStart;
|
||||
progressEnd = l + (r - l) * fillEnd;
|
||||
|
||||
l = progressStart;
|
||||
r = progressEnd;
|
||||
break;
|
||||
case FillType.VERTICAL:
|
||||
progressStart = b + (t - b) * fillStart;
|
||||
progressEnd = b + (t - b) * fillEnd;
|
||||
|
||||
b = progressStart;
|
||||
t = progressEnd;
|
||||
break;
|
||||
default:
|
||||
errorID(2626);
|
||||
break;
|
||||
}
|
||||
|
||||
dataList[0].x = l;
|
||||
dataList[0].y = b;
|
||||
dataList[1].x = r;
|
||||
dataList[1].y = b;
|
||||
dataList[2].x = l;
|
||||
dataList[2].y = t;
|
||||
dataList[3].x = r;
|
||||
dataList[3].y = t;
|
||||
}
|
||||
|
||||
createData (sprite: Sprite): RenderData {
|
||||
const renderData: RenderData | null = sprite.requestRenderData();
|
||||
// 0-4 for local vertex
|
||||
renderData.dataLength = 4;
|
||||
renderData.resize(4, 6);
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES);
|
||||
|
||||
// not need
|
||||
renderData.data.forEach((data) => { data.z = 0; });
|
||||
return renderData;
|
||||
}
|
||||
|
||||
private updateWorldVertexData (sprite: Sprite, chunk: StaticVBChunk): void {
|
||||
const node = sprite.node;
|
||||
node.getWorldMatrix(m);
|
||||
|
||||
const renderData = sprite.renderData;
|
||||
if (!renderData) return;
|
||||
const stride = renderData.floatStride;
|
||||
const dataList = sprite.renderData.data;
|
||||
const vData = chunk.vb;
|
||||
|
||||
let offset = 0;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const local = dataList[i];
|
||||
const x = local.x;
|
||||
const y = local.y;
|
||||
let rhw = m.m03 * x + m.m07 * y + m.m15;
|
||||
rhw = rhw ? 1 / rhw : 1;
|
||||
|
||||
offset = i * stride;
|
||||
vData[offset] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
|
||||
vData[offset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw;
|
||||
vData[offset + 2] = (m.m02 * x + m.m06 * y + m.m14) * rhw;
|
||||
}
|
||||
}
|
||||
|
||||
fillBuffers (sprite: Sprite, renderer: IBatcher): void {
|
||||
const renderData = sprite.renderData;
|
||||
if (!renderData) return;
|
||||
const chunk = renderData.chunk;
|
||||
if (sprite._flagChangedVersion !== sprite.node.flagChangedVersion || renderData.vertDirty) {
|
||||
this.updateWorldVertexData(sprite, chunk);
|
||||
renderData.vertDirty = false;
|
||||
sprite._flagChangedVersion = sprite.node.flagChangedVersion;
|
||||
}
|
||||
|
||||
const bid = chunk.bufferId;
|
||||
const vid = chunk.vertexOffset;
|
||||
const meshBuffer = chunk.meshBuffer;
|
||||
const ib = chunk.meshBuffer.iData;
|
||||
let indexOffset = meshBuffer.indexOffset;
|
||||
ib[indexOffset++] = vid;
|
||||
ib[indexOffset++] = vid + 1;
|
||||
ib[indexOffset++] = vid + 2;
|
||||
ib[indexOffset++] = vid + 2;
|
||||
ib[indexOffset++] = vid + 1;
|
||||
ib[indexOffset++] = vid + 3;
|
||||
meshBuffer.indexOffset += 6;
|
||||
}
|
||||
|
||||
updateColor (sprite: Sprite): void {
|
||||
const renderData = sprite.renderData;
|
||||
if (!renderData) return;
|
||||
const vData = renderData.chunk.vb;
|
||||
const stride = renderData.floatStride;
|
||||
let colorOffset = 5;
|
||||
const color = sprite.color;
|
||||
const colorR = color.r / 255;
|
||||
const colorG = color.g / 255;
|
||||
const colorB = color.b / 255;
|
||||
const colorA = sprite.node._uiProps.opacity;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
vData[colorOffset] = colorR;
|
||||
vData[colorOffset + 1] = colorG;
|
||||
vData[colorOffset + 2] = colorB;
|
||||
vData[colorOffset + 3] = colorA;
|
||||
|
||||
colorOffset += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const barFilled = new BarFilled();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user