switch functionality and bug fixes
This commit is contained in:
parent
05ec5bf38f
commit
d0467eb0c6
3 changed files with 45629 additions and 141 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"label": "Test run",
|
"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",
|
"label": "Build debug",
|
||||||
|
|
|
||||||
55
main.odin
55
main.odin
|
|
@ -4,7 +4,6 @@ package main
|
||||||
|
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:math"
|
|
||||||
import "core:math/rand"
|
import "core:math/rand"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:encoding/json"
|
import "core:encoding/json"
|
||||||
|
|
@ -12,6 +11,16 @@ import "core:strings"
|
||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
import "core:mem"
|
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
|
SWITCHES
|
||||||
*/
|
*/
|
||||||
|
|
@ -295,7 +304,7 @@ HELP_MESSAGE :: """
|
||||||
Usage: <program> <yyp_resource_path> <room_resource_path> <jmap_path> <jmap_config_path> [other flags...]
|
Usage: <program> <yyp_resource_path> <room_resource_path> <jmap_path> <jmap_config_path> [other flags...]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ProgramArguments :: struct {
|
ProgramConfig :: struct {
|
||||||
x, y: int,
|
x, y: int,
|
||||||
clear_area: bool,
|
clear_area: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -304,46 +313,45 @@ switch_definitions := []SwitchDefinition {
|
||||||
{
|
{
|
||||||
name = "x",
|
name = "x",
|
||||||
fullname = "x",
|
fullname = "x",
|
||||||
shortname = "x",
|
|
||||||
description = "set x at which to place the jmap contents at (default: 0)",
|
description = "set x at which to place the jmap contents at (default: 0)",
|
||||||
no_argument = false,
|
no_argument = false,
|
||||||
usage = "-x <value>",
|
usage = "-x:<value>",
|
||||||
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
||||||
args := cast(^ProgramArguments)args
|
args := cast(^ProgramConfig)args
|
||||||
x, x_ok := strconv.parse_int(value, 10)
|
x, x_ok := strconv.parse_int(value, 10)
|
||||||
if !x_ok {
|
if !x_ok {
|
||||||
fmt.eprintln("Invalid argument passed to switch 'x'")
|
fmt.eprintln("Invalid argument passed to switch 'x'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
args.x = x
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = "y",
|
name = "y",
|
||||||
fullname = "y",
|
fullname = "y",
|
||||||
shortname = "y",
|
|
||||||
description = "set y at which to place the jmap contents at (default: 0)",
|
description = "set y at which to place the jmap contents at (default: 0)",
|
||||||
no_argument = false,
|
no_argument = false,
|
||||||
usage = "-y <value>",
|
usage = "-y:<value>",
|
||||||
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
||||||
args := cast(^ProgramArguments)args
|
args := cast(^ProgramConfig)args
|
||||||
y, y_ok := strconv.parse_int(value, 10)
|
y, y_ok := strconv.parse_int(value, 10)
|
||||||
if !y_ok {
|
if !y_ok {
|
||||||
fmt.eprintln("Invalid argument passed to switch 'y'")
|
fmt.eprintln("Invalid argument passed to switch 'y'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
args.y = y
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = "clear_area",
|
name = "clear_area",
|
||||||
fullname = "clear_area",
|
fullname = "clear_area",
|
||||||
shortname = "clear_area",
|
|
||||||
description = "clear area where jmap contents are placed",
|
description = "clear area where jmap contents are placed",
|
||||||
no_argument = true,
|
no_argument = true,
|
||||||
usage = "-clear_area",
|
usage = "-clear_area",
|
||||||
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
callback = proc(value: string, args: ^byte) -> (ok: bool) {
|
||||||
args := cast(^ProgramArguments)args
|
args := cast(^ProgramConfig)args
|
||||||
args.clear_area = true
|
args.clear_area = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +369,14 @@ main :: proc() {
|
||||||
room_resource_path := os.args[2]
|
room_resource_path := os.args[2]
|
||||||
jmap_path := os.args[3]
|
jmap_path := os.args[3]
|
||||||
jmap_config_path := os.args[4]
|
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 {
|
if error != nil {
|
||||||
error := error.(ProgramError)
|
error := error.(ProgramError)
|
||||||
fmt.println("ERROR (", error.type, "):", error.message, sep = "")
|
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}
|
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)
|
yyp_project_string, yyp_project_read_error := os.read_entire_file_from_path(yyp_project_path, context.allocator)
|
||||||
if yyp_project_read_error != nil {
|
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 = ""))
|
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))
|
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 {
|
for jmap_instance in jmap_instance_list {
|
||||||
binding := &jmap_instance_to_gamemaker_binding_map[jmap_instance.object_index]
|
binding := &jmap_instance_to_gamemaker_binding_map[jmap_instance.object_index]
|
||||||
if len(binding.path) == 0 {
|
if len(binding.path) == 0 {
|
||||||
|
|
@ -502,7 +529,9 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat
|
||||||
}
|
}
|
||||||
continue
|
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)
|
append(room_layer_instances, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
45651
rSatoru.yy
45651
rSatoru.yy
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue