Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-assets

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Load asset URL textures, atlases and BMFont with AssetBank. Use for refcounted disposal, extension selection, cache reuse or AIR_E_ATLAS_IN_USE/AIR_E_FNT_IN_USE cleanup.

  • 10 files
  • 88.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-assets

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescontracts.md

≈3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-assets skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Contracts

  • There is no Editor asset pipeline. resources resolves by symbol name on the default bundle face, but the export is a bare new Bundle() (src/cocos/asset/asset-manager/bundle.ts:655); assetManager.resources (src/cocos/asset/asset-manager/asset-manager.ts:369-370) and assetManager.getBundle(name) (:482-483) read the module-level bundles cache (src/cocos/asset/asset-manager/shared.ts:35), which the manager also exposes as public bundles (src/cocos/asset/asset-manager/asset-manager.ts:162), and only a Creator-format config puts anything in it (src/cocos/asset/asset-manager/factory.ts:84 maps the name resources onto that singleton). With nothing registered the getter is null, so loadAssetAsync skips the bundle branch entirely (src/air/utils/load-asset.ts:47-48); if you do hand it an unconfigured bundle, Bundle.load rejects through Bundle ${item.bundle} doesn't contain ${item.path} (src/cocos/asset/asset-manager/url-transformer.ts:106) and loadAssetAsync swallows that rejection and falls through to the registry (src/air/utils/load-asset.ts:49-57). Bundle, Config, PackManager, Variant and Cache are not export names on the default face, so a bundle instance is only reachable through assetManager.getBundle(...) and assetManager.assets is a plain string-keyed map (src/cocos/asset/asset-manager/cache.ts:184-189, get :206, has :225, remove :244).
  • loadAssetAsync (src/air/utils/load-asset.ts:32 typed overload, :38 url overload, :39 implementation) resolves in a fixed order: glTF when type === GLTFAsset or the path is .gltf/.glb (:40-43), then the resources bundle when present (:47-51), then the registry assetManager.assets.get(path) gated on cached instanceof type (:60-62), then a registry hit keyed by path before anything is fetched. With a type and no hit it throws [cocosair] loadAssetAsync: '<path>' not found. Register it via assetManager.assets.add('<path>', asset), or set up a resources bundle. (:64). Without a type it fetches and engine-deserializes, falling back to JSON.parse when the payload is not serialized (:68-77), and a non-2xx response throws [cocosair] loadAssetAsync failed: <url> (<status>) (:70). Both message shapes are the contract recorded at docs/manual/asset-loading-and-lifetime.md:20, :22.
  • The registry is a cache, not a guard. assetManager.assets.add(key, asset) silently overwrites an existing key (src/cocos/asset/asset-manager/cache.ts:184-189), a destroy() only takes effect at the end of the frame, and a destroyed asset stays reachable through its key until you remove it - loadAssetAsync(path, type) will hand back the dead instance (docs/manual/asset-loading-and-lifetime.md:26-34, items 1 through 5). Same-key reload therefore requires the sequence remove(key) -> rebuild -> add(key) -> loadAssetAsync, and every consumer must call isValid(asset) after a load (examples/ui-asset-loading/src/main.ts runs exactly that round-trip and is bound to the asset-loaded validator).
  • loadRemote is a method, not an import: neither load nor loadRemote nor loadAny appears as an export name, so reach them as assetManager.loadRemote(url, optionsOrExt?, onComplete?) (src/cocos/asset/asset-manager/asset-manager.ts:649-651). Its first statement is the URL-keyed short circuit: when reloadAsset is falsy and assets.has(url) it returns the cached asset immediately (:654-656), which is how a destroyed AudioClip or texture comes back after destroy() alone - examples/audio-basic/main.js:523-530 documents exactly that recovery, and the fix is assetManager.releaseAsset(asset) (src/cocos/asset/asset-manager/asset-manager.ts:754-755, which runs releaseManager.tryRelease(asset, true)). AssetBank sidesteps the trap by always sending reloadAsset: true with an explicit ext (src/air/assets/asset-bank.ts:362).
  • AssetBank (src/air/assets/asset-bank.ts:146, re-exported at src/air/ui-kit.ts:142) is a Promise wrapper with reference counting, not a second asset system: load (:173), release (:264), refCount (:160), inFlightCount (:157), size (:154), releaseAll (:288) and the hard-coded static underlyingCancelSupported = false (:148) are the whole public surface, and the generic T on load is a caller assertion the bank never checks (:9). The cache key is url alone or `${url}|ext=${ext.toLowerCase()}` (:80-82, lower-cased once at :175), so ext is part of identity and the same URL under two ext values is two entries.
  • ext rules are strict: it must match /^[a-zA-Z0-9]{1,16}$/ or AIR_E_INVALID_EXT throws (:77, :94), and a URL with no suffix requires an explicit ext or AIR_E_EXT_REQUIRED throws (:85-90, :100). The value reaches the engine as .${ext} with reloadAsset: true (:362); a suffix-only URL keeps the native cache path (:365). signal cancels the subscription only - the waiter is removed from the shared in-flight record (:318), the network request still completes, and an orphaned late result is balanced with a net-zero addRef/decRef pair (:391-398). Progress is honestly two-phase, onProgress(0, 1) at subscribe and (1, 1) at settle (:328, :406), because loadRemote exposes no task-level progress at all (:144). A cache hit is delivered in a microtask (:212, rationale :188), so a same-tick abort or release wins and refunds only that subscription (:193-207).
  • The AIR_E_* codes are typed but not importable: AirAssetErrorCode is the union at src/air/assets/asset-bank.ts:61-67 and AirAssetError the class at :70, both re-exported from src/air/ui-kit.ts:143 as types only, so neither name resolves in the default bundle export block and you match on err.code. Throw sites: AIR_E_ABORTED at :183, :207, :225, :320, :414 via :428; AIR_E_PROGRESS_ERROR at :220, :332, :408; AIR_E_REVOKED at :301, :229, :414; AIR_E_LOAD_FAILED at :386 with the shared body at :425-428. release never force-releases (:258-263), and releaseAll revokes in-flight waiters under an identity guard so a late callback cannot delete a newer same-key record (:290-302, :349).
  • A runtime texture is two objects. ImageAsset (src/cocos/asset/assets/image-asset.ts:182) describes CPU pixels and accepts HTMLCanvasElement | HTMLImageElement | IMemoryImageSource | ImageBitmap through reset (:670, :154); Texture2D (src/cocos/asset/assets/texture-2d.ts:85) is the GPU sampler. texture.image = img is mipmaps = [img] and clears every other level (:161-163, :150-155); reset(info) leaves the gfx resource invalid until you uploadData (:192-202, src/cocos/asset/assets/simple-texture.ts:151). There is no generateMipmaps method - levels come from updateMipmaps(firstLevel, count) (src/cocos/asset/assets/texture-2d.ts:232) and from create-time generation only when the mip filter is not NONE (src/cocos/asset/assets/simple-texture.ts:325-329), and the power-of-two test is skipped on WebGL2 (:47-51). Sampling is setWrapMode/setFilters/setMipFilter/setAnisotropy on TextureBase (src/cocos/asset/assets/texture-base.ts:205, :226, :242, :256), whose serialized wrap defaults are REPEAT (:122, :128, :134) - docs/manual/textures.md:33 claims CLAMP_TO_EDGE and is stale. Over-size is a soft log, not a throw (errorID(9100...) at src/cocos/gfx/webgl2/webgl2-commands.ts:931-933), against capabilities.maxTextureSize (src/cocos/gfx/webgl/webgl-device.ts:180).
  • SpriteFrame binding is untracked. Sprite's spriteFrame setter and its _applySpriteFrame never call addRef() or decRef() (src/cocos/2d/components/sprite.ts:207-218, :691), and Label.font does the same for a BitmapFont (src/cocos/2d/components/label.ts:466-487), so a bound component is invisible to every handle guard in this skill. Ref before you bind and unref after you unbind (docs/manual/atlas-loading.md:42, docs/manual/bitmap-font-loading.md:37), and expect AIR_E_ATLAS_IN_USE (src/air/assets/atlas/atlas-factory.ts:106 - frame.refCount > 1) or AIR_E_FNT_IN_USE (src/air/assets/bmfont.ts:123) when you forget.
  • libGDX atlases: parseAtlasText(text) (src/air/assets/atlas/atlas-parser.ts:143) accepts the legacy (xy + size, orig + offset) and compact (bounds, offsets) dialects and rejects mixing them, unknown keys, and Creator .plist input (:213-264). rect keeps xy with top-left origin and no page flip (src/air/assets/atlas/atlas-factory.ts:46, ruling recorded at :7-9 and docs/manual/atlas-loading.md:35), rotation stays a rotated flag rather than a rect change (:43), and the engine consumes rect as UV directly (src/cocos/2d/assets/sprite-frame.ts:1038, :1088). createAtlasHandle takes exactly one reference per page texture and per frame (src/air/assets/atlas/atlas-factory.ts:89-90) and destroys everything it built if any region fails (:85-88); loadAtlas is PNG-only on the auto path (src/air/assets/atlas/atlas-loader.ts:48, :53, :57) and indexes page loads by pageIndex so completion order cannot reorder textures (:89, :96-107).
  • BMFont: parseFnt (src/air/assets/bmfont.ts:36) is text-dialect only - XML and binary input throws AIR_E_FNT_FORMAT (:37) - and enforces pages=1, page id=0, char page=0 and unpacked (:63, :64, :73), so a multi-page or packed font never reaches the factory. createBitmapFont (:104) demands a full unrotated page matching scaleW/scaleH on both the frame rect and the texture (:105-109), else AIR_E_FNT_PAGE_TEXTURE (:110); a trimmed sub-rectangle cannot be a font page. loadBitmapFont (:132) loads the .fnt and one .png through a caller-supplied AssetBank, and the assembler picks the bmfont path whenever comp.font instanceof BitmapFont before cacheMode is consulted (src/cocos/2d/assembler/label/index.ts:34-40), which makes cacheMode effectively inert for a BMFont label (src/cocos/2d/components/label.ts:489-495).
  • Keep the three capability layers apart. assetManager, AssetManager, resources, loadAssetAsync, AssetBank, Texture2D, ImageAsset, SpriteFrame, SpriteAtlas, BitmapFont, Font, Asset, TextAsset, JsonAsset, EffectAsset, parseFnt, createBitmapFont, loadBitmapFont, parseAtlasText, createAtlasHandle, createAtlasSpriteFrame, loadAtlas and isValid each resolve by symbol name in the single export { ... } block of build/cocosair.module.js; load, loadRemote, loadAny, Bundle, PackManager, Config, Variant, Cache, SimpleTexture, TextureBase, AirAssetError and AirAssetErrorCode do not, so those last two are compile-time-only shapes. Browser-verified at candidate fingerprint 2f089f6ce25eaccd: ui-asset-loading binds loadAssetAsync, ImageAsset, Texture2D and SpriteFrame.createWithImage to asset-loaded and AssetManager.releaseAsset plus Texture2D.destroy to resource-released; texture-basic binds ImageAsset/Texture2D to material-property; static-model binds loadAssetAsync to scene-ready only; texture2d-ops binds twelve Texture2D members to no-runtime-error alone with reads = 0, so it proves the calls do not throw, not that pixels are correct. No results[] entry binds AssetBank, loadRemote, any atlas function or any bitmap-font function, and docs/evidence/port-gap/eg3-installed-atlas-s11.json (gate EG3, execution.status: PASS, scope.subset: true, completed: false) is the only tracked atlas record - docs/manual/asset-bank-loading.md:5 states its own jsdom boundary too.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "load remote files without a Creator resources bundle",
  "the same URL returns a destroyed asset",
  "create a texture from canvas or pixel data",
  "load a sprite atlas or bitmap font",
  "an atlas or font handle refuses to dispose"
]
owns
[
  "asset-bank",
  "asset-cache",
  "reference-counting",
  "texture2d",
  "atlas",
  "bmfont"
]
not_for
[
  "glTF or GLB model loading -> cocosair-gltf",
  "bind an existing font to Label -> cocosair-ui-2d",
  "live HTML textures and DOM -> cocosair-graphics-and-dom"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "管理远程资产、AssetBank 引用计数、纹理、图集和位图字体。用于加载、缓存、取消、共享资源释放或字体导入问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-assets