Merge pull request #12 from Nv7-GitHub/main

Sus mod and Nv7 Mod + Mod generator
This commit is contained in:
slweeb 2022-01-22 14:53:25 -05:00 committed by GitHub
commit 96a8509290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32786 additions and 0 deletions

32513
mods/nv7.js Executable file

File diff suppressed because it is too large Load Diff

92
mods/sus.js Normal file
View File

@ -0,0 +1,92 @@
function createSus(right, top) {
return {
color: "#ff0000",
behavior: [
`XX|CR:${top} AND CH:${top}|XX`,
`XX|XX|CR:${right} AND CH:${right}`,
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}
}
function createSusTop(top) {
return {
color: "#ff0000",
behavior: [
`XX|CR:${top} AND CH:${top}|XX`,
`XX|XX|DL`,
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}
}
function createSusTopRow(right) {
return {
color: "#ff0000",
behavior: [
`XX|CR:top AND CH:top|XX`,
`XX|XX|CR:${right} AND CH:${right}`,
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}
}
elements.sus = createSus("sus2", "sus4")
elements.sus.behavior[2] = "XX|M1|XX"
elements.sus.hidden = false
elements.sus2 = createSus("sus3", "sus5")
elements.sus3 = createSusTop("sus6")
elements.sus4 = createSus("sus5", "sus7")
elements.sus5 = createSus("sus6", "sus8")
elements.sus6 = createSusTop("sus9")
elements.sus7 = createSus("sus8", "susA")
elements.sus8 = createSus("sus9", "susB")
elements.sus9 = createSusTop("susC")
elements.susA = createSusTopRow("susB")
elements.susB = createSusTopRow("susC")
elements.susC = {
color: "#ff0000",
behavior: [
`XX|CR:top AND CH:top|XX`,
`XX|XX|DL`,
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}
elements.top = {
color: "#000000",
behavior: [
`XX|DL|XX`,
`XX|DL%5|XX`,
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}
// Colors
elements.sus2.color = "#000000"
elements.sus8.color = "#00ffff"
elements.sus9.color = "#00ffff"
/*
susA susB susC
sus7 sus8 sus9
sus4 sus5 sus6
sus_ sus2 sus3
*/

116
scripts/im2elements/code.go Normal file
View File

@ -0,0 +1,116 @@
package main
import (
"fmt"
"image"
"strings"
)
const category = "special"
func genCode(im image.Image, name string) string {
out := &strings.Builder{}
fmt.Fprintf(out, `elements.%s_top = {
color: "#000000",
behavior: [
"XX|DL|XX",
"XX|DL%%5|XX",
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}`+"\n\n", name)
for y := im.Bounds().Dy() - 1; y >= 0; y-- {
for x := 0; x < im.Bounds().Dx(); x++ {
r, g, b, _ := im.At(x, y).RGBA()
if r == 0 && g == 0 && b == 0 {
continue
}
r = r >> 8
g = g >> 8
b = b >> 8
// Get hex
hex := fmt.Sprintf("#%02x%02x%02x", r, g, b)
// Add code
nameNum := fmt.Sprintf("%s_%d_%d", name, x, y)
fall := "XX"
hidden := "true"
if y == im.Bounds().Dy()-1 && x == 0 {
nameNum = name
fall = "M1"
hidden = "false"
}
top := fmt.Sprintf("%s_%d_%d", name, x, y-1)
right := fmt.Sprintf("%s_%d_%d", name, x+1, y)
// On top and right?
if y == 0 && x == im.Bounds().Dx()-1 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s_top AND CH:%s_top|XX",
"XX|XX|DL",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, name, name, category, hidden)
continue
}
// If on top?
if y == 0 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s_top AND CH:%s_top|XX",
"XX|XX|CR:%s AND CH:%s",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, name, name, right, right, category, hidden)
continue
}
// If on far right?
if x == im.Bounds().Dx()-1 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s AND CH:%s|XX",
"XX|XX|DL",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, top, top, category, hidden)
continue
}
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s AND CH:%s|XX",
"XX|XX|CR:%s AND CH:%s",
"XX|%s|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, top, top, right, right, fall, category, hidden)
}
}
return out.String()
}

View File

@ -0,0 +1,5 @@
module im2elements
go 1.17
require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646

View File

@ -0,0 +1,2 @@
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=

View File

@ -0,0 +1,58 @@
package main
import (
"image"
_ "image/jpeg"
_ "image/png"
"bufio"
"fmt"
"os"
"strconv"
"github.com/nfnt/resize"
)
var reader = bufio.NewReader(os.Stdin)
func getInput(par string) string {
fmt.Print(par)
text, _, err := reader.ReadLine()
if err != nil {
panic(err)
}
return string(text)
}
func toInt(val string) int {
v, err := strconv.Atoi(val)
if err != nil {
panic(err)
}
return v
}
func main() {
filename := getInput("Image: ")
f, err := os.Open(filename)
if err != nil {
panic(err)
}
defer f.Close()
im, _, err := image.Decode(f)
if err != nil {
panic(err)
}
width := toInt(getInput("Max Width (works best with 5-10): "))
height := toInt(getInput("Max Height (works best with 5-10, leave at 0 for scaling): "))
im = resize.Resize(uint(width), uint(height), im, resize.Lanczos3)
name := getInput("Name: ")
outF := getInput("Output file (JS): ")
err = os.WriteFile(outF, []byte(genCode(im, name)), os.ModePerm)
if err != nil {
panic(err)
}
}