Skip to content

Commit 4865d9f

Browse files
committed
Replaced concrete filesystem dependency with interface
1 parent 5e97823 commit 4865d9f

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

filesystem.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package vmt
22

33
import (
44
keyvalues "github.com/galaco/KeyValues"
5-
"github.com/golang-source-engine/filesystem"
5+
"io"
66
"strings"
77
)
88

@@ -11,10 +11,14 @@ const (
1111
vmtExtension = ".vmt"
1212
)
1313

14+
type virtualFilesystem interface {
15+
GetFile(string) (io.Reader, error)
16+
}
17+
1418
// FromFilesystem loads a material from filesystem
1519
// Its important to note this is the ONLY way to automatically
1620
// resolve `import` properties present in a vmt
17-
func FromFilesystem(filePath string, fs *filesystem.FileSystem, definition Material) (Material, error) {
21+
func FromFilesystem(filePath string, fs virtualFilesystem, definition Material) (Material, error) {
1822
// ensure proper file path
1923
validatedPath := sanitizeFilePath(filePath)
2024

@@ -38,7 +42,7 @@ func sanitizeFilePath(filePath string) string {
3842
return filePath
3943
}
4044

41-
func readVmtFromFilesystem(path string, fs *filesystem.FileSystem) (*keyvalues.KeyValue, error) {
45+
func readVmtFromFilesystem(path string, fs virtualFilesystem) (*keyvalues.KeyValue, error) {
4246
root, err := readKeyValuesFromFilesystem(path, fs)
4347
if err != nil {
4448
return nil, err
@@ -56,7 +60,7 @@ func readVmtFromFilesystem(path string, fs *filesystem.FileSystem) (*keyvalues.K
5660
return root, nil
5761
}
5862

59-
func mergeIncludedVmtRecursive(base *keyvalues.KeyValue, includePath string, fs *filesystem.FileSystem) (*keyvalues.KeyValue, error) {
63+
func mergeIncludedVmtRecursive(base *keyvalues.KeyValue, includePath string, fs virtualFilesystem) (*keyvalues.KeyValue, error) {
6064
parent, err := readKeyValuesFromFilesystem(includePath, fs)
6165
if err != nil {
6266
return base, err
@@ -80,7 +84,7 @@ func mergeIncludedVmtRecursive(base *keyvalues.KeyValue, includePath string, fs
8084
// ReadKeyValues loads a keyvalues file.
8185
// Its just a simple wrapper that combines the KeyValues library and
8286
// the filesystem module.
83-
func readKeyValuesFromFilesystem(filePath string, fs *filesystem.FileSystem) (*keyvalues.KeyValue, error) {
87+
func readKeyValuesFromFilesystem(filePath string, fs virtualFilesystem) (*keyvalues.KeyValue, error) {
8488
stream, err := fs.GetFile(filePath)
8589
if err != nil {
8690
return nil, err

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module github.com/golang-source-engine/vmt
22

33
go 1.13
44

5-
require (
6-
github.com/galaco/KeyValues v1.4.1
7-
github.com/golang-source-engine/filesystem v0.1.2
8-
)
5+
require github.com/galaco/KeyValues v1.4.1

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ github.com/galaco/vpk2 v0.0.0-20181012095330-21e4d1f6c888 h1:QCMt6AZ5gwsJ3SNsvTU
1010
github.com/galaco/vpk2 v0.0.0-20181012095330-21e4d1f6c888/go.mod h1:jL22XAWuUlYUmONuamxDdbDlGJhuOFkqNRPJwuBA3X8=
1111
github.com/go-gl/mathgl v0.0.0-20190713194549-592312d8590a h1:yoAEv7yeWqfL/l9A/J5QOndXIJCldv+uuQB1DSNQbS0=
1212
github.com/go-gl/mathgl v0.0.0-20190713194549-592312d8590a/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
13-
github.com/golang-source-engine/filesystem v0.1.0 h1:KyOT6ibo5k6UpLg3JfVRRpwVSX6k2AgQEARNDjDFUIA=
14-
github.com/golang-source-engine/filesystem v0.1.0/go.mod h1:yWGjkMHmaX6NvpUKueRi7/QubJDFp2dxyHKhEWZRwcM=
15-
github.com/golang-source-engine/filesystem v0.1.1 h1:MbvhLir27h+nppmV6OjN1nSsSf/bcxijzR73Yr+YDX0=
16-
github.com/golang-source-engine/filesystem v0.1.1/go.mod h1:39q6MJzPeePmSiCdb1esQRNrdalKnz2UAe/bNmNtz3k=
17-
github.com/golang-source-engine/filesystem v0.1.2 h1:6e+E71FSrohJlcbTNmOh1cVnPDP04/V4Gkfno/5VdGI=
18-
github.com/golang-source-engine/filesystem v0.1.2/go.mod h1:HKc/2NsiY0wj9uRSM6s5AQIt/8J9T7qx2nITY8JBKEU=
1913
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
2014
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a h1:gHevYm0pO4QUbwy8Dmdr01R5r1BuKtfYqRqF0h/Cbh0=
2115
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

0 commit comments

Comments
 (0)