Let's Make a Map Editor Pt. 4
Contents
Checkout the previous post
Previous commit: e52241f
Internal conflict
I want the code to be more modular. There aren't many files, but I've been more regularly practicing BDD and TDD concepts.
This project falls lower on the priority list compared to some of my other projects, but I suspect that I will clean this up more.
To accommodate this, I started moving things around and cleaning up the code. I won't go into detail here on what's different.
PNG-Embed
One of the original ideas for this project was to embed the map data into the sprite atlas. I wasn't sure how much data you could embed in a png. It's probably worth finding the answer to that question. However, with the png-embed this became very easy.
func (l Level) ExportPNG() {
b, err := json.Marshal(l)
if err != nil {
fmt.Println(err)
return
}
bs, _ := ioutil.ReadFile("sample.png")
str := base64.StdEncoding.EncodeToString(b)
// Encode the key "FOO" with the value "BAR" (string).
data, _ := pngembed.Embed(bs, "FOO", str)
ioutil.WriteFile("sample.png", data, 0755)
}
func extractPNG() {
bs, _ := ioutil.ReadFile("sample.png")
fileBytes, err := pngembed.Extract(bs)
if err != nil {
println(err.Error())
return
}
data, err := base64.StdEncoding.DecodeString(string(fileBytes["FOO"]))
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Printf("%q\n", data)
}
It still needs some guards to prevent attempting loading a file that doesn't exist (and probably other things).
What's next?
- add a way to make a tile collidable
- map layers
- undo/redo
- cleanup
- add more ease-of-use/ux
commit 24ce6dc9