Skip to content

Commit

Permalink
chore: modify files according to the specification
Browse files Browse the repository at this point in the history
  • Loading branch information
TuGitee committed Feb 6, 2024
1 parent d4952da commit 5558fc0
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @Date: 2024-01-22 10:28:03
* @LastEditors: TuGitee [email protected]
* @LastEditTime: 2024-01-25 15:03:08
* @FilePath: \builder\spx-gui\src\class\AssetBase.ts
* @FilePath: \builder\spx-gui\src\class\asset-base.ts
* @Description: The abstract class of an asset.
*/
import type { assetBase } from "@/interface/file";
import type { AssetBaseInterface } from "@/interface/file";
import { getStorage } from "@/util/class";
import FileWithUrl from "@/class/FileWithUrl";
import { isObjectEmpty } from "@/util/global";
Expand All @@ -19,7 +19,7 @@ import type { Config } from '@/interface/file';
* @author tgb
* @createDate 2024-01-18
*/
export default abstract class AssetBase implements assetBase {
export abstract class AssetBase implements AssetBaseInterface {
protected _files: FileWithUrl[];
public name: string;
public abstract config: Config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AssetBase from "./AssetBase";
import Sound from "./sound";
import Sprite from "./sprite";
import { AssetBase } from "./asset-base";
import { Sound } from "./sound";
import { Sprite } from "./sprite";

export abstract class AssetList<T extends AssetBase> {
public list: T[] = [];
Expand Down
11 changes: 6 additions & 5 deletions spx-gui/src/class/backdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* @Description: The class of a backdrop.
*/
import type { BackdropConfig, Scene } from "@/interface/file";
import AssetBase from "./AssetBase";
import { AssetBase } from "./asset-base";
import { isInstance, getAllFromLocal } from "@/util/class";
import type { rawFile } from "@/types/file";
import type { RawDir } from "@/types/file";
import { useProjectStore } from "@/store/modules/project";

/**
* @class Backdrop
Expand Down Expand Up @@ -46,7 +47,7 @@ import type { rawFile } from "@/types/file";
* backdrop.config = backdrop.genDefualtConfig()
*/

export default class Backdrop extends AssetBase {
export class Backdrop extends AssetBase {
/**
* The root path of the backdrop.
*/
Expand Down Expand Up @@ -120,7 +121,7 @@ export default class Backdrop extends AssetBase {
"name": file.name.split(".")[0],
"path": file.name
})),
"zorder": [],
"zorder": useProjectStore().project?.sprite.list.map(sprite => sprite.name) || [],
"sceneIndex": 0
}
}
Expand Down Expand Up @@ -165,7 +166,7 @@ export default class Backdrop extends AssetBase {
* Get the directory of the backdrop.
*/
get dir() {
const dir: Record<string, rawFile> = {}
const dir: RawDir = {}
dir[`${this.path}index.json`] = this.config
for (const file of this.files) {
dir[`${this.path}${file.name}`] = file
Expand Down
8 changes: 4 additions & 4 deletions spx-gui/src/class/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @FilePath: \builder\spx-gui\src\class\sound.ts
* @Description: The class of a sound.
*/
import AssetBase from "./AssetBase";
import { AssetBase } from "./asset-base";
import { isInstance, getAllFromLocal } from "@/util/class";
import type { rawFile } from "@/types/file";
import type { RawDir } from "@/types/file";
import type { SoundConfig } from '@/interface/file';

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ import type { SoundConfig } from '@/interface/file';
* snd1.config = snd1.genDefualtConfig()
*/

export default class Sound extends AssetBase {
export class Sound extends AssetBase {
/**
* The root path of the sounds.
*/
Expand Down Expand Up @@ -128,7 +128,7 @@ export default class Sound extends AssetBase {
* Get the directory of the sound.
*/
get dir() {
const dir: Record<string, rawFile> = {}
const dir: RawDir = {}
dir[`${this.path}/index.json`] = this.config
for (const file of this.files) {
dir[`${this.path}/${file.name}`] = file
Expand Down
8 changes: 4 additions & 4 deletions spx-gui/src/class/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import type { Costume, SpriteConfig } from "@/interface/file";
import AssetBase from "./AssetBase";
import { AssetBase } from "./asset-base";
import { isInstance, getAllFromLocal } from "@/util/class";
import type { rawFile } from "@/types/file";
import type { RawDir } from "@/types/file";

/**
* @class Sprite
Expand Down Expand Up @@ -57,7 +57,7 @@ import type { rawFile } from "@/types/file";
* spt1.config = spt1.genDefualtConfig()
*/

export default class Sprite extends AssetBase {
export class Sprite extends AssetBase {
/**
* The root path of the sprites.
*/
Expand Down Expand Up @@ -263,7 +263,7 @@ export default class Sprite extends AssetBase {
* Get the directory of the sprite.
*/
get dir() {
const dir: Record<string, rawFile> = {}
const dir: RawDir = {}
dir[`${this.path}/index.json`] = this.config
for (const file of this.files) {
dir[`${this.path}/${file.name}`] = file
Expand Down
6 changes: 3 additions & 3 deletions spx-gui/src/interface/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
*/

import FileWithUrl from "@/class/FileWithUrl";
import type { rawFile } from "@/types/file";
import type { RawDir } from "@/types/file";

/**
* file interface
*/
export interface assetBase {
export interface AssetBaseInterface {
files: FileWithUrl[];
config: Config;
dir?: Record<string, rawFile>;
dir?: RawDir;
path?: string;

/**
Expand Down
28 changes: 14 additions & 14 deletions spx-gui/src/store/modules/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import { ref, watch } from 'vue'
import { defineStore } from 'pinia'
import * as fs from '@/util/FileSystem'
import type { FileType, dirPath, rawDir } from "@/types/file";
import * as fs from '@/util/file-system'
import type { FileType, DirPath, RawDir } from "@/types/file";
import { convertDirPathToProject, convertRawDirToDirPath, convertRawDirToZip, getDirPathFromZip } from "@/util/file";
import saveAs from "file-saver";
import { SoundList, SpriteList } from "@/class/AssetList";
import Backdrop from '@/class/backdrop';
import { SoundList, SpriteList } from "@/class/asset-list";
import { Backdrop } from '@/class/backdrop';

const UNTITLED_NAME = 'Untitled'
interface ProjectData {
Expand All @@ -23,7 +23,7 @@ interface ProjectData {
sound: SoundList
backdrop: Backdrop
entryCode: string
UnidentifiedFile: rawDir
UnidentifiedFile: RawDir
}

export class Project implements ProjectData {
Expand All @@ -32,15 +32,15 @@ export class Project implements ProjectData {
sound: SoundList;
backdrop: Backdrop;
entryCode: string;
UnidentifiedFile: rawDir;
UnidentifiedFile: RawDir;

static ENTRY_FILE_NAME = 'index.gmx'

static fromRawData(data: ProjectData): Project {
return new Project(data.title, data.sprite, data.sound, data.backdrop, data.entryCode, data.UnidentifiedFile)
}

constructor(title: string, sprite: SpriteList = new SpriteList(), sound: SoundList = new SoundList(), backdrop: Backdrop = new Backdrop(), entryCode: string = "", UnidentifiedFile: rawDir = {}) {
constructor(title: string, sprite: SpriteList = new SpriteList(), sound: SoundList = new SoundList(), backdrop: Backdrop = new Backdrop(), entryCode: string = "", UnidentifiedFile: RawDir = {}) {
this.title = title
this.sprite = sprite
this.sound = sound
Expand All @@ -66,7 +66,7 @@ export class Project implements ProjectData {
async load(arg: string | File, title?: string): Promise<void> {
if (typeof arg === 'string') {
const paths = await fs.readdir(arg) as string[]
const dirPath: dirPath = {}
const dirPath: DirPath = {}
for (const path of paths) {
const content = await fs.readFile(path) as FileType
dirPath[path] = content
Expand All @@ -80,17 +80,17 @@ export class Project implements ProjectData {

/**
* Load project from directory.
* @param dirPath The directory
* @param DirPath The directory
*/
private _load(dirPath: dirPath): void;
private _load(dirPath: DirPath): void;

/**
* Load project.
* @param proj The project
*/
private _load(proj: Project): void;

private _load(arg: dirPath | Project): void {
private _load(arg: DirPath | Project): void {
if (typeof arg === 'object' && arg instanceof Project) {
this.title = arg.title
this.sprite = arg.sprite
Expand Down Expand Up @@ -126,8 +126,8 @@ export class Project implements ProjectData {
}

get rawDir() {
const dir: rawDir = {}
const files: rawDir = Object.assign({}, this.UnidentifiedFile, ...[this.backdrop, ...this.sprite.list, ...this.sound.list].map(item => item.dir))
const dir: RawDir = {}
const files: RawDir = Object.assign({}, this.UnidentifiedFile, ...[this.backdrop, ...this.sprite.list, ...this.sound.list].map(item => item.dir))
files[Project.ENTRY_FILE_NAME] = this.entryCode
for (const [path, value] of Object.entries(files)) {
const fullPath = this.path + path
Expand All @@ -136,7 +136,7 @@ export class Project implements ProjectData {
return dir
}

get dirPath(): Promise<dirPath> {
get dirPath(): Promise<DirPath> {
return convertRawDirToDirPath(this.rawDir)
}
}
Expand Down
29 changes: 4 additions & 25 deletions spx-gui/src/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,8 @@
* @Description: The type of file.
*/

import Sprite from "@/class/sprite"
import Sound from "@/class/sound"
import Backdrop from "@/class/backdrop"
import type { Config } from "@/interface/file"

export type codeType = {
path: string,
content: string
}

export interface projectType {
title: string,
sprites: Sprite[],
sounds: Sound[],
backdrop: Backdrop,
defaultDir: dirPath,
code: codeType
}

export interface FileType {
content: ArrayBuffer,
path: string,
Expand All @@ -34,16 +17,12 @@ export interface FileType {
modifyTime: Date
}

export interface dirPath {
export interface DirPath {
[path: string]: FileType
}

export type rawFile = string | File | Config

export interface rawDir {
[path: string]: rawFile
}
export type RawFile = string | File | Config

export interface directory {
[path: string]: File
export interface RawDir {
[path: string]: RawFile
}
2 changes: 1 addition & 1 deletion spx-gui/src/util/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @Description: The util of class.
*/

import AssetBase from "@/class/AssetBase";
import { AssetBase } from "@/class/asset-base";
import localforage from "localforage";

/**
Expand Down
File renamed without changes.
Loading

0 comments on commit 5558fc0

Please sign in to comment.