diff --git a/cocos/asset/assets/buffer-asset.jsb.ts b/cocos/asset/assets/buffer-asset.jsb.ts index b4ede886e4..45d72f9804 100644 --- a/cocos/asset/assets/buffer-asset.jsb.ts +++ b/cocos/asset/assets/buffer-asset.jsb.ts @@ -24,9 +24,12 @@ import { cclegacy } from '../../core'; import './asset'; import { patch_cc_BufferAsset } from '../../native-binding/decorators'; +import type { BufferAsset as JsbBufferAsset } from './buffer-asset'; -export type BufferAsset = jsb.BufferAsset; -export const BufferAsset = jsb.BufferAsset; +declare const jsb: any; + +export type BufferAsset = JsbBufferAsset; +export const BufferAsset: typeof JsbBufferAsset = jsb.BufferAsset; cclegacy.BufferAsset = jsb.BufferAsset; diff --git a/cocos/asset/assets/effect-asset.jsb.ts b/cocos/asset/assets/effect-asset.jsb.ts index 53dbc16ab7..d13d92a227 100644 --- a/cocos/asset/assets/effect-asset.jsb.ts +++ b/cocos/asset/assets/effect-asset.jsb.ts @@ -25,9 +25,15 @@ import{ cclegacy } from '../../core'; import './asset'; import { patch_cc_EffectAsset } from '../../native-binding/decorators'; +import type { EffectAsset as JsbEffectAsset } from './effect-asset'; +import type { BlendState, DepthStencilState, RasterizerState, DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, Uniform, MemoryAccess, Format} from "../../gfx/index.jsb"; +import type { RenderPassStage } from '../../rendering/define'; +import type { MacroRecord } from '../../render-scene/core/pass-utils'; -export type EffectAsset = jsb.EffectAsset; -export const EffectAsset = jsb.EffectAsset; +declare const jsb: any; + +export type EffectAsset = JsbEffectAsset; +export const EffectAsset: typeof JsbEffectAsset = jsb.EffectAsset; cclegacy.EffectAsset = EffectAsset; @@ -38,5 +44,149 @@ effectAssetProto._ctor = function () { this.hideInEditor = false; }; +// NOTE: TS cannot merge exported type in multiple modules, so we need to declare namespace EffectAsset again here. +export declare namespace EffectAsset { + export interface IPropertyInfo { + type: number; // auto-extracted from shader + handleInfo?: [string, number, number]; // auto-generated from 'target' + samplerHash?: number; // auto-generated from 'sampler' + value?: number[] | string; // default value + linear?: boolean; // whether to convert the input to linear space first before applying + } + // Pass instance itself are compliant to IPassStates too + export interface IPassStates { + priority?: number; + primitive?: PrimitiveMode; + stage?: RenderPassStage; + rasterizerState?: RasterizerState; + depthStencilState?: DepthStencilState; + blendState?: BlendState; + dynamicStates?: DynamicStateFlags; + phase?: string | number; + pass?: string; + } + export interface IPassInfo extends IPassStates { + program: string; // auto-generated from 'vert' and 'frag' + embeddedMacros?: MacroRecord; + propertyIndex?: number; + switch?: string; + properties?: Record; + shader?: IShaderInfo; + } + export interface ITechniqueInfo { + passes: IPassInfo[]; + name?: string; + } + + export interface IBlockInfo { + binding: number; + name: string; + members: Uniform[]; + stageFlags: ShaderStageFlags; + } + export interface ISamplerTextureInfo { + binding: number; + name: string; + type: Type; + count: number; + stageFlags: ShaderStageFlags; + } + export interface ISamplerInfo { + set: number; + binding: number; + name: string; + count: number; + stageFlags: ShaderStageFlags; + } + export interface ITextureInfo { + set: number; + binding: number; + name: string; + type: Type; + count: number; + stageFlags: ShaderStageFlags; + } + export interface IBufferInfo { + binding: number; + name: string; + memoryAccess: MemoryAccess; + stageFlags: ShaderStageFlags; + } + export interface IImageInfo { + binding: number; + name: string; + type: Type; + count: number; + memoryAccess: MemoryAccess; + stageFlags: ShaderStageFlags; + } + + export interface IInputAttachmentInfo { + set: number; + binding: number; + name: string; + count: number; + stageFlags: ShaderStageFlags; + } + export interface IAttributeInfo { + name: string; + format: Format; + isNormalized: boolean; + stream: number; + isInstanced: boolean; + location: number; + defines: string[]; + } + export interface IDefineInfo { + name: string; + type: string; + range?: number[]; + options?: string[]; + default?: string; + } + export interface IBuiltin { + name: string; + defines: string[]; + binding?: number; + } + export interface IBuiltinInfo { + buffers: IBuiltin[]; + blocks: IBuiltin[]; + samplerTextures: IBuiltin[]; + images: IBuiltin[]; + } + export interface IDescriptorInfo { + rate: number; + blocks: IBlockInfo[]; + samplerTextures: ISamplerTextureInfo[]; + samplers: ISamplerInfo[]; + textures: ITextureInfo[]; + buffers: IBufferInfo[]; + images: IImageInfo[]; + subpassInputs: IInputAttachmentInfo[]; + } + export interface IShaderInfo { + name: string; + hash: number; + glsl4: { vert: string, frag: string, compute?: string }; + glsl3: { vert: string, frag: string, compute?: string }; + glsl1: { vert: string, frag: string }; + builtins: { globals: IBuiltinInfo, locals: IBuiltinInfo, statistics: Record }; + defines: IDefineInfo[]; + attributes: IAttributeInfo[]; + blocks: IBlockInfo[]; + samplerTextures: ISamplerTextureInfo[]; + samplers: ISamplerInfo[]; + textures: ITextureInfo[]; + buffers: IBufferInfo[]; + images: IImageInfo[]; + subpassInputs: IInputAttachmentInfo[]; + descriptors: IDescriptorInfo[]; + } + export interface IPreCompileInfo { + [name: string]: boolean[] | number[] | string[]; + } +} + // handle meta data, it is generated automatically patch_cc_EffectAsset({EffectAsset}) diff --git a/cocos/asset/assets/image-asset.jsb.ts b/cocos/asset/assets/image-asset.jsb.ts index c106cd333b..ce4fafaaeb 100644 --- a/cocos/asset/assets/image-asset.jsb.ts +++ b/cocos/asset/assets/image-asset.jsb.ts @@ -65,7 +65,8 @@ function isNativeImage (imageSource: ImageSource): imageSource is (HTMLImageElem return imageSource instanceof jsbWindow.HTMLImageElement || imageSource instanceof jsbWindow.HTMLCanvasElement || isImageBitmap(imageSource); } -const imageAssetProto = ImageAsset.prototype; +// TODO: we mark imageAssetProto as type of any, because here we have many dynamic injected property @dumganhar +const imageAssetProto: any = ImageAsset.prototype; imageAssetProto._ctor = function (nativeAsset?: ImageSource) { jsb.Asset.prototype._ctor.apply(this, arguments); diff --git a/cocos/asset/assets/image-asset.ts b/cocos/asset/assets/image-asset.ts index 44010ce519..d63132531d 100644 --- a/cocos/asset/assets/image-asset.ts +++ b/cocos/asset/assets/image-asset.ts @@ -478,7 +478,7 @@ export class ImageAsset extends Asset { * @zh 此图像资源的图像数据。 */ get data () { - if (this._nativeData && isNativeImage(this._nativeData)) { + if (isNativeImage(this._nativeData)) { return this._nativeData; } diff --git a/cocos/asset/assets/rendering-sub-mesh.jsb.ts b/cocos/asset/assets/rendering-sub-mesh.jsb.ts index 2dad3fe34c..99576bf15c 100644 --- a/cocos/asset/assets/rendering-sub-mesh.jsb.ts +++ b/cocos/asset/assets/rendering-sub-mesh.jsb.ts @@ -77,7 +77,8 @@ export interface IFlatBuffer { export type RenderingSubMesh = JsbRenderingSubMesh; export const RenderingSubMesh: typeof JsbRenderingSubMesh = jsb.RenderingSubMesh; -const renderingSubMeshProto = RenderingSubMesh.prototype; +// TODO: we mark renderingSubMeshProto as type of any, because here we have many dynamic injected property @dumganhar +const renderingSubMeshProto: any = RenderingSubMesh.prototype; renderingSubMeshProto._ctor = function (vertexBuffers: Buffer[], attributes: Attribute[], primitiveMode: PrimitiveMode, indexBuffer: Buffer | null = null, indirectBuffer: Buffer | null = null) { diff --git a/cocos/asset/assets/texture-2d.jsb.ts b/cocos/asset/assets/texture-2d.jsb.ts index 2be40500a9..6a9e74c30f 100644 --- a/cocos/asset/assets/texture-2d.jsb.ts +++ b/cocos/asset/assets/texture-2d.jsb.ts @@ -77,7 +77,8 @@ texture2DProto._serialize = function (ctxForExporting: any) { texture2DProto._deserialize = function (serializedData: any, handle: any) { const data = serializedData as ITexture2DSerializeData; - TextureBase.prototype._deserialize.call(this, data.base); + // NOTE: _deserialize expect 3 arguments + TextureBase.prototype._deserialize.call(this, data.base, undefined); this._mipmaps = new Array(data.mipmaps.length); for (let i = 0; i < data.mipmaps.length; ++i) { diff --git a/cocos/core/utils/js-typed.ts b/cocos/core/utils/js-typed.ts index 0cb880e42c..69ef0bf5de 100644 --- a/cocos/core/utils/js-typed.ts +++ b/cocos/core/utils/js-typed.ts @@ -141,7 +141,8 @@ export const getset = (() => { setter = undefined; } descriptor.get = getter; - descriptor.set = setter; + // TODO: on OH platform, strictNullCheck compiler option is false, so we need to force inferring as Setter type. @PP_Pro + descriptor.set = setter as Setter; descriptor.enumerable = enumerable; descriptor.configurable = configurable; Object.defineProperty(object, propertyName, descriptor); diff --git a/cocos/gfx/base/pipeline-sub-state.jsb.ts b/cocos/gfx/base/pipeline-sub-state.jsb.ts index e389031443..4ab1af2e55 100644 --- a/cocos/gfx/base/pipeline-sub-state.jsb.ts +++ b/cocos/gfx/base/pipeline-sub-state.jsb.ts @@ -551,8 +551,10 @@ export class BlendTarget { } export class BlendState { - private targets: BlendTarget[]; - private _blendColor: Color; + // NOTE: not initialize in constructor + public targets!: BlendTarget[]; + // NOTE: not initialize in constructor + private _blendColor!: Color; protected _nativeObj; protected _isA2C: boolean = false; protected _isIndepend: boolean = false; @@ -647,7 +649,8 @@ export class BlendState { for (let i = 0, len = this.targets.length; i < len; ++i) { this.targets[i].destroy(); } - this.targets = null; + // NOTE: Type 'null' is not assignable to type 'BlendTarget[]'. + this.targets = null as any; this._nativeObj = null; } } \ No newline at end of file diff --git a/cocos/gi/light-probe/delaunay.jsb.ts b/cocos/gi/light-probe/delaunay.jsb.ts index f5fc1255b5..b97e39b484 100644 --- a/cocos/gi/light-probe/delaunay.jsb.ts +++ b/cocos/gi/light-probe/delaunay.jsb.ts @@ -23,13 +23,18 @@ */ import { Mat3, Vec3, _decorator } from "../../core"; import { patch_cc_CircumSphere, patch_cc_Tetrahedron, patch_cc_Vertex } from "../../native-binding/decorators"; +import type { Vertex as JsbVertex, CircumSphere as JsbCircumSphere, Tetrahedron as JsbTetrahedron } from './delaunay'; +declare const jsb: any; -export const Vertex = jsb.Vertex; +export const Vertex: typeof JsbVertex = jsb.Vertex; +export type Vertex = JsbVertex; patch_cc_Vertex({Vertex, Vec3}); -export const CircumSphere = jsb.CircumSphere; +export const CircumSphere: typeof JsbCircumSphere = jsb.CircumSphere; +export type CircumSphere = JsbCircumSphere; patch_cc_CircumSphere({CircumSphere, Vec3}); -export const Tetrahedron = jsb.Tetrahedron; +export const Tetrahedron: typeof JsbTetrahedron = jsb.Tetrahedron; +export type Tetrahedron = JsbTetrahedron; patch_cc_Tetrahedron({Tetrahedron, Mat3, Vec3, CircumSphere}); \ No newline at end of file diff --git a/cocos/gi/light-probe/light-probe.jsb.ts b/cocos/gi/light-probe/light-probe.jsb.ts index 2106ab42e9..8e0849697d 100644 --- a/cocos/gi/light-probe/light-probe.jsb.ts +++ b/cocos/gi/light-probe/light-probe.jsb.ts @@ -24,13 +24,16 @@ import { _decorator } from '../../core'; import { patch_cc_LightProbesData } from '../../native-binding/decorators'; import { Tetrahedron, Vertex } from './delaunay'; +import type { LightProbes as JsbLightProbes, LightProbesData as JsbLightProbesData } from './light-probe'; - -export const LightProbes = jsb.LightProbes; +declare const jsb: any; +export const LightProbes: typeof JsbLightProbes = jsb.LightProbes; +export type LightProbes = JsbLightProbes; _decorator.ccclass('cc.LightProbes')(LightProbes); // patch_cc_LightProbes({LightProbes}); // not exists -export const LightProbesData = jsb.LightProbesData; +export const LightProbesData: typeof JsbLightProbesData = jsb.LightProbesData; +export type LightProbesData = JsbLightProbesData; patch_cc_LightProbesData({LightProbesData, Vertex, Tetrahedron}); diff --git a/cocos/render-scene/core/program-lib.jsb.ts b/cocos/render-scene/core/program-lib.jsb.ts index 80170504e8..60d1652df2 100644 --- a/cocos/render-scene/core/program-lib.jsb.ts +++ b/cocos/render-scene/core/program-lib.jsb.ts @@ -24,6 +24,11 @@ import { API, } from '../../gfx'; import { cclegacy } from '../../core'; +import type { EffectAsset } from '../../asset/assets/effect-asset'; +import type { Attribute, ShaderInfo, DescriptorSetLayout, DescriptorSetLayoutBinding, PipelineLayout } from '../../gfx'; +import type { IDefineRecord } from './program-lib'; + +declare const jsb: any; export interface ITemplateInfo { gfxAttributes: Attribute[]; diff --git a/cocos/render-scene/scene/index.jsb.ts b/cocos/render-scene/scene/index.jsb.ts index 540efc2de7..0449c70dcd 100644 --- a/cocos/render-scene/scene/index.jsb.ts +++ b/cocos/render-scene/scene/index.jsb.ts @@ -22,9 +22,12 @@ THE SOFTWARE. */ import { Vec3, Enum, cclegacy } from '../../core'; +import type { LODData as JsbLODData, LODGroup as JsbLODGroup } from './lod-group'; -export const LODData = jsb.LODData; -export const LODGroup = jsb.LODGroup; +export const LODData: typeof JsbLODData = jsb.LODData; +export type LODData = JsbLODData; +export const LODGroup: typeof JsbLODGroup = jsb.LODGroup; +export type LODGroup = JsbLODGroup; import type { Ambient as JsbAmbient, diff --git a/cocos/render-scene/scene/reflection-probe.jsb.ts b/cocos/render-scene/scene/reflection-probe.jsb.ts index 8dde3c081d..27824d8cad 100644 --- a/cocos/render-scene/scene/reflection-probe.jsb.ts +++ b/cocos/render-scene/scene/reflection-probe.jsb.ts @@ -23,6 +23,8 @@ */ import { ClearFlagBit } from '../../gfx'; import { SKYBOX_FLAG } from './camera'; +import type { ReflectionProbe as JsbReflectionProbe } from './reflection-probe'; + declare const jsb: any; export enum ProbeClearFlag { @@ -35,7 +37,8 @@ export enum ProbeType { PLANAR = 1, } -export const ReflectionProbe = jsb.ReflectionProbe; +export const ReflectionProbe: typeof JsbReflectionProbe = jsb.ReflectionProbe; +export type ReflectionProbe = JsbReflectionProbe; const reflectionProbeProto: any = jsb.ReflectionProbe.prototype; reflectionProbeProto._ctor = function (id:number) { this._probeId = id; diff --git a/cocos/render-scene/scene/submodel.jsb.ts b/cocos/render-scene/scene/submodel.jsb.ts index dc230d2e92..ca04d9ebcd 100644 --- a/cocos/render-scene/scene/submodel.jsb.ts +++ b/cocos/render-scene/scene/submodel.jsb.ts @@ -21,5 +21,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import type { SubModel as JsbSubModel } from './submodel'; -export const SubModel = jsb.SubModel; +declare const jsb: any; + +export type SubModel = JsbSubModel; +export const SubModel: typeof JsbSubModel = jsb.SubModel; diff --git a/cocos/rendering/geometry-renderer.jsb.ts b/cocos/rendering/geometry-renderer.jsb.ts index fd6f290310..be0b70c038 100644 --- a/cocos/rendering/geometry-renderer.jsb.ts +++ b/cocos/rendering/geometry-renderer.jsb.ts @@ -22,7 +22,11 @@ THE SOFTWARE. */ import { cclegacy } from '../core'; +import type { GeometryRenderer as JsbGeometryRenderer } from './geometry-renderer'; -export const GeometryRenderer = jsb.GeometryRenderer; +declare const jsb: any; + +export const GeometryRenderer: typeof JsbGeometryRenderer = jsb.GeometryRenderer; +export type GeometryRenderer = JsbGeometryRenderer; cclegacy.GeometryRenderer = jsb.GeometryRenderer; diff --git a/cocos/rendering/index.jsb.ts b/cocos/rendering/index.jsb.ts index 20a99057f5..01096229aa 100644 --- a/cocos/rendering/index.jsb.ts +++ b/cocos/rendering/index.jsb.ts @@ -25,34 +25,71 @@ declare const nr: any; declare const jsb: any; -import { getPhaseID } from './pass-phase'; import { ccenum, CCString, js } from '../core'; import * as pipeline from './define'; import { ccclass, serializable, editable, type } from '../core/data/class-decorator'; import { legacyCC } from '../core/global-exports'; import * as decors from '../native-binding/decorators'; +import { RenderTexture } from '../asset/assets/render-texture'; +import type { + RenderPipeline as NrRenderPipeline, + RenderFlow as NrRenderFlow, + RenderStage as NrRenderStage, + InstancedBuffer as NrInstancedBuffer, + PipelineStateManager as NrPipelineStateManager, + ForwardPipeline as NrForwardPipeline, + ForwardFlow as NrForwardFlow, + ShadowFlow as NrShadowFlow, + ForwardStage as NrForwardStage, + ShadowStage as NrShadowStage, + DeferredPipeline as NrDeferredPipeline, + MainFlow as NrMainFlow, + LightingStage as NrLightingStage, + PostProcessStage as NrPostProcessStage, + GbufferStage as NrGbufferStage, + BloomStage as NrBloomStage, + ReflectionProbeFlow as NrReflectionProbeFlow, + ReflectionProbeStage as NrReflectionProbeStage, +} from './index'; + export { pipeline }; - -nr.getPhaseID = getPhaseID; - -export const RenderPipeline = nr.RenderPipeline; -export const RenderFlow = nr.RenderFlow; -export const RenderStage = nr.RenderStage; -export const InstancedBuffer = nr.InstancedBuffer; -export const PipelineStateManager = nr.PipelineStateManager; -export const ForwardPipeline = nr.ForwardPipeline; -export const ForwardFlow = nr.ForwardFlow; -export const ShadowFlow = nr.ShadowFlow; -export const ForwardStage = nr.ForwardStage; -export const ShadowStage = nr.ShadowStage; -export const DeferredPipeline = nr.DeferredPipeline; -export const MainFlow = nr.MainFlow; -export const LightingStage = nr.LightingStage; -export const PostProcessStage = nr.PostProcessStage; -export const GbufferStage = nr.GbufferStage; -export const BloomStage = nr.BloomStage; -export const ReflectionProbeFlow = nr.ReflectionProbeFlow; -export const ReflectionProbeStage = nr.ReflectionProbeStage; +export * from './pass-phase'; +export const RenderPipeline: typeof NrRenderPipeline = nr.RenderPipeline; +export type RenderPipeline = NrRenderPipeline; +export const RenderFlow: typeof NrRenderFlow = nr.RenderFlow; +export type RenderFlow = NrRenderFlow; +export const RenderStage: typeof NrRenderStage = nr.RenderStage; +export type RenderStage = NrRenderStage; +export const InstancedBuffer: typeof NrInstancedBuffer = nr.InstancedBuffer; +export type InstancedBuffer = NrInstancedBuffer; +export const PipelineStateManager: typeof NrPipelineStateManager = nr.PipelineStateManager; +export type PipelineStateManager = NrPipelineStateManager; +export const ForwardPipeline: typeof NrForwardPipeline = nr.ForwardPipeline; +export type ForwardPipeline = NrForwardPipeline; +export const ForwardFlow: typeof NrForwardFlow = nr.ForwardFlow; +export type ForwardFlow = NrForwardFlow; +export const ShadowFlow: typeof NrShadowFlow = nr.ShadowFlow; +export type ShadowFlow = NrShadowFlow; +export const ForwardStage: typeof NrForwardStage = nr.ForwardStage; +export type ForwardStage = NrForwardStage; +export const ShadowStage: typeof NrShadowStage = nr.ShadowStage; +export type ShadowStage = NrShadowStage; +export const DeferredPipeline: typeof NrDeferredPipeline = nr.DeferredPipeline; +export type DeferredPipeline = NrDeferredPipeline; +export const MainFlow: typeof NrMainFlow = nr.MainFlow; +export type MainFlow = NrMainFlow; +export const LightingStage: typeof NrLightingStage = nr.LightingStage; +export type LightingStage = NrLightingStage; +export const PostProcessStage: typeof NrPostProcessStage = nr.PostProcessStage; +export type PostProcessStage = NrPostProcessStage; +export const GbufferStage: typeof NrGbufferStage = nr.GbufferStage; +export type GbufferStage = NrGbufferStage; +export const BloomStage: typeof NrBloomStage = nr.BloomStage; +export type BloomStage = NrBloomStage; +export const ReflectionProbeFlow: typeof NrReflectionProbeFlow = nr.ReflectionProbeFlow; +export type ReflectionProbeFlow = NrReflectionProbeFlow; +export const ReflectionProbeStage: typeof NrReflectionProbeStage = nr.ReflectionProbeStage; +export type ReflectionProbeStage = NrReflectionProbeStage; export { PipelineEventType } from './pipeline-event'; interface IRenderFlowInfo { @@ -79,7 +116,8 @@ nr.PipelineStateManager.getOrCreatePipelineState = function (device, pass, shade }; // ForwardPipeline -const forwardPipelineProto = ForwardPipeline.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const forwardPipelineProto: any = ForwardPipeline.prototype; forwardPipelineProto._ctor = function () { this._tag = 0; this._flows = []; @@ -104,7 +142,8 @@ forwardPipelineProto.onLoaded = function () { this.initialize(info); } -const forwardFlowProto = ForwardFlow.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const forwardFlowProto: any = ForwardFlow.prototype; forwardFlowProto._ctor = function () { this._name = 0; this._priority = 0; @@ -119,7 +158,8 @@ forwardFlowProto.init = function (pipeline) { this.initialize(info); } -const shadowFlowProto = ShadowFlow.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const shadowFlowProto: any = ShadowFlow.prototype; shadowFlowProto._ctor = function () { this._name = 0; this._priority = 0; @@ -134,7 +174,9 @@ shadowFlowProto.init = function (pipeline) { this.initialize(info); } -const reflectionProbeFlowProto = ReflectionProbeFlow.prototype; + +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const reflectionProbeFlowProto: any = ReflectionProbeFlow.prototype; reflectionProbeFlowProto._ctor = function () { this._name = 0; this._priority = 0; @@ -149,7 +191,9 @@ reflectionProbeFlowProto.init = function (pipeline) { this.initialize(info); } -const forwardStageProto = ForwardStage.prototype; + +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const forwardStageProto: any = ForwardStage.prototype; forwardStageProto._ctor = function () { this._name = 0; this._priority = 0; @@ -166,14 +210,17 @@ forwardStageProto.init = function (pipeline) { this.initialize(info); } -const shadowStageProto = ShadowStage.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const shadowStageProto: any = ShadowStage.prototype; shadowStageProto._ctor = function () { this._name = 0; this._priority = 0; this._tag = 0; } -const reflectionProbeStage = ReflectionProbeStage.prototype; + +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const reflectionProbeStage: any = ReflectionProbeStage.prototype; reflectionProbeStage._ctor = function () { this._name = 0; this._priority = 0; @@ -235,7 +282,8 @@ export class RenderQueueDesc { } } -const deferredPipelineProto = DeferredPipeline.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const deferredPipelineProto: any = DeferredPipeline.prototype; deferredPipelineProto._ctor = function () { this._tag = 0; this._flows = []; @@ -255,7 +303,9 @@ deferredPipelineProto.onLoaded = function () { this.initialize(info); } -const mainFlowProto = MainFlow.prototype; + +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const mainFlowProto: any = MainFlow.prototype; mainFlowProto._ctor = function () { this._name = 0; this._priority = 0; @@ -270,7 +320,8 @@ mainFlowProto.init = function (pipeline) { this.initialize(info); } -const gbufferStageProto = GbufferStage.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const gbufferStageProto: any = GbufferStage.prototype; gbufferStageProto._ctor = function () { this._name = 0; this._priority = 0; @@ -287,8 +338,8 @@ gbufferStageProto.init = function (pipeline) { this.initialize(info); } - -const lightingStageProto = LightingStage.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const lightingStageProto: any = LightingStage.prototype; lightingStageProto._ctor = function () { this._name = 0; this._priority = 0; @@ -307,7 +358,8 @@ lightingStageProto.init = function (pipeline) { this.initialize(info); } -const bloomStageProto = BloomStage.prototype; +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const bloomStageProto: any = BloomStage.prototype; bloomStageProto._ctor = function () { this._name = 0; this._priority = 0; @@ -326,7 +378,9 @@ bloomStageProto.init = function (pipeline) { this.initialize(info); } -const postProcessStageProto = PostProcessStage.prototype; + +// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar +const postProcessStageProto: any = PostProcessStage.prototype; postProcessStageProto._ctor = function () { this._name = 0; this._priority = 0; @@ -350,8 +404,6 @@ legacyCC.RenderFlow = RenderFlow; legacyCC.RenderStage = RenderStage; legacyCC.RenderPipeline = RenderPipeline; - -const RenderTexture: any = jsb.RenderTexture; @ccclass('RenderTextureConfig') class RenderTextureConfig { @serializable diff --git a/cocos/rendering/pass-phase.jsb.ts b/cocos/rendering/pass-phase.jsb.ts deleted file mode 100644 index 8af6dcacaf..0000000000 --- a/cocos/rendering/pass-phase.jsb.ts +++ /dev/null @@ -1,27 +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. -*/ - -declare const nr: any; - -export const getPhaseID = nr.getPhaseID; diff --git a/cocos/rendering/render-pipeline.jsb.ts b/cocos/rendering/render-pipeline.jsb.ts index ef548dafca..be43772d10 100644 --- a/cocos/rendering/render-pipeline.jsb.ts +++ b/cocos/rendering/render-pipeline.jsb.ts @@ -23,6 +23,18 @@ */ import { cclegacy } from '../core'; -export const RenderPipeline = nr.RenderPipeline; +import { RenderPipeline as NrRenderPipeline } from './render-pipeline'; +import { Buffer, InputAssembler } from '../gfx'; + +declare const nr: any; + +export const RenderPipeline: typeof NrRenderPipeline = nr.RenderPipeline; +export type RenderPipeline = NrRenderPipeline; // Do not delete, for the class detection of editor cclegacy.RenderPipeline = RenderPipeline; + +export class PipelineInputAssemblerData { + quadIB: Buffer|null = null; + quadVB: Buffer|null = null; + quadIA: InputAssembler|null = null; +} diff --git a/cocos/rendering/render-stage.jsb.ts b/cocos/rendering/render-stage.jsb.ts index 937994e78a..f45bfcc2a4 100644 --- a/cocos/rendering/render-stage.jsb.ts +++ b/cocos/rendering/render-stage.jsb.ts @@ -25,6 +25,20 @@ declare var nr:any; import { legacyCC } from '../core/global-exports'; -export const RenderStage = nr.RenderStage; +import type { RenderStage as NrRenderStage } from './render-stage'; +import type { RenderQueueDesc } from './pipeline-serialization'; +export const RenderStage: typeof NrRenderStage = nr.RenderStage; +export type RenderStage = NrRenderStage; // Do not delete, for the class detection of editor legacyCC.RenderStage = RenderStage; + +/** + * @en The render stage information descriptor + * @zh 渲染阶段描述信息。 + */ +export interface IRenderStageInfo { + name: string; + priority: number; + tag?: number; + renderQueues?: RenderQueueDesc[]; +} \ No newline at end of file diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index 1cc503cd69..b8589e5c43 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -188,7 +188,8 @@ nodeProto.addComponent = function (typeOrClassName) { // check requirement - const ReqComp = (constructor)._requireComponent; + // TODO: `_requireComponent` is injected properties + const ReqComp = (constructor as any)._requireComponent; if (ReqComp && !this.getComponent(ReqComp)) { this.addComponent(ReqComp); } @@ -1271,7 +1272,9 @@ nodeProto._instantiate = function (cloned: Node, isSyncedNode: boolean) { cloned = legacyCC.instantiate._clone(this, this); } - const newPrefabInfo = cloned._prefab; + // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. + // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 + const newPrefabInfo = (cloned as any)._prefab; if (EDITOR && newPrefabInfo) { if (cloned === newPrefabInfo.root) { // newPrefabInfo.fileId = ''; diff --git a/cocos/scene-graph/scene-globals.jsb.ts b/cocos/scene-graph/scene-globals.jsb.ts index 470348a621..51061ce5ac 100644 --- a/cocos/scene-graph/scene-globals.jsb.ts +++ b/cocos/scene-graph/scene-globals.jsb.ts @@ -28,6 +28,17 @@ import { Ambient, EnvironmentLightingType } from '../render-scene/scene'; import { Material } from '../asset/assets/material'; import { Vec2, Vec3, Color, Vec4 } from '../core/math'; import * as decros from '../native-binding/decorators'; +import type { + AmbientInfo as JsbAmbientInfo, + SkyboxInfo as JsbSkyboxInfo, + FogInfo as JsbFogInfo, + ShadowsInfo as JsbShadowsInfo, + OctreeInfo as JsbOctreeInfo, + SceneGlobals as JsbSceneGlobals, + LightProbeInfo as JsbLightProbeInfo, +} from './scene-globals'; + +declare const jsb: any; export const DEFAULT_WORLD_MIN_POS = new Vec3(-1024.0, -1024.0, -1024.0); export const DEFAULT_WORLD_MAX_POS = new Vec3(1024.0, 1024.0, 1024.0); @@ -135,34 +146,34 @@ export const ShadowType = Enum({ ShadowMap: 1, }); -// @ts-ignore -export const AmbientInfo = jsb.AmbientInfo; +export const AmbientInfo: typeof JsbAmbientInfo = jsb.AmbientInfo; +export type AmbientInfo = JsbAmbientInfo; legacyCC.AmbientInfo = AmbientInfo; -// @ts-ignore -export const SkyboxInfo = jsb.SkyboxInfo; +export const SkyboxInfo: typeof JsbSkyboxInfo = jsb.SkyboxInfo; +export type SkyboxInfo = JsbSkyboxInfo; legacyCC.SkyboxInfo = SkyboxInfo; -// @ts-ignore -export const FogInfo = jsb.FogInfo; +export const FogInfo: typeof JsbFogInfo = jsb.FogInfo; +export type FogInfo = JsbFogInfo; legacyCC.FogInfo = FogInfo; FogInfo.FogType = FogType; -// @ts-ignore -export const ShadowsInfo = jsb.ShadowsInfo; +export const ShadowsInfo: typeof JsbShadowsInfo = jsb.ShadowsInfo; +export type ShadowsInfo = JsbShadowsInfo; legacyCC.ShadowsInfo = ShadowsInfo; -// @ts-ignore -export const OctreeInfo = jsb.OctreeInfo; +export const OctreeInfo: typeof JsbOctreeInfo = jsb.OctreeInfo; +export type OctreeInfo = JsbOctreeInfo; legacyCC.OctreeInfo = OctreeInfo; -// @ts-ignore -export const LightProbeInfo = jsb.LightProbeInfo; +export const LightProbeInfo: typeof JsbLightProbeInfo = jsb.LightProbeInfo; +export type LightProbeInfo = JsbLightProbeInfo; //legacyCC.LightProbeInfo = LightProbeInfo; -// @ts-ignore -export const SceneGlobals = jsb.SceneGlobals; +export const SceneGlobals: typeof JsbSceneGlobals = jsb.SceneGlobals; +export type SceneGlobals = JsbSceneGlobals; legacyCC.SceneGlobals = SceneGlobals; (function () { @@ -266,7 +277,7 @@ legacyCC.SceneGlobals = SceneGlobals; // handle meta data, it is generated automatically -decros.patch_cc_SceneGlobals({SceneGlobals, AmbientInfo, SkyboxInfo, FogInfo, ShadowsInfo, LightProbeInfo, OctreeInfo, LightProbeInfo}); +decros.patch_cc_SceneGlobals({SceneGlobals, AmbientInfo, SkyboxInfo, FogInfo, ShadowsInfo, LightProbeInfo, OctreeInfo}); decros.patch_cc_OctreeInfo({OctreeInfo, CCInteger, Vec3, DEFAULT_WORLD_MAX_POS, DEFAULT_WORLD_MIN_POS, DEFAULT_OCTREE_DEPTH}); diff --git a/cocos/serialization/deserialize-dynamic.ts b/cocos/serialization/deserialize-dynamic.ts index ee97148d00..f7185405aa 100644 --- a/cocos/serialization/deserialize-dynamic.ts +++ b/cocos/serialization/deserialize-dynamic.ts @@ -477,7 +477,8 @@ class _Deserializer { case 'TypedArrayRef': return this._deserializeTypedArrayViewRef(serialized); default: - if (serialized.__type__) { // Typed object (including CCClass) + // NOTE: when 'strictNullCheck' is false, TS can't infer serialized as SerializedGeneralTypedObject + if ((serialized as unknown as SerializedGeneralTypedObject).__type__) { // Typed object (including CCClass) return this._deserializeTypeTaggedObject(serialized, globalIndex, owner, propName); } else if (!Array.isArray(serialized)) { // Embedded primitive javascript object return this._deserializePlainObject(serialized); diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index ab7027f93b..2420ad71b5 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -36,7 +36,7 @@ import { BlendFactor } from '../../gfx'; import { legacyCC } from '../../core/global-exports'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; import { RenderData } from '../../2d/renderer/render-data'; -import { Texture2D } from '../../../typedoc-index.js'; +import { Texture2D } from '../../asset/assets/texture-2d'; import { director } from '../../game'; const _quadTriangles = [0, 1, 2, 2, 3, 0]; diff --git a/pal/audio/native/player.ts b/pal/audio/native/player.ts index 439ac8c707..95bac930a9 100644 --- a/pal/audio/native/player.ts +++ b/pal/audio/native/player.ts @@ -23,7 +23,7 @@ */ import { systemInfo } from 'pal/system-info'; -import { AudioType, AudioState, AudioEvent, AudioPCMDataView, AudioBufferView } from '../type'; +import { AudioType, AudioState, AudioEvent, AudioPCMDataView, AudioBufferView, AudioLoadOptions } from '../type'; import { EventTarget } from '../../../cocos/core/event'; import { legacyCC } from '../../../cocos/core/global-exports'; import { clamp, clamp01 } from '../../../cocos/core'; @@ -157,14 +157,14 @@ export class AudioPlayer implements OperationQueueable { }).catch((e) => {}); } } - static load (url: string): Promise { + static load (url: string, opts?: AudioLoadOptions): Promise { return new Promise((resolve, reject) => { - AudioPlayer.loadNative(url).then((url) => { + AudioPlayer.loadNative(url, opts).then((url) => { resolve(new AudioPlayer(url as string)); }).catch((err) => reject(err)); }); } - static loadNative (url: string): Promise { + static loadNative (url: string, opts?: AudioLoadOptions): Promise { return new Promise((resolve, reject) => { if (systemInfo.platform === Platform.WIN32) { // NOTE: audioEngine.preload() not works well on Win32 platform. @@ -184,9 +184,9 @@ export class AudioPlayer implements OperationQueueable { } }); } - static loadOneShotAudio (url: string, volume: number): Promise { + static loadOneShotAudio (url: string, volume: number, opts?: AudioLoadOptions): Promise { return new Promise((resolve, reject) => { - AudioPlayer.loadNative(url).then((url) => { + AudioPlayer.loadNative(url, opts).then((url) => { // HACK: AudioPlayer should be a friend class in OneShotAudio resolve(new (OneShotAudio as any)(url, volume)); }).catch(reject); diff --git a/pal/input/native/accelerometer-input.ts b/pal/input/native/accelerometer-input.ts index b155b63a58..c9a23e75e1 100644 --- a/pal/input/native/accelerometer-input.ts +++ b/pal/input/native/accelerometer-input.ts @@ -22,7 +22,6 @@ THE SOFTWARE. */ -import { AccelerometerCallback } from 'pal/input'; import { systemInfo } from 'pal/system-info'; import { screenAdapter } from 'pal/screen-adapter'; import { EventTarget } from '../../../cocos/core/event'; @@ -31,6 +30,8 @@ import { Orientation } from '../../screen-adapter/enum-type'; import { Acceleration, EventAcceleration } from '../../../cocos/input/types'; import { InputEventType } from '../../../cocos/input/types/event-enum'; +export type AccelerometerCallback = (res: EventAcceleration) => void; + export class AccelerometerInputSource { private _intervalInSeconds = 0.2; private _intervalId? :number; diff --git a/pal/input/native/gamepad-input.ts b/pal/input/native/gamepad-input.ts index 1e78920254..5001ea103e 100644 --- a/pal/input/native/gamepad-input.ts +++ b/pal/input/native/gamepad-input.ts @@ -23,7 +23,6 @@ */ /* eslint-disable brace-style */ -import { GamepadCallback } from 'pal/input'; import { systemInfo } from 'pal/system-info'; import { InputEventType } from '../../../cocos/input/types/event-enum'; import { Feature } from '../../system-info/enum-type'; @@ -32,6 +31,8 @@ import { EventGamepad } from '../../../cocos/input/types'; import { InputSourceButton, InputSourceDpad, InputSourceStick } from '../input-source'; import { js } from '../../../cocos/core'; +export type GamepadCallback = (res: EventGamepad) => void; + enum Button { BUTTON_SOUTH, BUTTON_EAST, diff --git a/pal/input/native/handheld-input.ts b/pal/input/native/handheld-input.ts index 09fddd0e60..4fdc6b0675 100644 --- a/pal/input/native/handheld-input.ts +++ b/pal/input/native/handheld-input.ts @@ -22,13 +22,14 @@ THE SOFTWARE. */ -import { HandheldCallback } from 'pal/input'; import { InputEventType } from '../../../cocos/input/types/event-enum'; import { EventTarget } from '../../../cocos/core/event/event-target'; import { EventHandheld } from '../../../cocos/input/types'; import { InputSourcePosition, InputSourceOrientation } from '../input-source'; import { Vec3, Quat } from '../../../cocos/core/math'; +export type HandheldCallback = (res: EventHandheld) => void; + enum Pose { AR_MOBILE, } diff --git a/pal/input/native/handle-input.ts b/pal/input/native/handle-input.ts index 4cf04bdbfe..fed98fc407 100644 --- a/pal/input/native/handle-input.ts +++ b/pal/input/native/handle-input.ts @@ -22,13 +22,14 @@ THE SOFTWARE. */ -import { HandleCallback } from 'pal/input'; import { InputEventType } from '../../../cocos/input/types/event-enum'; import { EventTarget } from '../../../cocos/core/event/event-target'; import { EventHandle } from '../../../cocos/input/types'; import { InputSourceButton, InputSourceStick, InputSourcePosition, InputSourceOrientation } from '../input-source'; import { Vec3, Quat } from '../../../cocos/core/math'; +export type HandleCallback = (res: EventHandle) => void; + enum Button { BUTTON_EAST, BUTTON_SOUTH, diff --git a/pal/input/native/hmd-input.ts b/pal/input/native/hmd-input.ts index 918efe307f..897114ab7f 100644 --- a/pal/input/native/hmd-input.ts +++ b/pal/input/native/hmd-input.ts @@ -22,13 +22,14 @@ THE SOFTWARE. */ -import { HMDCallback } from 'pal/input'; import { InputEventType } from '../../../cocos/input/types/event-enum'; import { EventTarget } from '../../../cocos/core/event/event-target'; import { EventHMD } from '../../../cocos/input/types'; import { InputSourcePosition, InputSourceOrientation } from '../input-source'; import { Vec3, Quat } from '../../../cocos/core/math'; +export type HMDCallback = (res: EventHMD) => void; + enum Pose { VIEW_LEFT, VIEW_RIGHT, diff --git a/pal/input/native/keyboard-input.ts b/pal/input/native/keyboard-input.ts index 956e204046..e99712c200 100644 --- a/pal/input/native/keyboard-input.ts +++ b/pal/input/native/keyboard-input.ts @@ -22,12 +22,13 @@ THE SOFTWARE. */ -import { KeyboardCallback } from 'pal/input'; import { systemInfo } from 'pal/system-info'; import { KeyCode, EventKeyboard } from '../../../cocos/input/types'; import { EventTarget } from '../../../cocos/core/event'; import { InputEventType } from '../../../cocos/input/types/event-enum'; +export type KeyboardCallback = (res: EventKeyboard) => void; + const nativeKeyCode2KeyCode: Record = { 12: KeyCode.NUM_LOCK, 10048: KeyCode.NUM_0, diff --git a/pal/input/native/mouse-input.ts b/pal/input/native/mouse-input.ts index d282ffe6c4..1ccd64b5f7 100644 --- a/pal/input/native/mouse-input.ts +++ b/pal/input/native/mouse-input.ts @@ -22,13 +22,14 @@ THE SOFTWARE. */ -import { MouseCallback } from 'pal/input'; import { screenAdapter } from 'pal/screen-adapter'; import { EventMouse } from '../../../cocos/input/types'; import { EventTarget } from '../../../cocos/core/event'; import { Vec2 } from '../../../cocos/core/math'; import { InputEventType } from '../../../cocos/input/types/event-enum'; +export type MouseCallback = (res: EventMouse) => void; + declare const jsb: any; export class MouseInputSource { diff --git a/pal/input/native/touch-input.ts b/pal/input/native/touch-input.ts index 04cd2d81b6..aeb1d539b8 100644 --- a/pal/input/native/touch-input.ts +++ b/pal/input/native/touch-input.ts @@ -22,7 +22,6 @@ THE SOFTWARE. */ -import { TouchCallback } from 'pal/input'; import { screenAdapter } from 'pal/screen-adapter'; import { Size, Vec2 } from '../../../cocos/core/math'; import { EventTarget } from '../../../cocos/core/event'; @@ -31,6 +30,8 @@ import { touchManager } from '../touch-manager'; import { macro } from '../../../cocos/core/platform/macro'; import { InputEventType } from '../../../cocos/input/types/event-enum'; +export type TouchCallback = (res: EventTouch) => void; + declare const jsb: any; export class TouchInputSource { diff --git a/pal/minigame/non-minigame.ts b/pal/minigame/non-minigame.ts index 66af9b987f..01053d21fc 100644 --- a/pal/minigame/non-minigame.ts +++ b/pal/minigame/non-minigame.ts @@ -22,7 +22,5 @@ THE SOFTWARE. */ -import { IMiniGame } from 'pal/minigame'; - -const minigame: IMiniGame = {} as IMiniGame; +const minigame: any = {}; export { minigame }; diff --git a/pal/minigame/taobao_minigame.ts b/pal/minigame/taobao_minigame.ts index c80f19a6a2..e2cb492975 100644 --- a/pal/minigame/taobao_minigame.ts +++ b/pal/minigame/taobao_minigame.ts @@ -37,8 +37,7 @@ const languageMap: Record = { declare let my: any; -// @ts-expect-error can't init minigame when it's declared -const minigame: IMiniGame = {}; +const minigame: IMiniGame = {} as IMiniGame; cloneObject(minigame, my); // #region SystemInfo @@ -75,17 +74,15 @@ Object.defineProperty(minigame, 'orientation', { }); // #endregion SystemInfo -// @ts-expect-error TODO: move into minigame.d.ts -minigame.isSupportLandscape = function () { +function detectLandscapeSupport () { const locSysInfo = minigame.getSystemInfoSync(); if (typeof locSysInfo.deviceOrientation === 'string' && locSysInfo.deviceOrientation.startsWith('landscape')) { if (versionCompare(locSysInfo.version, '10.15.10') < 0) { console.warn('The current Taobao client version does not support Landscape, the minimum requirement is 10.15.10'); } } -}; -// @ts-expect-error TODO: Check whether the landscape screen is supported -minigame.isSupportLandscape(); +} +detectLandscapeSupport(); // #region Audio const polyfilledCreateInnerAudio = createInnerAudioContextPolyfill(my, { @@ -95,12 +92,12 @@ const polyfilledCreateInnerAudio = createInnerAudioContextPolyfill(my, { onSeek: false, }, true); minigame.createInnerAudioContext = function (): InnerAudioContext { - const audio: InnerAudioContext = polyfilledCreateInnerAudio(); - // @ts-expect-error InnerAudioContext has onCanPlay + // NOTE: `onCanPlay` is not standard minigame interface, + // so here we mark audio as type of any + const audio: any = polyfilledCreateInnerAudio(); audio.onCanplay = audio.onCanPlay.bind(audio); - // @ts-expect-error InnerAudioContext has onCanPlay delete audio.onCanPlay; - return audio; + return audio as InnerAudioContext; }; // #region Audio @@ -173,9 +170,10 @@ minigame.getSafeArea = function () { }; // #endregion SafeArea +declare const $global: any; // global variable on Taobao platform. + // TODO: A filpY operation will be performed after ReadPixels on Taobao. if (!my.isIDE) { - // @ts-expect-error canvas defined in global const locCanvas = $global.screencanvas; if (locCanvas) { const originalGetContext = locCanvas.getContext.bind(locCanvas); diff --git a/pal/screen-adapter/native/screen-adapter.ts b/pal/screen-adapter/native/screen-adapter.ts index 2ca644b907..0ec2675d22 100644 --- a/pal/screen-adapter/native/screen-adapter.ts +++ b/pal/screen-adapter/native/screen-adapter.ts @@ -23,11 +23,35 @@ */ import { EDITOR } from 'internal:constants'; -import { ConfigOrientation, IScreenOptions, SafeAreaEdge } from 'pal/screen-adapter'; import { EventTarget } from '../../../cocos/core/event/event-target'; import { Size } from '../../../cocos/core/math'; import { Orientation } from '../enum-type'; +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; +} + // these value is defined in the native layer const orientationMap: Record = { 0: Orientation.PORTRAIT, @@ -54,10 +78,10 @@ class ScreenAdapter extends EventTarget { public get windowSize (): Size { const dpr = this.devicePixelRatio; // NOTE: fix precision issue on Metal render end. - // @ts-expect-error interface for OH only - const width = globalThis.oh ? jsb.device.getInnerWidth() : jsb.window.innerWidth; - // @ts-expect-error interface for OH only - const height = globalThis.oh ? jsb.device.getInnerHeight() : jsb.window.innerHeight; + // TODO: interface for OH only, we need a unified interface @qiuguohua + const width = globalThis.oh ? (jsb.device as any).getInnerWidth() : jsb.window.innerWidth; + // TODO: interface for OH only, we need a unified interface @qiuguohua + const height = globalThis.oh ? (jsb.device as any).getInnerHeight() : jsb.window.innerHeight; // NOTE: fix precision issue on Metal render end. const roundWidth = Math.round(width); const roundHeight = Math.round(height); diff --git a/pal/system-info/native/system-info.ts b/pal/system-info/native/system-info.ts index 6445587f2b..65234d9a24 100644 --- a/pal/system-info/native/system-info.ts +++ b/pal/system-info/native/system-info.ts @@ -22,10 +22,13 @@ THE SOFTWARE. */ -import { IFeatureMap } from 'pal/system-info'; import { EventTarget } from '../../../cocos/core/event'; import { BrowserType, NetworkType, OS, Platform, Language, Feature } from '../enum-type'; +type IFeatureMap = { + [feature in Feature]: boolean; +}; + // NOTE: these methods are implemented on native. declare function __getPlatform(): string; declare function __getCurrentLanguageCode(): string;