switch functionality and bug fixes

This commit is contained in:
Synthasmagoria 2026-11-11 21:56:45 +01:00
commit d0467eb0c6
3 changed files with 45629 additions and 141 deletions

View file

@ -1,7 +1,7 @@
[
{
"label": "Test run",
"command": "odin run . -- project.yyp rSatoru.yy jmap.jmap jmap_config.json5",
"command": "odin run . -- project.yyp rSatoru.yy jmap.jmap jmap_config.json5 -x:1600 -y:608 -clear_area",
},
{
"label": "Build debug",

View file

@ -4,7 +4,6 @@ package main
import "base:runtime"
import "core:os"
import "core:math"
import "core:math/rand"
import "core:fmt"
import "core:encoding/json"
@ -12,6 +11,16 @@ import "core:strings"
import "core:strconv"
import "core:mem"
JMAP_ROOM_WIDTH :: 800
JMAP_ROOM_HEIGHT :: 608
/* ###
UTILILITY
*/
point_in_rectangle :: proc(px, py, rx, ry, rw, rh: int) -> bool {
return px >= rx && px < rx + rw && py >= ry && py < ry + rh
}
/* ###
SWITCHES
*/
@ -295,7 +304,7 @@ HELP_MESSAGE :: """
Usage: <program> <yyp_resource_path> <room_resource_path> <jmap_path> <jmap_config_path> [other flags...]
"""
ProgramArguments :: struct {
ProgramConfig :: struct {
x, y: int,
clear_area: bool,
}
@ -304,46 +313,45 @@ switch_definitions := []SwitchDefinition {
{
name = "x",
fullname = "x",
shortname = "x",
description = "set x at which to place the jmap contents at (default: 0)",
no_argument = false,
usage = "-x <value>",
usage = "-x:<value>",
callback = proc(value: string, args: ^byte) -> (ok: bool) {
args := cast(^ProgramArguments)args
args := cast(^ProgramConfig)args
x, x_ok := strconv.parse_int(value, 10)
if !x_ok {
fmt.eprintln("Invalid argument passed to switch 'x'")
return false
}
args.x = x
return true
}
},
{
name = "y",
fullname = "y",
shortname = "y",
description = "set y at which to place the jmap contents at (default: 0)",
no_argument = false,
usage = "-y <value>",
usage = "-y:<value>",
callback = proc(value: string, args: ^byte) -> (ok: bool) {
args := cast(^ProgramArguments)args
args := cast(^ProgramConfig)args
y, y_ok := strconv.parse_int(value, 10)
if !y_ok {
fmt.eprintln("Invalid argument passed to switch 'y'")
return false
}
args.y = y
return true
}
},
{
name = "clear_area",
fullname = "clear_area",
shortname = "clear_area",
description = "clear area where jmap contents are placed",
no_argument = true,
usage = "-clear_area",
callback = proc(value: string, args: ^byte) -> (ok: bool) {
args := cast(^ProgramArguments)args
args := cast(^ProgramConfig)args
args.clear_area = true
return true
}
@ -361,7 +369,14 @@ main :: proc() {
room_resource_path := os.args[2]
jmap_path := os.args[3]
jmap_config_path := os.args[4]
error := program(yyp_resource_path, room_resource_path, jmap_path, jmap_config_path)
config: ProgramConfig
if len(os.args) > 5 {
optional_args := os.args[4:]
if ok := process_switches(switch_definitions[:], optional_args, cast(^byte)&config); !ok {
fmt.println("ERROR: Malformed arguments")
}
}
error := program(yyp_resource_path, room_resource_path, jmap_path, jmap_config_path, config)
if error != nil {
error := error.(ProgramError)
fmt.println("ERROR (", error.type, "):", error.message, sep = "")
@ -395,7 +410,7 @@ program_error_create :: proc(error: ProgramErrorType, message: string, loc := #c
return {type = error, message = message, location = loc}
}
program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_path: string) -> Maybe(ProgramError) {
program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_path: string, program_config: ProgramConfig) -> Maybe(ProgramError) {
yyp_project_string, yyp_project_read_error := os.read_entire_file_from_path(yyp_project_path, context.allocator)
if yyp_project_read_error != nil {
return program_error_create(yyp_project_read_error, fmt.tprint("Couldn't open Gamemaker project at '", yyp_project_path, "'", sep = ""))
@ -493,6 +508,18 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat
room_layer_instances := &((&room_layer["instances"]).(json.Array))
if program_config.clear_area {
for i := 0; i < len(room_layer_instances); i += 1 {
instance := room_layer_instances[i].(json.Object)
x := instance["x"].(json.Float)
y := instance["y"].(json.Float)
if point_in_rectangle(int(x), int(y), program_config.x, program_config.y, JMAP_ROOM_WIDTH, JMAP_ROOM_HEIGHT) {
ordered_remove(room_layer_instances, i)
i -= 1
}
}
}
for jmap_instance in jmap_instance_list {
binding := &jmap_instance_to_gamemaker_binding_map[jmap_instance.object_index]
if len(binding.path) == 0 {
@ -502,7 +529,9 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat
}
continue
}
instance := resource_room_layer_create_instance("v4", "2.0", binding.object_name, 32, 32, binding.path, context.allocator)
x := f64(jmap_instance.x + program_config.x)
y := f64(jmap_instance.y + program_config.y)
instance := resource_room_layer_create_instance("v4", "2.0", binding.object_name, x, y, binding.path, context.allocator)
append(room_layer_instances, instance)
}

45651
rSatoru.yy

File diff suppressed because it is too large Load diff