2019-07-07 06:28:11 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2024-05-24 20:54:41 +00:00
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
2019-07-07 06:28:11 +00:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
"sort"
|
2019-07-07 06:28:11 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/enum"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
|
2024-05-24 20:54:41 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level/rle"
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
2020-11-15 23:20:15 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-07-07 06:28:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Show information about a Level or Doodad file.
|
2020-06-05 06:11:03 +00:00
|
|
|
var Show *cli.Command
|
2019-07-07 06:28:11 +00:00
|
|
|
|
|
|
|
func init() {
|
2020-06-05 06:11:03 +00:00
|
|
|
Show = &cli.Command{
|
2019-07-07 06:28:11 +00:00
|
|
|
Name: "show",
|
|
|
|
Usage: "show information about a level or doodad file",
|
|
|
|
ArgsUsage: "<.level or .doodad>",
|
|
|
|
Flags: []cli.Flag{
|
2020-06-05 06:11:03 +00:00
|
|
|
&cli.BoolFlag{
|
2019-07-07 06:28:11 +00:00
|
|
|
Name: "actors",
|
|
|
|
Usage: "print verbose actor data in Level files",
|
|
|
|
},
|
2020-06-05 06:11:03 +00:00
|
|
|
&cli.BoolFlag{
|
2019-07-07 06:28:11 +00:00
|
|
|
Name: "chunks",
|
|
|
|
Usage: "print verbose data about all the pixel chunks in a file",
|
|
|
|
},
|
2020-06-05 06:11:03 +00:00
|
|
|
&cli.BoolFlag{
|
2019-07-07 06:28:11 +00:00
|
|
|
Name: "script",
|
|
|
|
Usage: "print the script from a doodad file and exit",
|
|
|
|
},
|
2021-06-07 01:59:04 +00:00
|
|
|
&cli.StringFlag{
|
2021-09-04 04:35:12 +00:00
|
|
|
Name: "attachment",
|
2021-06-07 01:59:04 +00:00
|
|
|
Aliases: []string{"a"},
|
2021-09-04 04:35:12 +00:00
|
|
|
Usage: "print the contents of the attached filename to terminal",
|
2021-06-07 01:59:04 +00:00
|
|
|
},
|
2020-06-05 06:11:03 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "verbose",
|
|
|
|
Aliases: []string{"v"},
|
|
|
|
Usage: "print verbose output (all verbose flags enabled)",
|
2019-07-07 06:28:11 +00:00
|
|
|
},
|
2024-05-24 20:54:41 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "visualize-rle",
|
|
|
|
Usage: "visually dump RLE encoded chunks to the terminal (VERY noisy for large drawings!)",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "chunk",
|
|
|
|
Usage: "specific chunk coordinate; when debugging chunks, only show this chunk (example: 2,-1)",
|
|
|
|
},
|
2019-07-07 06:28:11 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
if c.NArg() < 1 {
|
2021-09-04 04:35:12 +00:00
|
|
|
return cli.Exit(
|
2019-07-07 06:28:11 +00:00
|
|
|
"Usage: doodad show <.level .doodad ...>",
|
|
|
|
1,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-05 06:11:03 +00:00
|
|
|
filenames := c.Args().Slice()
|
2019-07-07 06:28:11 +00:00
|
|
|
for _, filename := range filenames {
|
|
|
|
switch strings.ToLower(filepath.Ext(filename)) {
|
|
|
|
case enum.LevelExt:
|
|
|
|
if err := showLevel(c, filename); err != nil {
|
|
|
|
log.Error(err.Error())
|
2021-09-04 04:35:12 +00:00
|
|
|
return cli.Exit("Error", 1)
|
2019-07-07 06:28:11 +00:00
|
|
|
}
|
|
|
|
case enum.DoodadExt:
|
|
|
|
if err := showDoodad(c, filename); err != nil {
|
|
|
|
log.Error(err.Error())
|
2021-09-04 04:35:12 +00:00
|
|
|
return cli.Exit("Error", 1)
|
2019-07-07 06:28:11 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Error("File %s: not a level or doodad", filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// showLevel shows data about a level file.
|
|
|
|
func showLevel(c *cli.Context, filename string) error {
|
|
|
|
lvl, err := level.LoadJSON(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-07 01:59:04 +00:00
|
|
|
// Are we printing an attached file?
|
|
|
|
if filename := c.String("attachment"); filename != "" {
|
|
|
|
if data, err := lvl.GetFile(filename); err == nil {
|
|
|
|
fmt.Print(string(data))
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Couldn't get attached file '%s': %s\n", filename, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 03:34:59 +00:00
|
|
|
// Is it a new zipfile format?
|
|
|
|
var fileType = "json or gzip"
|
|
|
|
if lvl.Zipfile != nil {
|
|
|
|
fileType = "zipfile"
|
|
|
|
}
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf("===== Level: %s =====\n", filename)
|
|
|
|
|
|
|
|
fmt.Println("Headers:")
|
2022-04-30 03:34:59 +00:00
|
|
|
fmt.Printf(" File format: %s\n", fileType)
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf(" File version: %d\n", lvl.Version)
|
|
|
|
fmt.Printf(" Game version: %s\n", lvl.GameVersion)
|
Update savegame format, Allow out-of-bounds camera
Updates the savegame.json file format:
* Levels now have a UUID value assigned at first save.
* The savegame.json will now track level completion/score based on UUID,
making it robust to filename changes in either levels or levelpacks.
* The savegame file is auto-migrated on startup - for any levels not
found or have no UUID, no change is made, it's backwards compatible.
* Level Properties window adds an "Advanced" tab to show/re-roll UUID.
New JavaScript API for doodad scripts:
* `Actors.CameraFollowPlayer()` tells the camera to return focus to the
player character. Useful for "cutscene" doodads that freeze the player,
call `Self.CameraFollowMe()` and do a thing before unfreezing and sending the
camera back to the player. (Or it will follow them at their next directional
input control).
* `Self.MoveBy(Point(x, y int))` to move the current actor a bit.
New option for the `doodad` command-line tool:
* `doodad resave <.level or .doodad>` will load and re-save a drawing, to
migrate it to the newest file format versions.
Small tweaks:
* On bounded levels, allow the camera to still follow the player if the player
finds themselves WELL far out of bounds (40 pixels margin). So on bounded
levels you can create "interior rooms" out-of-bounds to Warp Door into.
* New wallpaper: "Atmosphere" has a black starscape pattern that fades into a
solid blue atmosphere.
* Camera strictly follows the player the first 20 ticks, not 60 of level start
* If player is frozen, directional inputs do not take the camera focus back.
2023-03-08 05:55:10 +00:00
|
|
|
fmt.Printf(" Level UUID: %s\n", lvl.UUID)
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf(" Level title: %s\n", lvl.Title)
|
|
|
|
fmt.Printf(" Author: %s\n", lvl.Author)
|
|
|
|
fmt.Printf(" Password: %s\n", lvl.Password)
|
|
|
|
fmt.Printf(" Locked: %+v\n", lvl.Locked)
|
|
|
|
fmt.Println("")
|
|
|
|
|
2022-03-27 21:23:25 +00:00
|
|
|
fmt.Println("Game Rules:")
|
|
|
|
fmt.Printf(" Difficulty: %s (%d)\n", lvl.GameRule.Difficulty, lvl.GameRule.Difficulty)
|
|
|
|
fmt.Printf(" Survival: %+v\n", lvl.GameRule.Survival)
|
|
|
|
fmt.Println("")
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
showPalette(lvl.Palette)
|
|
|
|
|
|
|
|
fmt.Println("Level Settings:")
|
|
|
|
fmt.Printf(" Page type: %s\n", lvl.PageType.String())
|
|
|
|
fmt.Printf(" Max size: %dx%d\n", lvl.MaxWidth, lvl.MaxHeight)
|
|
|
|
fmt.Printf(" Wallpaper: %s\n", lvl.Wallpaper)
|
|
|
|
fmt.Println("")
|
|
|
|
|
2021-06-07 01:59:04 +00:00
|
|
|
fmt.Println("Attached Files:")
|
|
|
|
if files := lvl.ListFiles(); len(files) > 0 {
|
|
|
|
for _, v := range files {
|
|
|
|
data, _ := lvl.GetFile(v)
|
|
|
|
fmt.Printf(" %s: %d bytes\n", v, len(data))
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" None\n\n")
|
|
|
|
}
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
// Print the actor information.
|
|
|
|
fmt.Println("Actors:")
|
|
|
|
fmt.Printf(" Level contains %d actors\n", len(lvl.Actors))
|
|
|
|
if c.Bool("actors") || c.Bool("verbose") {
|
|
|
|
fmt.Println(" List of Actors:")
|
|
|
|
for id, actor := range lvl.Actors {
|
|
|
|
fmt.Printf(" - Name: %s\n", actor.Filename)
|
|
|
|
fmt.Printf(" UUID: %s\n", id)
|
|
|
|
fmt.Printf(" At: %s\n", actor.Point)
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
if len(actor.Options) > 0 {
|
|
|
|
var ordered = []string{}
|
|
|
|
for name := range actor.Options {
|
|
|
|
ordered = append(ordered, name)
|
|
|
|
}
|
|
|
|
sort.Strings(ordered)
|
|
|
|
|
|
|
|
fmt.Println(" Options:")
|
|
|
|
for _, name := range ordered {
|
|
|
|
val := actor.Options[name]
|
|
|
|
fmt.Printf(" %s %s = %v\n", val.Type, val.Name, val.Value)
|
|
|
|
}
|
|
|
|
}
|
2019-07-07 06:28:11 +00:00
|
|
|
if c.Bool("links") {
|
|
|
|
for _, link := range actor.Links {
|
|
|
|
if other, ok := lvl.Actors[link]; ok {
|
|
|
|
fmt.Printf(" Link: %s (%s)\n", link, other.Filename)
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" Link: %s (**UNRESOLVED**)", link)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
} else {
|
|
|
|
fmt.Print(" Use -actors or -verbose to serialize Actors\n\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize chunk information.
|
|
|
|
showChunker(c, lvl.Chunker)
|
|
|
|
|
|
|
|
fmt.Println("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func showDoodad(c *cli.Context, filename string) error {
|
|
|
|
dd, err := doodads.LoadJSON(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("script") {
|
|
|
|
fmt.Printf("// %s.js\n", filename)
|
|
|
|
fmt.Println(strings.TrimSpace(dd.Script))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-30 03:34:59 +00:00
|
|
|
// Is it a new zipfile format?
|
|
|
|
var fileType = "json or gzip"
|
|
|
|
if dd.Zipfile != nil {
|
|
|
|
fileType = "zipfile"
|
|
|
|
}
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf("===== Doodad: %s =====\n", filename)
|
|
|
|
|
|
|
|
fmt.Println("Headers:")
|
2022-04-30 03:34:59 +00:00
|
|
|
fmt.Printf(" File format: %s\n", fileType)
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf(" File version: %d\n", dd.Version)
|
|
|
|
fmt.Printf(" Game version: %s\n", dd.GameVersion)
|
|
|
|
fmt.Printf(" Doodad title: %s\n", dd.Title)
|
|
|
|
fmt.Printf(" Author: %s\n", dd.Author)
|
2023-02-17 05:47:18 +00:00
|
|
|
fmt.Printf(" Dimensions: %s\n", dd.Size)
|
2021-09-04 04:35:12 +00:00
|
|
|
fmt.Printf(" Hitbox: %s\n", dd.Hitbox)
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf(" Locked: %+v\n", dd.Locked)
|
|
|
|
fmt.Printf(" Hidden: %+v\n", dd.Hidden)
|
|
|
|
fmt.Printf(" Script size: %d bytes\n", len(dd.Script))
|
|
|
|
fmt.Println("")
|
|
|
|
|
|
|
|
if len(dd.Tags) > 0 {
|
|
|
|
fmt.Println("Tags:")
|
|
|
|
for k, v := range dd.Tags {
|
|
|
|
fmt.Printf(" %s: %s\n", k, v)
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
if len(dd.Options) > 0 {
|
|
|
|
var ordered = []string{}
|
|
|
|
for name := range dd.Options {
|
|
|
|
ordered = append(ordered, name)
|
|
|
|
}
|
|
|
|
sort.Strings(ordered)
|
|
|
|
|
|
|
|
fmt.Println("Options:")
|
|
|
|
for _, name := range ordered {
|
|
|
|
opt := dd.Options[name]
|
|
|
|
fmt.Printf(" %s %s = %v\n", opt.Type, opt.Name, opt.Default)
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
showPalette(dd.Palette)
|
|
|
|
|
|
|
|
for i, layer := range dd.Layers {
|
|
|
|
fmt.Printf("Layer %d: %s\n", i, layer.Name)
|
|
|
|
showChunker(c, layer.Chunker)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func showPalette(pal *level.Palette) {
|
|
|
|
fmt.Println("Palette:")
|
|
|
|
for _, sw := range pal.Swatches {
|
|
|
|
fmt.Printf(" - Swatch name: %s\n", sw.Name)
|
|
|
|
fmt.Printf(" Attributes: %s\n", sw.Attributes())
|
|
|
|
fmt.Printf(" Color: %s\n", sw.Color.ToHex())
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
|
|
|
func showChunker(c *cli.Context, ch *level.Chunker) {
|
2023-02-17 05:47:18 +00:00
|
|
|
var (
|
|
|
|
worldSize = ch.WorldSize()
|
|
|
|
chunkSize = int(ch.Size)
|
|
|
|
width = worldSize.W - worldSize.X
|
|
|
|
height = worldSize.H - worldSize.Y
|
2024-05-24 20:54:41 +00:00
|
|
|
|
|
|
|
// Chunk debugging CLI options.
|
|
|
|
visualize = c.Bool("visualize-rle")
|
|
|
|
specificChunk = c.String("chunk")
|
2023-02-17 05:47:18 +00:00
|
|
|
)
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Println("Chunks:")
|
|
|
|
fmt.Printf(" Pixels Per Chunk: %d^2\n", ch.Size)
|
|
|
|
fmt.Printf(" Number Generated: %d\n", len(ch.Chunks))
|
|
|
|
fmt.Printf(" Coordinate Range: (%d,%d) ... (%d,%d)\n",
|
|
|
|
worldSize.X,
|
|
|
|
worldSize.Y,
|
|
|
|
worldSize.W,
|
|
|
|
worldSize.H,
|
|
|
|
)
|
|
|
|
fmt.Printf(" World Dimensions: %dx%d\n", width, height)
|
|
|
|
|
|
|
|
// Verbose chunk information.
|
|
|
|
if c.Bool("chunks") || c.Bool("verbose") {
|
|
|
|
fmt.Println(" Chunk Details:")
|
2024-05-24 20:54:41 +00:00
|
|
|
for point := range ch.IterChunks() {
|
|
|
|
// Debugging specific chunk coordinate?
|
|
|
|
if specificChunk != "" && point.String() != specificChunk {
|
|
|
|
log.Warn("Skip chunk %s: not the specific chunk you're looking for", point)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk, ok := ch.GetChunk(point)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-07-07 06:28:11 +00:00
|
|
|
fmt.Printf(" - Coord: %s\n", point)
|
|
|
|
fmt.Printf(" Type: %s\n", chunkTypeToName(chunk.Type))
|
|
|
|
fmt.Printf(" Range: (%d,%d) ... (%d,%d)\n",
|
2023-02-17 05:47:18 +00:00
|
|
|
int(point.X)*chunkSize,
|
|
|
|
int(point.Y)*chunkSize,
|
|
|
|
(int(point.X)*chunkSize)+chunkSize,
|
|
|
|
(int(point.Y)*chunkSize)+chunkSize,
|
2019-07-07 06:28:11 +00:00
|
|
|
)
|
2024-05-24 20:54:41 +00:00
|
|
|
fmt.Printf(" Usage: %f (%d len of %d)\n", chunk.Usage(), chunk.Len(), chunkSize*chunkSize)
|
|
|
|
|
|
|
|
// Visualize the RLE encoded chunks?
|
|
|
|
if visualize && chunk.Type == level.RLEType {
|
|
|
|
ext, bin, err := ch.RawChunkFromZipfile(point)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
continue
|
|
|
|
} else if ext != ".bin" {
|
|
|
|
log.Error("Unexpected filetype for RLE compressed chunk (expected .bin, got %s)", ext)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read off the first byte (chunk type)
|
|
|
|
var reader = bytes.NewBuffer(bin)
|
|
|
|
binary.ReadUvarint(reader)
|
|
|
|
bin = reader.Bytes()
|
|
|
|
|
|
|
|
grid, err := rle.NewGrid(chunkSize)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
grid.Decompress(bin)
|
|
|
|
fmt.Println(grid.Visualize())
|
|
|
|
}
|
2019-07-07 06:28:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Println(" Use -chunks or -verbose to serialize Chunks")
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
2023-02-18 22:21:07 +00:00
|
|
|
func chunkTypeToName(v uint64) string {
|
2019-07-07 06:28:11 +00:00
|
|
|
switch v {
|
|
|
|
case level.MapType:
|
|
|
|
return "map"
|
2024-05-24 20:54:41 +00:00
|
|
|
case level.RLEType:
|
|
|
|
return "rle map"
|
2019-07-07 06:28:11 +00:00
|
|
|
case level.GridType:
|
|
|
|
return "grid"
|
|
|
|
default:
|
|
|
|
return fmt.Sprintf("type %d", v)
|
|
|
|
}
|
|
|
|
}
|