4 Commits

Author SHA1 Message Date
b384795e53 added --tps and --background 2024-03-25 20:32:09 +01:00
b41d23a2fd + screenshot 2024-03-25 18:33:02 +01:00
dacbb5567c +logo 2024-03-25 18:26:53 +01:00
6cb30560d0 added Zyko0/Ebiary/asset for live reloading 2024-03-25 18:09:06 +01:00
5 changed files with 54 additions and 15 deletions

BIN
.github/assets/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
.github/assets/screenshot.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

View File

@@ -1,5 +1,7 @@
# 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)
@@ -11,6 +13,10 @@ 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
@@ -72,6 +78,8 @@ 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.3"
VERSION string = "0.0.4"
Usage string = `This is kage-viewer, a shader viewer.
Usage: kage-viewer [-vd] [-c <config file>] [-g geom] [-p geom] \
@@ -44,6 +44,8 @@ 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>
@@ -59,6 +61,8 @@ type Config struct {
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
Flag string `koanf:"map-flag"`
@@ -91,6 +95,8 @@ 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)

25
game.go
View File

@@ -37,6 +37,7 @@ type Game struct {
Ticks int
Slider float64
Flag int
Background *asset.LiveAsset[*ebiten.Image]
}
func LoadImage(name string) (*ebiten.Image, error) {
@@ -71,8 +72,21 @@ 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
}
@@ -128,6 +142,12 @@ 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,
@@ -146,6 +166,11 @@ 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{