commit ab524834d67d81286b6cfc116f9aa7b4093342b5 Author: Synthasmagoria Date: Wed Nov 11 14:23:36 2026 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db21dde --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +gamemaker_jmap_import diff --git a/.zed/tasks.json b/.zed/tasks.json new file mode 100644 index 0000000..a47abfb --- /dev/null +++ b/.zed/tasks.json @@ -0,0 +1,10 @@ +[ + { + "label": "Test run", + "command": "odin run . -- ../Satoru-Gojo-Needle/Satoru-Gojo-Needle.yyp jmap.jmap jmap_config.json5", + }, + { + "label": "Build debug", + "command": "odin build . -debug", + } +] diff --git a/debug.raddbg b/debug.raddbg new file mode 100755 index 0000000..45a79c0 --- /dev/null +++ b/debug.raddbg @@ -0,0 +1,9 @@ +// raddbg 0.9.30 project file + +target: +{ + executable: gamemaker_jmap_import + working_directory: "" + enabled: 1 + arguments: "../Satoru-Gojo-Needle/Satoru-Gojo-Needle.yyp jmap.jmap jmap_config.json5" +} diff --git a/gamemaker_jmap_import.rdi b/gamemaker_jmap_import.rdi new file mode 100755 index 0000000..010e6e2 Binary files /dev/null and b/gamemaker_jmap_import.rdi differ diff --git a/jmap.jmap b/jmap.jmap new file mode 100644 index 0000000..b09f805 --- /dev/null +++ b/jmap.jmap @@ -0,0 +1,12 @@ +jtool|1.111.6|inf:0|dot:0|bor:0|px:40ug000000000|py:40ujmcpg00000|ps:1|pg:1|objects:-c02b02bg13g39g6m037044g35g-bg2mg2m01d01c01e01kg9bg6g068g-eg1s01m01n01kg1b08903c06d06e03j0ch0c40ndg-fg1s01r01n01o01kg1k01h01i01j01406m05g03f0350-ig1q01o01i03r05p03n0ij03k06f0680390nj0-mg1q01p01n01h01j01i01k01f01e01c01b01a019017g16g-lg1p01h01i01k01n01j01f01e01c01a019016giq057g3b0nq0-hg1o01g01b01f01e01d01c05s04m05l04i05a0fi0nl0-kg1i01j01k01e01c0190ge05p03h03f06a036gcn0-m01lg150140-l01lg140c50-k01lgac0340-jg1n01k01j01i01906o04h05g03e06d05b0ng0-gg1o01f0140150hf06r05n04k05j03c06d03e0cg0cb0-dg1kg1c01b01d01e01h03m06f05g06i0-i028g280650670-h0180140170150-b02d02cg2c02gg2g0150g507eg-cg1d01c01b01e01kg3f0ii06j05h0ni0-9g1cg1eg8dg5dgaj03ag38g-g018017069g-f018019g1707k09904g0-a01g01h01s01508dg670-ag1j01sg1rg1qg1pg1og1ng1mg1lg1kg1ag18gi9g7c03dg5i04h0n9g-701i01jg-402j01jg1eg1fg1dg-4g2j01kg19g18g2qg2q02p82oo2o82n02mg6cg3bg-502j01jg1fg1dg2r02q02p82o82mg5i04gg-5g2j018g2r02q02o82mg6kg39g-901s01jg1501601703h0cg0-3g1kg1cg19g-801jg6i03s0-601jg2r02q02p82o82ng2mg6dg-7g1fg1eg17g18g19g4gg6cg4ag-8g1eg1cg69gf9g-7o2qg2r02q02p82ng2n02mg2l82ko-882r02q02p82ng2mg2ko-8o2r02q02p82ng2mg2ko-982r02q02p82o82ng2mg2lo2ko-9o2r02qg2q02p82oo2o82ng2n02mg2lo2l82ko-6g18g2qg2q02p82oo2o82ng2n02mg4i05h03eg3cg6bgcfgc9g-e019g18017065g-d019g17013gk80lpgc80f5g-j01503lg460-582p8-5o2p8 + +data repeated below for easy parsing by other tools +objects: (x, y, type) +224 256 2 240 256 2 592 240 2 576 240 2 768 336 1 768 368 1 736 368 1 704 464 1 704 592 1 672 592 1 672 560 1 640 432 1 640 464 1 608 592 1 416 560 1 416 592 1 480 592 1 448 592 1 448 560 1 448 528 1 512 592 1 512 560 1 608 560 1 560 576 1 560 544 1 560 512 1 608 496 1 576 336 1 608 336 1 608 368 1 640 368 1 640 400 1 528 368 1 528 336 1 528 304 1 480 560 1 480 528 1 512 528 1 512 496 1 512 368 1 480 496 1 448 496 1 448 464 1 352 592 1 352 560 1 384 432 1 320 528 1 320 592 1 320 560 1 256 592 1 256 560 1 224 592 1 192 592 1 192 560 1 160 592 1 160 560 1 256 528 1 112 592 1 160 528 1 160 496 1 144 448 2 128 448 2 128 416 1 288 224 2 288 240 1 288 272 1 272 224 2 256 224 2 256 240 1 256 272 1 224 272 1 272 176 1 320 240 1 128 384 1 128 352 1 176 352 1 256 304 1 224 304 1 224 336 1 224 432 1 352 432 1 320 432 1 288 432 1 256 432 1 288 304 1 320 272 1 320 304 1 352 400 1 416 304 1 416 368 1 448 368 1 480 368 1 528 272 1 528 240 1 400 224 2 384 224 2 384 192 1 416 192 1 480 208 1 448 96 1 480 0 2 480 16 2 480 32 2 480 48 2 768 192 1 768 160 1 528 -16 1 528 16 1 784 208 1 752 208 1 720 208 1 688 208 1 656 208 1 624 208 1 592 208 1 560 208 1 528 208 1 496 160 1 496 128 1 496 96 1 496 64 1 496 32 1 496 0 1 336 0 1 368 32 1 368 0 1 368 112 1 304 0 1 304 32 1 336 176 1 336 144 1 336 112 1 272 144 1 272 -16 1 176 -16 1 176 16 1 144 16 1 144 48 1 720 120 2 736 120 2 736 136 2 736 152 2 736 168 2 736 184 2 720 184 2 704 168 2 704 184 2 704 152 2 704 136 2 704 120 2 680 120 2 680 136 2 680 152 2 680 168 2 680 184 2 664 184 2 648 168 2 648 184 2 624 120 2 608 120 2 624 136 2 624 152 2 624 168 2 624 184 2 608 184 2 592 184 2 592 168 2 592 152 2 592 136 2 592 120 2 568 168 2 568 184 2 552 120 2 552 184 2 536 184 2 536 168 2 536 152 2 536 136 2 536 120 2 144 80 1 208 208 1 112 112 1 144 112 1 176 112 1 176 320 1 176 288 1 144 208 1 32 192 1 32 160 1 64 160 1 96 160 1 96 288 1 128 320 1 96 320 1 96 352 1 32 224 1 -16 288 1 -16 256 1 0 416 1 96 384 1 96 416 1 0 400 1 0 368 1 32 416 1 32 400 1 32 480 1 80 592 1 80 560 1 0 544 1 32 576 1 0 576 1 736 64 2 736 48 2 736 32 2 720 16 2 720 80 2 704 80 2 704 64 2 704 48 2 704 32 2 704 16 2 680 32 2 680 16 2 664 16 2 680 40 2 680 56 2 680 64 2 680 80 2 664 80 2 648 80 2 648 64 2 648 48 2 648 32 2 648 16 2 624 64 2 624 80 2 608 80 2 592 80 2 608 16 2 592 64 2 592 48 2 592 32 2 592 16 2 320 528 16 352 400 17 32 224 16 176 208 18 176 256 3 240 240 9 576 256 6 576 304 3 768 432 5 736 400 6 736 464 3 704 560 18 672 464 5 672 528 5 640 496 6 112 560 5 416 496 4 416 528 3 560 480 3 608 464 3 576 368 6 608 400 5 576 432 4 512 352 7 480 464 18 512 464 3 544 432 5 512 400 4 480 400 5 448 432 4 384 496 5 352 464 6 320 496 3 352 528 3 288 496 6 224 560 3 256 512 10 224 496 5 192 528 6 128 464 6 160 464 3 256 208 7 336 224 7 304 208 3 304 176 8 304 192 8 304 176 5 160 336 8 160 352 9 176 384 6 192 432 5 256 400 3 256 336 3 288 400 6 288 336 6 320 336 6 320 400 3 352 272 3 384 368 5 352 368 3 352 304 6 384 352 4 384 304 5 448 304 6 480 336 3 448 272 18 480 272 6 448 208 5 416 208 4 416 272 5 384 240 6 416 160 3 480 176 10 448 128 6 448 32 5 448 80 4 416 80 5 400 32 4 400 112 4 768 128 3 528 48 6 336 80 3 272 112 6 304 64 6 272 16 6 272 80 3 240 16 3 176 48 3 240 80 6 208 176 3 208 112 4 176 144 6 144 176 3 144 240 6 96 192 6 96 256 3 16 256 4 48 256 3 48 320 6 32 368 3 32 448 6 96 448 6 64 480 4 80 528 3 0 512 3 128 288 20 32 544 12 688 288 21 608 528 12 384 400 12 224 400 12 416 336 12 384 160 12 368 80 12 176 80 12 128 288 12 0 336 12 448 432 15 176 144 15 176 208 23 704 560 23 480 464 23 544 432 23 384 496 23 304 336 23 448 272 23 48 288 15 +version:1.111.6 +infinitejump:0 +dotkid:0 +bordertype:0 +playersavex:416 +playersavey:423.3999938964843700 +playersavexscale:1 diff --git a/jmap_config.json5 b/jmap_config.json5 new file mode 100644 index 0000000..e149d10 --- /dev/null +++ b/jmap_config.json5 @@ -0,0 +1,4 @@ +spikeUp: { + layer: "Threats", + object_index: "objSpikeUp", +} diff --git a/main.odin b/main.odin new file mode 100644 index 0000000..a37d9ef --- /dev/null +++ b/main.odin @@ -0,0 +1,382 @@ +package main + +import "base:runtime" +import "core:os" +import "core:fmt" +import "core:encoding/json" +import "core:strings" +import "core:strconv" +import "core:mem" + +/* ### + SWITCHES +*/ +SwitchDefinition :: struct { + name: string, + fullname: string, + shortname: string, + usage: string, + description: string, + no_argument: bool, + callback: proc(value: string, args: ^byte) -> (ok: bool), +} + +SwitchSplitError :: enum { + None, + Empty, + MissingDash, + MissingStartQuote, + MissingEndQuote, +} + +switch_split :: proc(str: string) -> (name, value: string, err: SwitchSplitError) { + name = "" + value = "" + err = .None + + if len(str) == 0 { + err = .Empty + return + } + if str[0] != '-' { + err = .MissingDash + return + } + colon_index := strings.index_rune(str, ':') + if colon_index == -1 { + name = str[1:] + return + } + name = str[1:colon_index] + value = str[colon_index + 1:] + if value[0] != '"' && value[len(value) - 1] == '"' { + err = .MissingStartQuote + return + } else if value[0] == '"' && value[len(value) - 1] != '"' { + err = .MissingEndQuote + return + } + if value[0] == '"' && value[len(value) - 1] == '"' { + value = value[1:len(value) - 2] + } + return +} + +process_switches :: proc(switch_definitions: []SwitchDefinition, args: []string, args_out: ^byte, temp_allocator := context.temp_allocator) -> (_ok: bool) { + _ok = true + error_state: bool + switch_map := make(map[string]SwitchDefinition, temp_allocator) + for switch_definition in switch_definitions { + shortname := switch_definition.shortname + shortname_length := len(shortname) + if shortname_length > 0 { + if shortname in switch_map { + _ok = false + existing_switch_definition := switch_map[shortname] + fmt.eprintln("Argument error: Switch for ", switch_definition.name, " (", shortname, ") already existed for '", existing_switch_definition.name, sep = "") + } else { + switch_map[shortname] = switch_definition + } + } + + fullname := switch_definition.fullname + fullname_length := len(fullname) + if fullname_length > 0 { + if fullname in switch_map { + _ok = false + existing_switch_definition := switch_map[fullname] + fmt.eprintln("Argument error: Switch for ", switch_definition.name, " (", fullname, ") already existed for '", existing_switch_definition.name, sep = "") + } else { + switch_map[fullname] = switch_definition + } + } + + if shortname_length == 0 && fullname_length == 0 { + _ok = false + fmt.eprintln("Switch definition error: ", switch_definition.name, " had no shortname or fullname", sep = "") + } + } + for arg in args[1:] { + name, value, err := switch_split(arg) + if err != .None { + _ok = false + fmt.eprintln("Argument error: ", err, " (", arg, ")", sep = "") + continue + } + if name not_in switch_map { + _ok = false + fmt.eprintln("Argument error: Non-existent switch", name, sep = "") + continue + } + switch_map[name].callback(value, args_out) + } + return _ok +} + +/* ### + GAMEMAKER RESOURCE HANDLING +*/ + +GAMEMAKER_RESOURCE_JSON5_MARSHAL_OPTIONS :: json.Marshal_Options { + spec = .JSON5, + pretty = true, + sort_maps_by_key = true, + indentation = 0, + spaces = 4, + use_spaces = true, +} + +ResourceError :: union { + os.Error, + json.Error, + json.Marshal_Error, +} + +ResourceType :: enum { + Extension, + Font, + Note, + Object, + Particle, + Path, + Room, + Script, + Sequence, + Shader, + Sound, + Sprite, + Tileset, +} + +@rodata resource_type_folder_names := [ResourceType]string { + .Extension = "extensions", + .Font = "fonts", + .Note = "notes", + .Object = "objects", + .Particle = "particles", + .Path = "paths", + .Room = "rooms", + .Script = "scripts", + .Sequence = "sequences", + .Shader = "shaders", + .Sound = "sound", + .Sprite = "sprites", + .Tileset = "tilesets", +} + +RoomLayerType :: enum { + Background, + Instance, + Tile, + Path, + Asset, + Effects, + UI, + _Invalid, +} + +@rodata room_layer_type_identifier := [RoomLayerType]string { + .Background = "GMRBackgroundLayer", + .Instance = "GMRInstanceLayer", + .Tile = "GMRTileLayer", + .Path = "GMRPathLayer", + .Asset = "GMRAssetLayer", + .Effects = "GMREffectsLayer", + .UI = "GMRUiLayer", + ._Invalid = "", +} + +resource_read :: proc(path: string) -> (object: json.Object, err: ResourceError) { + data := os.read_entire_file(path, context.allocator) or_return + resource := json.parse(data, .JSON5, true) or_return + object = resource.(json.Object) + return +} + +resource_write :: proc(path: string, data: json.Value) -> ResourceError { + str := json.marshal(data, GAMEMAKER_RESOURCE_JSON5_MARSHAL_OPTIONS) or_return + os.write_entire_file(path, str) or_return + return nil +} + +resource_get_version :: proc(resource: json.Object) -> string { + return resource["resourceVersion"].(json.String) +} + +resource_project_find_asset :: proc(project: json.Object, name: string, type: ResourceType) -> json.Value { + resources := project["resources"].(json.Array) + for resource in resources { + id := resource.(json.Object)["id"].(json.Object) + if id["name"].(json.String) != name { + continue + } + if strings.split(id["path"].(json.String), "/")[0] != resource_type_folder_names[type] { + continue + } + return resource + } + return nil +} + +resource_room_layer_get_type :: proc(layer: json.Object) -> RoomLayerType { + type_name := layer["resourceType"].(json.String) + for type in RoomLayerType { + if type_name == room_layer_type_identifier[type] { + return type + } + } + return ._Invalid +} + +resource_path_is_type :: proc(path: string, type: ResourceType) -> bool { + path := strings.split(path, "/") + return path[0] == resource_type_folder_names[type] +} + +/* ### + PROGRAM +*/ + +/* ### + PROGRAM +*/ + +HELP_MESSAGE :: """ +--- GAMEMAKER JMAP IMPORTER --- +Usage: [other flags...] +""" + +main :: proc() { + args := os.args + switch len(args) { + case 0, 1, 2, 3: + fmt.println("ERROR: Too few arguments") + fmt.println(HELP_MESSAGE) + case: + yyp_path := os.args[1] + jmap_path := os.args[2] + jmap_config_path := os.args[3] + error := program(yyp_path, jmap_path, jmap_config_path) + if error != nil { + error := error.(ProgramError) + fmt.println("ERROR:", error.message) + fmt.println(error.location) + } + } +} + +ProgramErrorError :: enum { + JmapBadObjectList, +} + +ProgramErrorType :: union { + ProgramErrorError, + JmapObjectListError, + os.Error, + json.Error +} + +ProgramError :: struct { + type: ProgramErrorType, + message: string, + location: runtime.Source_Code_Location, +} + +program_error_create :: proc(error: ProgramErrorType, message: string, loc := #caller_location) -> ProgramError { + return {type = error, message = message, location = loc} +} + +program :: proc(yyp_path, jmap_path, jmap_config_path: string) -> Maybe(ProgramError) { + yyp_string, yyp_read_error := os.read_entire_file_from_path(yyp_path, context.allocator) + if yyp_read_error != nil { + return program_error_create(yyp_read_error, fmt.tprint("Couldn't open GameMaker project path at '", yyp_path, "'", sep = "")) + } + + yyp, yyp_parse_error := json.parse_bytes(yyp_string, allocator = context.allocator) + if yyp_parse_error != nil { + return program_error_create(yyp_parse_error ,"Failed to parse yyp project json") + } + + jmap, jmap_read_error := os.read_entire_file_from_path(jmap_path, context.allocator) + if jmap_read_error != nil { + return program_error_create(jmap_read_error, fmt.tprint("Couldn't open jmap path at '", jmap_path, "'", sep = "")) + } + + jmap_object_list, jmap_object_list_error := jmap_object_list_from_text(string(jmap), context.allocator, context.temp_allocator) + switch jmap_object_list_error { + case .None: + case .NoStartMarker: + return program_error_create(jmap_object_list_error, "Couldn't find start marker in jmap") + case .NoEndMarker: + return program_error_create(jmap_object_list_error, "Couldn't find end marker in jmap") + case .BadListLength: + return program_error_create(jmap_object_list_error, "Object list was not of a correct length") + case .BadObject: + return program_error_create(jmap_object_list_error, "Bad object in jmap object list") + } + + fmt.println(jmap_object_list) + + jmap_config_text, jmap_config_read_error := os.read_entire_file_from_path(jmap_config_path, allocator = context.allocator) + if jmap_config_read_error != nil { + return program_error_create(jmap_read_error, fmt.tprint("Couldn't open jmap config path at '", jmap_config_path, "'", sep = "")) + } + return nil +} + +JmapObjectListError :: enum { + None, + NoStartMarker, + NoEndMarker, + BadListLength, + BadObject, +} + +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 +}