1 Commits

Author SHA1 Message Date
540c8ba9d4 added Zyko0/Ebiary/asset for live reloading 2024-03-25 18:03:02 +01:00
5 changed files with 15 additions and 54 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 KiB

View File

@@ -1,7 +1,5 @@
# kage-viewer - Viewer for shaders written in Kage, similar to glslviewer
![Logo](https://github.com/TLINDEN/kageviewer/blob/main/.github/assets/logo.png)
[![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://github.com/tlinden/kage-viewer/blob/master/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/tlinden/kage-viewer)](https://goreportcard.com/report/github.com/tlinden/kage-viewer)
@@ -13,10 +11,6 @@ reloads changed assets, which allows you to develop your shader and
see live, how it responds to your changes. If loading fails, an error
will be printed to STDOUT. The same applies for images.
## Screenshot
![Screenshot](https://github.com/TLINDEN/kageviewer/blob/main/.github/assets/screenshot.png)
## Installation
The tool does not have any dependencies. Just download the binary for
@@ -78,8 +72,6 @@ Options:
-s --shader <kage file> Shader to run
-g --geometry <WIDTHxHEIGHT> Window size
-p --position <XxY> Position of image0
-b --background <png file> Image to load as background
-t --tps <ticks/s> At how many ticks per second to run
--map-flag <name> Map Flag uniform to <name>
--map-ticks <name> Map Flag uniform to <name>
--map-slider <name> Map Flag uniform to <name>

View File

@@ -32,7 +32,7 @@ import (
)
const (
VERSION string = "0.0.4"
VERSION string = "0.0.3"
Usage string = `This is kage-viewer, a shader viewer.
Usage: kage-viewer [-vd] [-c <config file>] [-g geom] [-p geom] \
@@ -44,8 +44,6 @@ Options:
-s --shader <kage file> Shader to run
-g --geometry <WIDTHxHEIGHT> Window size
-p --position <XxY> Position of image0
-b --background <png file> Image to load as background
-t --tps <ticks/s> At how many ticks per second to run
--map-flag <name> Map Flag uniform to <name>
--map-ticks <name> Map Flag uniform to <name>
--map-slider <name> Map Flag uniform to <name>
@@ -56,15 +54,13 @@ Options:
)
type Config struct {
Showversion bool `koanf:"version"` // -v
Debug bool `koanf:"debug"` // -d
Config string `koanf:"config"` // -c
Image []string `koanf:"image"` // -i
Shader string `koanf:"shader"` // -s
Background string `koanf:"background"` // -b
TPS int `koanf:"tps"` // -t
Geo string `koanf:"geometry"` // -g
Posision string `koanf:"position"` // -p
Showversion bool `koanf:"version"` // -v
Debug bool `koanf:"debug"` // -d
Config string `koanf:"config"` // -c
Image []string `koanf:"image"` // -i
Shader string `koanf:"shader"` // -s
Geo string `koanf:"geometry"` // -g
Posision string `koanf:"position"` // -p
Flag string `koanf:"map-flag"`
Ticks string `koanf:"map-ticks"`
Mouse string `koanf:"map-mouse"`
@@ -95,8 +91,6 @@ func InitConfig() (*Config, error) {
flagset.StringP("map-ticks", "", "Ticks", "map ticks uniform")
flagset.StringP("map-mouse", "", "Mouse", "map mouse uniform")
flagset.StringP("map-slider", "", "Slider", "map slider uniform")
flagset.StringP("background", "b", "", "background image")
flagset.IntP("tps", "t", 60, "ticks per second")
if err := flagset.Parse(os.Args[1:]); err != nil {
return nil, fmt.Errorf("failed to parse program arguments: %w", err)

39
game.go
View File

@@ -30,14 +30,13 @@ import (
)
type Game struct {
Conf *Config
Images []*asset.LiveAsset[*ebiten.Image]
Shader *asset.LiveAsset[*ebiten.Shader]
Cursor []float64
Ticks int
Slider float64
Flag int
Background *asset.LiveAsset[*ebiten.Image]
Conf *Config
Images []*asset.LiveAsset[*ebiten.Image]
Shader *asset.LiveAsset[*ebiten.Shader]
Cursor []float64
Ticks int
Slider float64
Flag int
}
func LoadImage(name string) (*ebiten.Image, error) {
@@ -72,21 +71,8 @@ func (game *Game) Init() error {
return fmt.Errorf("failed to load shader %s: %s", game.Conf.Shader, err)
}
if game.Conf.Background != "" {
slog.Debug("Loading background", "image", game.Conf.Background)
img, err := asset.NewLiveAsset[*ebiten.Image](game.Conf.Background)
if err != nil {
return fmt.Errorf("failed to load image %s: %s", game.Conf.Background, err)
}
game.Background = img
}
game.Shader = shader
ebiten.SetMaxTPS(game.Conf.TPS)
return nil
}
@@ -142,12 +128,6 @@ func (game *Game) Update() error {
fmt.Println("warn: shader reloading error:", game.Shader.Error())
}
if game.Background != nil {
if game.Background.Error() != nil {
fmt.Println("warn: background image reloading error:", game.Background.Error())
}
}
if game.CheckInput() {
slog.Debug("Key pressed",
game.Conf.Flag, game.Flag,
@@ -166,11 +146,6 @@ func (game *Game) Update() error {
}
func (game *Game) Draw(screen *ebiten.Image) {
if game.Background != nil {
op := &ebiten.DrawImageOptions{}
screen.DrawImage(game.Background.Value(), op)
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]any{