Skip to content

Commit 6009f5e

Browse files
committed
Moved core ecs and asset code to their own sub module.
1 parent c79d8ae commit 6009f5e

39 files changed

+1568
-1231
lines changed

pkg/asset-mtl.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ package axe
33
import (
44
"regexp"
55

6+
"github.com/axe/axe-go/pkg/asset"
67
"github.com/udhos/gwob"
78
)
89

9-
var _ AssetFormat = &MtlFormat{}
10+
var _ asset.Format = &MtlFormat{}
1011
var mtlFormatRegex, _ = regexp.Compile(`\.mtl$`)
1112

1213
type MtlFormat struct {
1314
}
1415

15-
func (format *MtlFormat) Handles(ref AssetRef) bool {
16+
func (format *MtlFormat) Handles(ref asset.Ref) bool {
1617
return mtlFormatRegex.MatchString(ref.URI)
1718
}
1819

19-
func (format *MtlFormat) Types() []AssetType {
20-
return []AssetType{AssetTypeModel}
20+
func (format *MtlFormat) Types() []asset.Type {
21+
return []asset.Type{asset.TypeModel}
2122
}
2223

23-
func (format *MtlFormat) Load(asset *Asset) error {
24-
lib, err := gwob.ReadMaterialLibFromReader(asset.SourceReader, &gwob.ObjParserOptions{})
24+
func (format *MtlFormat) Load(a *asset.Asset) error {
25+
lib, err := gwob.ReadMaterialLibFromReader(a.SourceReader, &gwob.ObjParserOptions{})
2526

2627
if err != nil {
27-
asset.LoadStatus.Fail(err)
28+
a.LoadStatus.Fail(err)
2829
return err
2930
}
3031

3132
materials := Materials{}
32-
asset.Dependent = make([]AssetRef, 0)
33+
a.Dependent = make([]asset.Ref, 0)
3334

3435
for materialName, material := range lib.Lib {
3536
mat := Material{
@@ -57,39 +58,39 @@ func (format *MtlFormat) Load(asset *Asset) error {
5758
}
5859

5960
if mat.Ambient.Texture != "" {
60-
asset.AddNext(mat.Ambient.Texture, true)
61+
a.AddNext(mat.Ambient.Texture, true)
6162
}
6263
if mat.Specular.Texture != "" {
63-
asset.AddNext(mat.Specular.Texture, true)
64+
a.AddNext(mat.Specular.Texture, true)
6465
}
6566
if mat.Diffuse.Texture != "" {
66-
asset.AddNext(mat.Diffuse.Texture, true)
67+
a.AddNext(mat.Diffuse.Texture, true)
6768
}
6869
if mat.Emissive.Texture != "" {
69-
asset.AddNext(mat.Emissive.Texture, true)
70+
a.AddNext(mat.Emissive.Texture, true)
7071
}
7172
if mat.TextureBump != "" {
72-
asset.AddNext(mat.TextureBump, true)
73+
a.AddNext(mat.TextureBump, true)
7374
}
7475

7576
materials[materialName] = mat
7677
}
7778

78-
asset.Data = materials
79-
asset.LoadStatus.Success()
79+
a.Data = materials
80+
a.LoadStatus.Success()
8081

8182
return nil
8283
}
8384

84-
func (format *MtlFormat) Unload(asset *Asset) error {
85+
func (format *MtlFormat) Unload(asset *asset.Asset) error {
8586
asset.LoadStatus.Reset()
8687
return nil
8788
}
88-
func (format *MtlFormat) Activate(asset *Asset) error {
89+
func (format *MtlFormat) Activate(asset *asset.Asset) error {
8990
asset.ActivateStatus.Success()
9091
return nil
9192
}
92-
func (format *MtlFormat) Deactivate(asset *Asset) error {
93+
func (format *MtlFormat) Deactivate(asset *asset.Asset) error {
9394
asset.ActivateStatus.Reset()
9495
return nil
9596
}

pkg/asset-obj.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@ package axe
33
import (
44
"regexp"
55

6+
"github.com/axe/axe-go/pkg/asset"
67
"github.com/udhos/gwob"
78
)
89

9-
var _ AssetFormat = &ObjFormat{}
10+
var _ asset.Format = &ObjFormat{}
1011
var objFormatRegex, _ = regexp.Compile(`\.obj$`)
1112

1213
type ObjFormat struct {
1314
}
1415

15-
func (format *ObjFormat) Handles(ref AssetRef) bool {
16+
func (format *ObjFormat) Handles(ref asset.Ref) bool {
1617
return objFormatRegex.MatchString(ref.URI)
1718
}
1819

19-
func (format *ObjFormat) Types() []AssetType {
20-
return []AssetType{AssetTypeModel}
20+
func (format *ObjFormat) Types() []asset.Type {
21+
return []asset.Type{asset.TypeModel}
2122
}
2223

23-
func (format *ObjFormat) Load(asset *Asset) error {
24+
func (format *ObjFormat) Load(asset *asset.Asset) error {
2425
obj, err := gwob.NewObjFromReader(asset.Ref.Name, asset.SourceReader, nil)
2526
if err != nil {
2627
asset.LoadStatus.Fail(err)
@@ -116,15 +117,15 @@ func (format *ObjFormat) Load(asset *Asset) error {
116117
return nil
117118
}
118119

119-
func (format *ObjFormat) Unload(asset *Asset) error {
120+
func (format *ObjFormat) Unload(asset *asset.Asset) error {
120121
asset.LoadStatus.Reset()
121122
return nil
122123
}
123-
func (format *ObjFormat) Activate(asset *Asset) error {
124+
func (format *ObjFormat) Activate(asset *asset.Asset) error {
124125
asset.ActivateStatus.Success()
125126
return nil
126127
}
127-
func (format *ObjFormat) Deactivate(asset *Asset) error {
128+
func (format *ObjFormat) Deactivate(asset *asset.Asset) error {
128129
asset.ActivateStatus.Reset()
129130
return nil
130131
}

0 commit comments

Comments
 (0)