forked from goplus/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools/spxls): implement spx resource reference check
Updates goplus#1059 Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
- Loading branch information
Showing
2 changed files
with
282 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/fs" | ||
) | ||
|
||
// SpxSpriteResource represents a spx sprite resource. | ||
type SpxSpriteResource struct { | ||
Name string `json:"name"` | ||
Costumes []SpxSpriteCostumeResource `json:"costumes"` | ||
CostumeIndex int `json:"costumeIndex"` | ||
Animations []SpxSpriteAnimationResource `json:"fAnimations"` | ||
DefaultAnimation string `json:"defaultAnimation"` | ||
} | ||
|
||
// SpxSpriteCostumeResource represents a spx sprite costume resource. | ||
type SpxSpriteCostumeResource struct { | ||
Index int `json:"index"` | ||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
} | ||
|
||
// SpxSpriteAnimationResource represents a spx sprite animation resource. | ||
type SpxSpriteAnimationResource struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
// getSpxSpriteResource gets a spx sprite resource from the workspace. | ||
func (s *Server) getSpxSpriteResource(name string) (*SpxSpriteResource, error) { | ||
metadata, err := fs.ReadFile(s.workspaceRootFS, fmt.Sprintf("assets/sprites/%s/index.json", name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
sprite := SpxSpriteResource{Name: name} | ||
if err := json.Unmarshal(metadata, &sprite); err != nil { | ||
return nil, err | ||
} | ||
return &sprite, nil | ||
} | ||
|
||
// SpxSoundResource represents a sound resource in spx. | ||
type SpxSoundResource struct { | ||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
} | ||
|
||
// getSpxSoundResource gets a spx sound resource from the workspace. | ||
func (s *Server) getSpxSoundResource(name string) (*SpxSoundResource, error) { | ||
metadata, err := fs.ReadFile(s.workspaceRootFS, fmt.Sprintf("assets/sounds/%s/index.json", name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
sound := SpxSoundResource{Name: name} | ||
if err := json.Unmarshal(metadata, &sound); err != nil { | ||
return nil, err | ||
} | ||
return &sound, nil | ||
} |