-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:SpriteAtlas Adaptation Editor Workflow (#461)
* feat:SpriteAtlas Adaptation Editor Workflow
- Loading branch information
1 parent
b1ff2ce
commit df843e8
Showing
6 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/loader/src/scene-loader/resources/SpriteAtlasResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { AssetType, ResourceManager, SpriteAtlas } from "@oasis-engine/core"; | ||
import { AssetConfig } from "../types"; | ||
import { getAllGetters } from "../utils"; | ||
import { SchemaResource } from "./SchemaResource"; | ||
import { SpriteResource } from "./SpriteResource"; | ||
|
||
export class SpriteAtlasResource extends SchemaResource { | ||
static defaultAtlas: SpriteAtlas; | ||
|
||
load(resourceManager: ResourceManager, assetConfig: AssetConfig): Promise<SpriteAtlasResource> { | ||
return new Promise((resolve) => { | ||
this.setMeta(); | ||
if (assetConfig.source) { | ||
resourceManager | ||
.load<SpriteAtlas>({ | ||
url: assetConfig.source, | ||
type: AssetType.SpriteAtlas | ||
}) | ||
.then((spriteAtlas) => { | ||
this._resource = spriteAtlas; | ||
const { sprites } = spriteAtlas; | ||
const schemaResourceManager = this.resourceManager; | ||
for (let index = sprites.length - 1; index >= 0; index--) { | ||
const sprite = sprites[index]; | ||
const spriteResource = new SpriteResource(schemaResourceManager, sprite); | ||
// @ts-ignore | ||
const assetID = sprite._assetID; | ||
// @ts-ignore | ||
schemaResourceManager.maxId = Math.max(assetID, schemaResourceManager.maxId); | ||
// @ts-ignore | ||
schemaResourceManager.resourceMap[assetID] = spriteResource; | ||
// @ts-ignore | ||
schemaResourceManager.resourceIdMap.set(spriteResource, "" + assetID); | ||
} | ||
resolve(this); | ||
}); | ||
} else { | ||
if (!SpriteAtlasResource.defaultAtlas) { | ||
SpriteAtlasResource.defaultAtlas = new SpriteAtlas(resourceManager.engine); | ||
} | ||
this._resource = SpriteAtlasResource.defaultAtlas; | ||
resolve(this); | ||
} | ||
}); | ||
} | ||
|
||
setMeta() { | ||
if (this.resource) { | ||
this.meta.name = this.resource.name; | ||
} | ||
} | ||
|
||
getProps() { | ||
const result = {}; | ||
const props = getAllGetters(this.resource); | ||
props.forEach((prop) => (result[prop] = this.resource[prop])); | ||
return result; | ||
} | ||
|
||
update() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters