Skip to content

Commit

Permalink
Update webasm blobs v0.9.209
Browse files Browse the repository at this point in the history
Increase go version to 1.16.
Embed webasm blobs in the binary.
Change CWD to binary dir, to allow launching the binary from any dir.
  • Loading branch information
jyaif committed Oct 10, 2024
1 parent 58d7eaf commit 796b9ae
Show file tree
Hide file tree
Showing 61 changed files with 39 additions and 11 deletions.
Binary file removed content/pewpewlive.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions generate_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
if os.path.exists('ppl-utils.exe'):
shutil.move('ppl-utils.exe', directory_name)

# Copy the other content
shutil.copytree('content', os.path.join(directory_name, 'content'))
# Copy the level
shutil.copytree('levels', os.path.join(directory_name, 'levels'))

# Remove all .DS_Store from the directory
for root, dirs, files in os.walk(directory_name):
Expand All @@ -74,7 +74,7 @@
os.remove(path)

# Remove all levels that do not start with 'sample_'
level_dir_path = os.path.join(directory_name, 'content', 'levels')
level_dir_path = os.path.join(directory_name, 'levels')
for dir in os.listdir(level_dir_path):
if not dir.startswith('sample_'):
path = os.path.join(level_dir_path, dir)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jyaif/ppl-utils

go 1.14
go 1.16
6 changes: 3 additions & 3 deletions level_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type LevelManifest struct {
HasScoreLeaderboard bool `json:"has_score_leaderboard"`
}

// GetDir returns the path to the content directory.
// GetDir returns the path to the levels directory.
func GetDir() string {
cwd, err := os.Getwd()
if err != nil {
Expand All @@ -47,7 +47,7 @@ func GetDir() string {
if err != nil {
panic(err)
}
dir = dir + string(os.PathSeparator) + "content"
dir = dir + string(os.PathSeparator) + "levels"
return dir
}

Expand All @@ -69,7 +69,7 @@ func ListLevels(dir string) []LevelJSON {
return stat_err
}

log.Print("path: " + path + ", file_info.Mode():" + file_info.Mode().String())
// log.Print("path: " + path + ", file_info.Mode():" + file_info.Mode().String())

fileIsASymLink := file_info.Mode()&os.ModeSymlink != 0
// If the file is a symlink, recursively walk it.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 31 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package main

import (
"embed"
"encoding/json"
"errors"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
)

//go:embed webasm/pewpew.*
//go:embed webasm/pewpewlive.*
var webasmFS embed.FS

func setHeaders(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
Expand Down Expand Up @@ -76,10 +83,31 @@ func getLevelManifest(w http.ResponseWriter, r *http.Request) {
}

func main() {
// Serves the static files
fs := cacheControlWrapper(http.FileServer(http.Dir(GetDir())))
http.Handle("/", fs)
// Change the current working directory to the directory of the executable
// Necessary to serve the levels if the binary is launched from an
// arbitrary directory.
executablePath, err := os.Executable()
if err != nil {
log.Print("Error getting executable path:", err)
return
}
executableDir := filepath.Dir(executablePath)
err = os.Chdir(executableDir)
if err != nil {
log.Print("Error changing directory:", err)
return
}

// Serve the static files
trimmedFS, trimmErr := fs.Sub(webasmFS, "webasm")
if trimmErr != nil {
log.Print("Error trimming directory:", trimmErr)
return
}
fsHandler := cacheControlWrapper(http.FileServerFS(trimmedFS))
http.Handle("/", fsHandler)

// Serve the levels
http.HandleFunc("/custom_levels/get_public_levels", list)
http.HandleFunc("/custom_levels/get_level", getLevel)
http.HandleFunc("/custom_levels/get_level_manifest", getLevelManifest)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion content/pewpewlive.js → webasm/pewpewlive.js

Large diffs are not rendered by default.

Binary file added webasm/pewpewlive.wasm
Binary file not shown.

0 comments on commit 796b9ae

Please sign in to comment.