PROJECT LINCTRA

鏈次元(內測版)

Object資源的Catalog

catalog.js 是 Object 資源的核心配置文件,用來設定物品資訊、圖片、擺放規則、自訂屬性結構與執行入口。Object 不只包括可擺放家具,也包括錢包等背包物品;是否可擺放與是否有 Runtime 是兩回事。

objectCatalog 屬性字典

文件位於 assets/object/{id}/catalog.js,必須以 export const objectCatalog 匯出配置物件。

  • id:物品資源的識別碼。由資源目錄名稱決定,例如 assets/object/bakery-display-case/catalog.js 的 id 是 bakery-display-case。同一包中的 Object id 應保持唯一,與 label 不同;更改目錄名稱後需同步更新引用。它也不是具體物品實例的 id。
  • packId:所屬資源包的識別碼。目前測試階段,在提交資源包時申請,同一包內的資源共用此 packId。主系統按載入來源提供它,不需在 objectCatalog 中另填 id 或 packId。
  • 引用物品時需同時區分資源包與物品,例如 packId: 'basepack' 與 itemKey: 'bakery-display-case';具體欄位名稱以調用接口為準。

下表按配置層級排列,預設全部展開;點擊父欄位旁的減號可收合,加號可重新展開。縮排與由深到淺的底色區分層級。類型使用英文,代碼示例使用當層的「欄位名: 值」寫法;[actionKey] 等自訂 key 以具體名稱示範。

缺省值以未套用分類預設時的解析結果為基準。主系統先套用 category 預設,再合併資源配置;物件逐層合併,一般陣列整組替換,customFields 按 key 合併:同名欄位覆寫指定屬性,新欄位追加到分類的欄位定義之後。「—」表示沒有自動提供的項目,{} 表示空配置,子欄位仍各自套用預設。

屬性類型缺省值代碼示例用途
labelstring''label: '烘培櫃'物品顯示名稱。
descriptionstring''description: '烘培展示櫃'物品簡述。
categorystring''category: 'furniture'選用分類預設。
keywordsstring[][]keywords: ['bakery', 'furniture']搜尋關鍵字;去空及去重。
resourcesobject{}resources: { runtime: './runtime.js' }資源路徑,以當前物品目錄為基準。
runtimestring''runtime: './runtime.js'Runtime 模組文件路徑。
imagesRecord<string, string>{}images: { base: './base.png', placed: './placed.png' }圖片角色到路徑的映射。
basestring—base: './base.png'清單與背包縮圖。
placedstring—placed: './placed.png'擺放到地圖時的圖片。
[role]string—detail: './detail.png'其他圖片角色;需另接使用流程。
inventoryobject{}inventory: { stackable: true, maxStack: 9999, unique: false }持有與堆疊規則,不是物品列表。
stackablebooleanfalsestackable: truetrue 表示允許堆疊。
maxStacknumber1maxStack: 9999每疊數量上限;正整數。
uniquebooleanfalseunique: true同一持有範圍的唯一性標記。
placementobject{}placement: { surface: ['floor'], snapToGrid: true }擺放表面與圖層配置。
surfacestring[][]surface: ['floor', 'support']允許表面:floor、support、wall。
snapToGridbooleanfalsesnapToGrid: true是否對齊格子。
layerstring''layer: 'overlay'繪製圖層;解析轉為小寫。
footprintobject{}footprint: { size: [2, 2] }占格與放置檢查配置。
size[number, number][1, 1]size: [2, 2]占格 [寬, 高];正整數,單位為格。
anchorTiles[number, number][][]anchorTiles: [[0, 1], [1, 1]]放置表面檢查使用的錨點格。
solidTiles[number, number][][]solidTiles: [[0, 1], [1, 1]]物品的實體阻擋格。
isFormbooleanfalseisForm: true表單型物品標記。
isKeybooleanfalseisKey: true金鑰型物品標記。
isContainerbooleanfalseisContainer: true容器物品標記。
isWalletbooleanfalseisWallet: true錢包物品標記。
walletobject{}wallet: { providerKind: 'ledger-readonly' }錢包專用配置;僅在 isWallet 啟用時使用,不會自行推導錢包標記。
providerKindstring''providerKind: 'ledger-readonly'錢包提供者類型。
supportedChainsstring[][]supportedChains: ['Ethereum', 'Polygon']錢包支援鏈列表;解析後為 chainList。crypto-address 使用 customFields 中 chains 的 default 固定值,不使用 wallet。
defaultWhitelistTokensobject[][]defaultWhitelistTokens: [{ symbol: 'ETH', chainName: 'Ethereum' }]錢包的預設代幣清單。
defaultWhitelistNftCollectionsobject[][]defaultWhitelistNftCollections: [{ symbol: 'BAYC', chainName: 'Ethereum' }]錢包的預設 NFT 集合清單。
customFieldsobject[][]customFields: [{ key: 'fontPreset', type: 'string', options: [{ value: 'kaishu', label: '楷體' }], default: 'kaishu' }]自訂屬性結構;房間編輯器中 string 可用 options 宣告下拉選項,或用 multiline 宣告段落;boolean 使用開關,number 使用數字框,range 可指定 [min, max] 或 [min, step, max] 並加上滑桿,不與獨立的 min/max/step 混用,詳見共用規約。
runtimeobject{}runtime: { actions: {} }執行入口配置,不是模組路徑。
actionsRecord<string, object>{}actions: { inspect: { handler: 'handleInspect' } }物品動作配置映射。
[actionKey]object—inspect: { handler: 'handleInspect' }單一動作配置。
handlerstring—handler: 'handleInspect'匯出函式名稱;必填且非空。
paramsRecord<string, object>{}params: { targetId: { required: true } }動作引數規則,不是實際值。
[paramKey]object—targetId: { required: true }單一引數規則。
requiredbooleanfalserequired: true引數必填標記;只解析 true。
itemMenusRecord<string, string>{}itemMenus: { inspect: '查看物品' }背包物品動作的選單文字。
[actionKey]string—inspect: '查看物品'對應 actions 的選單名稱;非空。
assetWindowsRecord<string, object>{}assetWindows: { networkSettings: { region: 'showcasePanel', module: './windows/network-settings-window.js', exportName: 'createLedgerReadonlyNetworkSettingsWindow' } }資源自訂視窗配置。
[windowKey]object—networkSettings: { region: 'showcasePanel', module: './windows/network-settings-window.js', exportName: 'createLedgerReadonlyNetworkSettingsWindow' }單一視窗描述。
regionstring—region: 'showcasePanel'目標面板區域;必填且非空。
modulestring—module: './windows/network-settings-window.js'視窗模組路徑;必填且非空。
exportNamestring—exportName: 'createLedgerReadonlyNetworkSettingsWindow'視窗工廠匯出名稱;必填且非空。
servicesRecord<string, string>{}services: { connectWallet: 'connectWallet' }核心服務 key 到匯出函式的映射。
[serviceKey]string—connectWallet: 'connectWallet'服務函式匯出名稱;非空。
menusRecord<string, string>{}menus: { inspect: 'handleInspectMenu' }選單函式入口映射。
[menuKey]string—inspect: 'handleInspectMenu'選單函式匯出名稱;非空。
hooksRecord<string, string>{}hooks: { onFrame: 'handleFrame' }Hook 入口映射;需對應調用流程。
[hookKey]string—onFrame: 'handleFrame'Hook 函式匯出名稱;非空。

命名與調用:資源開發者可以自行命名 actions、itemMenus、assetWindows、menus、hooks 的 key,並設計對應的觸發與調用流程。services 接入核心服務,其 key 必須符合Assets Service 白名單與契約;對應的 Runtime 匯出函式名稱仍可自行命名。itemMenus 的值是顯示文字,menus 的值則是函式名稱,不能混用。

customFields 定義結構與預設值,不是物品實例的即時資料。錢包等分類會提供共用欄位,資源的定義會接在其後;業務欄位名稱由資源自行決定,本頁不逐項列出。

自訂圖片的繪製區域由物品 Runtime 自行定義,例如掛畫在 Runtime 中使用 IMAGE_SLOT 常量;它不是 Catalog 屬性。功能標記也需配合對應系統流程;unique 不是全平台唯一 id。

配置片段與補充說明

placement 與 placement.footprint

placement: {
  surface: ['floor', 'support'],
  snapToGrid: true,
  layer: '',
  footprint: {
    size: [2, 2],
    anchorTiles: [[0, 1], [1, 1]],
    solidTiles: [[0, 1], [1, 1]]
  }
}

這段示範占 2×2 格的家具,下方兩格為錨點與實體阻擋格。placement.footprint.size 是 [寬, 高],單位為格;未提供時為 [1, 1]。格子座標是從 0 起算的物品局部 [欄, 列],不是地圖座標。anchorTiles 用於檢查放置表面,未提供時放置流程使用占格範圍;它與 solidTiles 的用途不同。

furniture 分類預設允許 floor、對齊格子,並允許堆疊至 9999。上例的 surface 會整組替換分類預設,額外允許 support。錢包分類沒有擺放表面;即使有 placement.footprint,也不代表可以擺放到地圖。占格配置統一寫在 placement 中,不再使用頂層 footprint 或 w、h。

runtime.actions、itemMenus 與 assetWindows

runtime: {
  actions: {
    'wallet-ledger-readonly-set-network': {
      handler: 'openSetNetworkAction'
    }
  },
  itemMenus: {
    'wallet-ledger-readonly-set-network': '設置網絡'
  },
  assetWindows: {
    networkSettings: {
      region: 'showcasePanel',
      module: './windows/network-settings-window.js',
      exportName: 'createLedgerReadonlyNetworkSettingsWindow'
    }
  },
  services: {
    connectWallet: 'connectWallet',
    loadTokenBalances: 'loadTokenBalances',
    updateWalletConnectedAccounts: 'updateWalletConnectedAccounts'
  }
}

這段取自 Ledger 只讀錢包:itemMenus 與 actions 使用相同動作 key;動作函式再調用開窗流程,assetWindows 不會自行顯示。視窗模組路徑相對於物品目錄,工廠函式必須存在於指定模組中。

視窗解析也接受 modulePath 作為 module 的別名,以及 factory、createWindow 作為 exportName 的別名;新配置建議統一使用 module 與 exportName。region、module、exportName 任一缺少非空值時,該視窗不會保留。動作 handler 為空時也會排除該動作。

crypto-wallet 分類預設為錢包、不可堆疊且 inventory.unique 為 true;資源可以明確覆寫,例如 Ledger 只讀錢包設定 inventory: { unique: false }。wallet 內的支援鏈、預設代幣與 NFT 清單只提供配置,不會單靠宣告就完成鏈或資產的接入;isWallet: false 時不使用 wallet 配置。四個錢包配置屬性不再支援根層寫法。Catalog adapter 仍輸出既有的 chainList、providerKind 與兩個白名單 metadata 欄位,供執行流程使用。

inventory.unique 表示同一持有範圍不能重複持有;目前錢包連結流程會一起檢查背包、主副手快捷欄及其中的巢狀容器。本次欄位整理不新增其他取得入口的唯一性檢查,也不改變既有比對方式。

家具與錢包的完整使用例子見Object資源;入口契約見Object Action介紹與Assets Service介紹。