example room

This commit is contained in:
Synthasmagoria 2026-11-11 15:02:00 +01:00
commit 9ea0da6831
2 changed files with 174 additions and 44 deletions

View file

@ -338,6 +338,51 @@ JmapObjectInstance :: struct {
x, y, object_index: int,
}
jmap_object_list_from_text :: proc(text: string, allocator: mem.Allocator, temp_allocator: mem.Allocator) -> (_object_list: []JmapObjectInstance, _error: JmapObjectListError) {
object_start_marker := "objects: (x, y, type)\n"
object_start_marker_index := strings.index(text, object_start_marker)
if object_start_marker_index == -1 {
return {}, .NoStartMarker
}
object_start_index := object_start_marker_index + len(object_start_marker)
object_end_marker := "version:"
object_end_index := strings.index(text, object_end_marker)
if object_end_index == -1 {
return {}, .NoEndMarker
}
object_list_string := text[object_start_index:object_end_index]
object_list_split := strings.split(object_list_string, sep = " ", allocator = temp_allocator)
if len(object_list_split) % 3 != 0 {
return {}, .BadListLength
}
object_list := make([]JmapObjectInstance, len(object_list_split) / 3, allocator)
for i := 0; i < len(object_list); i += 1 {
x, x_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 0]), 10)
if !x_ok {
fmt.println("ERROR: Couldn't parse x of object '", object_list_split[i * 3 + 0], "'", sep = "")
return {}, .BadObject
}
y, y_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 1]), 10)
if !y_ok {
fmt.println("ERROR: Couldn't parse y of object '", object_list_split[i * 3 + 1], "'", sep = "")
return {}, .BadObject
}
object_index, object_index_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 2]), 10)
if !object_index_ok {
fmt.println("ERROR: Couldn't parse object_index of object '", object_list_split[i * 3 + 2], "'", sep = "")
return {}, .BadObject
}
object_list[i] = {x, y, object_index}
}
return object_list, .None
}
jmap_object_map := map[int]string {
1 = "block",
2 = "miniBlock",
@ -386,47 +431,4 @@ jmap_object_map := map[int]string {
47 = "miniLineBlockVertical",
}
jmap_object_list_from_text :: proc(text: string, allocator: mem.Allocator, temp_allocator: mem.Allocator) -> (_object_list: []JmapObjectInstance, _error: JmapObjectListError) {
object_start_marker := "objects: (x, y, type)\n"
object_start_marker_index := strings.index(text, object_start_marker)
if object_start_marker_index == -1 {
return {}, .NoStartMarker
}
object_start_index := object_start_marker_index + len(object_start_marker)
object_end_marker := "version:"
object_end_index := strings.index(text, object_end_marker)
if object_end_index == -1 {
return {}, .NoEndMarker
}
object_list_string := text[object_start_index:object_end_index]
object_list_split := strings.split(object_list_string, sep = " ", allocator = temp_allocator)
if len(object_list_split) % 3 != 0 {
return {}, .BadListLength
}
object_list := make([]JmapObjectInstance, len(object_list_split) / 3, allocator)
for i := 0; i < len(object_list); i += 1 {
x, x_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 0]), 10)
if !x_ok {
fmt.println("ERROR: Couldn't parse x of object '", object_list_split[i * 3 + 0], "'", sep = "")
return {}, .BadObject
}
y, y_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 1]), 10)
if !y_ok {
fmt.println("ERROR: Couldn't parse y of object '", object_list_split[i * 3 + 1], "'", sep = "")
return {}, .BadObject
}
object_index, object_index_ok := strconv.parse_int(strings.trim_space(object_list_split[i * 3 + 2]), 10)
if !object_index_ok {
fmt.println("ERROR: Couldn't parse object_index of object '", object_list_split[i * 3 + 2], "'", sep = "")
return {}, .BadObject
}
object_list[i] = {x, y, object_index}
}
return object_list, .None
}
jmap_object_map_reverse: map[string]int