-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assets.go
139 lines (126 loc) · 3.05 KB
/
Assets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
_ "embed"
_ "image/jpeg"
_ "image/png"
"log"
"os"
"path/filepath"
"strings"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
var (
//go:embed .\BuildData\Assets\Textures\Nil_Texture.png
Nil_Texture_png string
Nil_Texture, _, _ = ebitenutil.NewImageFromReader(strings.NewReader(Nil_Texture_png))/*
//go:embed .\BuildData\Assets\Fonts\calibri-bold.ttf
Nil_Font_otf string
Nil_Font font.Face = nul_font_init(Nil_Font_otf)*/
)
/*
func nul_font_init(str string) font.Face {
nil_font, err := opentype.Parse([]byte(str))
if err != nil {
log.Fatal(err)
return nil
}
ffff, err := opentype.NewFace(
nil_font,
&opentype.FaceOptions{
Size: 24,
DPI: 72,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
return nil
}
return ffff
}
*/
var (
Exist, _ = os.Executable()
MainPath = NewPath(Exist)
Assets = MainPath.Dir("Assets")
Textures = Assets.Dir("Textures")
FonImage = TextureOpen(Textures, "geno-online-v1c.jpg", Nil_Texture)
Players = Textures.Dir("Players")
First = Players.Dir("First")
Main = First.Dir("Main")
Player_First_body_1_45 = TextureOpen(Main, "body_1_45.png", Nil_Texture)
Ground = Textures.Dir("Ground")
First_b = Ground.Dir("First")
Block_plit_face = TextureOpen(First_b, "plit_face.png", Nil_Texture)
Block_re_face = TextureOpen(First_b, "block re.png", Nil_Texture)
Block_wall_face = TextureOpen(First_b, "wall 1-1-1.png", Nil_Texture)
Fonts = Assets.Dir("Fonts")
//FonFont = FontOpen(Fonts, "Ranika.otf", Nil_Font)
)
func TextureOpen(p Path, f string, empty_texture *ebiten.Image) *ebiten.Image {
path, err := p.FileCheck(NewFile(f))
if err != nil {
log.Print(err)
return empty_texture
}
texture, _, err := ebitenutil.NewImageFromFile(path)
if err != nil {
log.Print(err)
return empty_texture
}
return texture
}
func FontOpen(p Path, f string, empty_texture font.Face) font.Face {
path, err := p.FileCheck(NewFile(f))
if err != nil {
log.Print(err)
return empty_texture
}
file, err := os.ReadFile(path)
font_data, err := opentype.Parse(file)
if err != nil {
log.Print(err)
return empty_texture
}
face, err := opentype.NewFace(
font_data,
&opentype.FaceOptions{
Size: 24,
DPI: 72,
Hinting: font.HintingFull,
})
if err != nil {
log.Print(err)
return nil
}
return face
}
type Path string
func NewPath(s string) Path {
return Path(filepath.Dir(s))
}
func (p Path) Dir(name string) Path {
return Path(filepath.Join(
string(p),
name,
))
}
func (p Path) FileCheck(f File) (string, error) {
path := filepath.Join(string(p), f.String())
_, err := os.Stat(path)
return path, err
}
type File struct {
Name, Extension string
}
func NewFile(s string) File {
return File{
Name: strings.TrimSuffix(s, filepath.Ext(s)),
Extension: filepath.Ext(s),
}
}
func (f File) String() string {
return f.Name + f.Extension
}