@@ 31,9 31,17 @@ Character :: struct {
animations: map[string]Anim,
}
-ini_value_or_common :: proc(m: ini.Map, section, key: string) -> (string, bool) {
- value, ok := m[section][key]
- if !ok do return m["common"][key]
+ini_value_or_common :: proc(m: ^ini.Map, section, key: string) -> (string, bool) {
+ section, ok := m[section]
+ if !ok do return "", false
+ value, ok2 := section[key]
+ if !ok2 {
+ common, ok := m["common"]
+ if !ok {
+ return "", false
+ }
+ return common[key]
+ }
return value, true
}
@@ 44,6 52,7 @@ Character_delete :: proc(ch: ^Character) -> runtime.Allocator_Error {
Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
ini_path := path.join({dir, "settings.ini"})
defer delete(ini_path)
+ ok = false
ini, ini_err, ok_ini := ini.load_map_from_path(
ini_path,
@@ 64,7 73,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
for &anim in required_animations {
_, ok = ini[anim]
if !ok {
- fmt.printf("ERROR: Required section {} not found\n", anim)
+ fmt.printf("error: required section {} not found\n", anim)
return
}
}
@@ 75,17 84,24 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
"walk_left",
"walk_right",
"grab",
- "grab_left",
- "grab_right",
"fall",
"drag",
"drag_left",
"drag_right",
}
+ has_walk := false
+ has_drag := false
+
for anim in animations {
+ ok = false
+
+ if anim == "walk" do has_walk = true
+ if anim == "drag" do has_drag = true
+ if (strings.has_prefix(anim, "walk_") && has_walk) || (strings.has_prefix(anim, "drag_") && has_drag) do continue
+
a := Anim{}
{ // Frame layout
- frame_layout_raw_value, ok := ini_value_or_common(ini, anim, "frame_layout")
+ frame_layout_raw_value, ok := ini_value_or_common(&ini, anim, "frame_layout")
if ok {
frame_layout_value := strings.to_lower(frame_layout_raw_value)
defer delete(frame_layout_value)
@@ 97,7 113,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
}
{ // FPS
- fps_value, ok := ini_value_or_common(ini, anim, "fps")
+ fps_value, ok := ini_value_or_common(&ini, anim, "fps")
if !ok {
fmt.println("ERROR: FPS not specified.")
return
@@ 110,7 126,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
}
{ // Frames
- frames_value, ok := ini_value_or_common(ini, anim, "frames")
+ frames_value, ok := ini_value_or_common(&ini, anim, "frames")
if !ok {
fmt.println("ERROR: Frames not specified.")
return
@@ 123,7 139,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
}
{ // Size
- w_value, ok := ini_value_or_common(ini, anim, "w")
+ w_value, ok := ini_value_or_common(&ini, anim, "w")
if !ok {
fmt.println("ERROR: No width specified")
return
@@ 134,7 150,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
return
}
- h_value, ok1 := ini_value_or_common(ini, anim, "h")
+ h_value, ok1 := ini_value_or_common(&ini, anim, "h")
if !ok1 {
fmt.println("ERROR: No height specified")
return
@@ 147,7 163,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
}
{ // Offset
- x_value, ok := ini_value_or_common(ini, anim, "offx")
+ x_value, ok := ini_value_or_common(&ini, anim, "offx")
if !ok {
fmt.println("ERROR: No X offset specified")
return
@@ 158,7 174,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
return
}
- y_value, ok1 := ini_value_or_common(ini, anim, "offy")
+ y_value, ok1 := ini_value_or_common(&ini, anim, "offy")
a.off.y, ok1 = strconv.parse_int(y_value)
if !ok1 {
fmt.println("ERROR: Invalid Y offset specified")
@@ 168,7 184,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
if strings.has_prefix(anim, "grab") || strings.has_prefix(anim, "drag") {
// Grab offset
- x_value, ok := ini_value_or_common(ini, anim, "grabx")
+ x_value, ok := ini_value_or_common(&ini, anim, "grabx")
if !ok {
fmt.println("ERROR: No X grab offset specified")
return
@@ 179,7 195,7 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
return
}
- y_value, ok1 := ini_value_or_common(ini, anim, "graby")
+ y_value, ok1 := ini_value_or_common(&ini, anim, "graby")
if !ok1 {
fmt.println("ERROR: No Y grab offset specified")
return
@@ 191,7 207,6 @@ Character_load :: proc(dir: string = ".") -> (ch: Character, ok: bool) {
}
}
- fmt.println(anim)
ch.animations[anim] = a
}
@@ 205,7 220,7 @@ main :: proc() {
panic("Invalid character")
}
- fmt.println(ch)
+ fmt.printf("%#v\n", ch)
desktop_width := win.GetSystemMetrics(win.SM_CXSCREEN)
desktop_height := win.GetSystemMetrics(win.SM_CYSCREEN)