Convert default textures into Go code

master
HimbeerserverDE 2021-09-03 20:08:09 +02:00
parent 3fe4176203
commit b73d56f6fa
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
85 changed files with 486 additions and 34 deletions

15
-p Normal file
View File

@ -0,0 +1,15 @@
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
00000010: 0000 0010 0000 0010 0806 0000 001f f3ff ................
00000020: 6100 0000 0173 5247 4200 aece 1ce9 0000 a....sRGB.......
00000030: 0006 624b 4744 008b 00b9 00f9 319b b5db ..bKGD......1...
00000040: 0000 0009 7048 5973 0000 0b13 0000 0b13 ....pHYs........
00000050: 0100 9a9c 1800 0000 0774 494d 4507 e102 .........tIME...
00000060: 090e 371e 7692 ce30 0000 000c 6954 5874 ..7.v..0....iTXt
00000070: 436f 6d6d 656e 7400 0000 0000 bcae b299 Comment.........
00000080: 0000 0049 4944 4154 38cb 63e8 def9 f33f ...IIDAT8.c....?
00000090: 0310 904b 5304 c086 50c5 249a bae0 3f10 ...KS...P.$...?.
000000a0: d0cf 05ff 9100 ba0b 9069 a25c 458c 46bc .........i.\E.F.
000000b0: 2ec0 6600 0329 8145 8c01 282e 20c7 00ac ..f..).E..(. ...
000000c0: ae20 c50b 4324 2512 6f12 9934 00f0 bce0 . ..C$%.o..4....
000000d0: 8954 1981 2400 0000 0049 454e 44ae 4260 .T..$....IEND.B`
000000e0: 82 .

View File

@ -36,10 +36,7 @@ func connectContent(conn net.Conn, name, userName string) (*contentConn, error)
userName: userName,
}
if err := cc.readDefaultTextures(); err != nil {
return nil, err
}
cc.addDefaultTextures()
go handleContent(cc)
return cc, nil
}

View File

@ -1,13 +1,10 @@
package main
import (
"crypto/sha1"
"encoding/base64"
"errors"
"log"
"net"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
@ -18,6 +15,8 @@ import (
"github.com/anon55555/mt/rudp"
)
//go:generate go run gen_textures.go
var b64 = base64.StdEncoding
type mediaFile struct {
@ -63,33 +62,8 @@ func (cc *contentConn) setState(state clientState) {
func (cc *contentConn) done() <-chan struct{} { return cc.doneCh }
func (cc *contentConn) readDefaultTextures() error {
executable, err := os.Executable()
if err != nil {
return err
}
path := filepath.Dir(executable) + "/textures"
files, err := os.ReadDir(path)
if err != nil {
return err
}
for _, file := range files {
data, err := os.ReadFile(path + "/" + file.Name())
if err != nil {
return err
}
sum := sha1.Sum(data)
cc.media = append(cc.media, mediaFile{
name: file.Name(),
base64SHA1: b64.EncodeToString(sum[:]),
data: data,
})
}
return nil
func (cc *contentConn) addDefaultTextures() {
cc.media = defaultTextures // auto generated variable, see gen_textures.go
}
func (cc *contentConn) log(dir string, v ...interface{}) {

404
default_textures.go Normal file

File diff suppressed because one or more lines are too long

62
gen_textures.go Normal file
View File

@ -0,0 +1,62 @@
//go:build ignore
// +build ignore
// This program generates default_textures.go. It can be invoked
// by running go generate
package main
import (
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"strings"
)
var b64 = base64.StdEncoding
func main() {
f, err := os.OpenFile("default_textures.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer f.Close()
f.WriteString("package main\n")
f.WriteString("\n")
f.WriteString("var defaultTextures = []mediaFile{\n")
dir, err := os.ReadDir("textures")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, file := range dir {
name := file.Name()
data, err := os.ReadFile("textures/" + name)
if err != nil {
fmt.Println(err)
continue
}
sum := sha1.Sum(data)
f.WriteString("\tmediaFile{\n")
f.WriteString("\t\tname: \"" + name + "\",\n")
f.WriteString("\t\tbase64SHA1: \"" + b64.EncodeToString(sum[:]) + "\",\n")
f.WriteString("\t\tdata: []byte{")
var strs []string
for _, b := range data {
strs = append(strs, "0x"+hex.EncodeToString([]byte{b}))
}
f.WriteString(strings.Join(strs, ", ") + "},\n")
f.WriteString("\t},\n")
}
f.WriteString("}\n")
}

BIN
textures/air.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
textures/aux1_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
textures/blank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

BIN
textures/bubble.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
textures/bubble_gone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

BIN
textures/camera_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
textures/cdb_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
textures/cdb_clear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

BIN
textures/cdb_queued.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

BIN
textures/cdb_update.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

BIN
textures/cdb_viewonline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
textures/chat_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

BIN
textures/chat_hide_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
textures/chat_show_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
textures/checkbox_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

BIN
textures/checkbox_32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

BIN
textures/checkbox_64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

BIN
textures/clear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

BIN
textures/debug_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
textures/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
textures/drop_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
textures/end_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

BIN
textures/fast_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
textures/fly_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
textures/gear_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
textures/halo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

BIN
textures/heart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

BIN
textures/heart_gone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

BIN
textures/ignore.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

BIN
textures/inventory_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

BIN
textures/joystick_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/joystick_off.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
textures/jump_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

BIN
textures/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
textures/menu_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

BIN
textures/menu_header.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
textures/minimap_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
textures/next_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

BIN
textures/no_screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

BIN
textures/noclip_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

BIN
textures/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
textures/player_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

BIN
textures/player_marker.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
textures/plus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

BIN
textures/prev_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

BIN
textures/progress_bar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

BIN
textures/rangeview_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
textures/rare_controls.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

BIN
textures/refresh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
textures/search.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

BIN
textures/server_ping_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

BIN
textures/server_ping_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

BIN
textures/server_ping_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

BIN
textures/server_ping_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

BIN
textures/server_public.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 B

BIN
textures/smoke_puff.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

BIN
textures/start_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

BIN
textures/sunrisebg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/unknown_item.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

BIN
textures/unknown_node.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

BIN
textures/unknown_object.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

BIN
textures/wieldhand.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

BIN
textures/zoom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB