diff --git a/main.odin b/main.odin index ce807ac..35c0de2 100644 --- a/main.odin +++ b/main.odin @@ -2,11 +2,11 @@ package main +import "core:encoding/json" import "base:runtime" import "core:os" import "core:math/rand" import "core:fmt" -import "core:encoding/json" import "core:strings" import "core:strconv" import "core:mem" @@ -395,6 +395,7 @@ ProgramErrorError :: enum { ProgramErrorType :: union { ProgramErrorError, JmapObjectListError, + ResourceError, os.Error, json.Error, json.Marshal_Error, @@ -411,26 +412,16 @@ program_error_create :: proc(error: ProgramErrorType, message: string, loc := #c } 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_root, yyp_project_read_error := resource_read(yyp_project_path) 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 = "")) } - yyp_project_json, yyp_project_parse_error := json.parse_bytes(yyp_project_string, allocator = context.allocator) - if yyp_project_parse_error != nil { - return program_error_create(yyp_project_parse_error, "Couldn't parse Gamemaker project json") - } - - room_resource_string, room_resource_read_error := os.read_entire_file_from_path(room_resource_path, context.allocator) + room_resource, room_resource_read_error := resource_read(room_resource_path) if room_resource_read_error != nil { return program_error_create(room_resource_read_error, fmt.tprint("Couldn't open GameMaker room resource at '", room_resource_path, "'", sep = "")) } - room_resource_json, room_resource_parse_error := json.parse_bytes(room_resource_string, allocator = context.allocator) - if room_resource_parse_error != nil { - return program_error_create(room_resource_parse_error ,"Failed to parse yyp project json") - } - jmap_json, 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 = "")) @@ -485,7 +476,7 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat } for key, &binding in jmap_instance_to_gamemaker_binding_map { - resource := resource_project_find_asset(yyp_project_json.(json.Object), binding.object_name, .Object) + resource := resource_project_find_asset(yyp_project_root, binding.object_name, .Object) if resource == nil { if binding.changed { fmt.eprintln("WARNING: Resource for jmap object '", binding.jmap_object_name, "' couldn't be found in project file (looked for '", binding.object_name, "')", sep = "") @@ -495,7 +486,6 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat binding.path = resource.(json.Object)["id"].(json.Object)["path"].(json.String) } - room_resource := &room_resource_json.(json.Object) room_layers := &(&room_resource["layers"]).(json.Array) room_layer, room_layer_found := resource_room_get_by_name(room_layers, jmap_config.layer) @@ -535,7 +525,7 @@ program :: proc(yyp_project_path, room_resource_path, jmap_path, jmap_config_pat append(room_layer_instances, instance) } - room_resource_after, room_resource_after_marshal_error := json.marshal(room_resource_json, GAMEMAKER_RESOURCE_JSON5_MARSHAL_OPTIONS) + room_resource_after, room_resource_after_marshal_error := json.marshal(room_resource, GAMEMAKER_RESOURCE_JSON5_MARSHAL_OPTIONS) if room_resource_after_marshal_error != nil { return program_error_create(room_resource_after_marshal_error, "Failed to convert marshal room data to resource") } diff --git a/notes.txt b/notes.txt deleted file mode 100644 index e69de29..0000000 diff --git a/rSatoru-original.yy b/rSatoru-original.yy new file mode 100644 index 0000000..96fcc43 --- /dev/null +++ b/rSatoru-original.yy @@ -0,0 +1,128 @@ +{ + "$GMRoom":"v1", + "%Name":"rSatoru", + "creationCodeFile":"", + "inheritCode":false, + "inheritCreationOrder":false, + "inheritLayers":false, + "instanceCreationOrder":[ + {"name":"inst_1B57A8DE","path":"rooms/rSatoru/rSatoru.yy",}, + {"name":"inst_24A5E355","path":"rooms/rSatoru/rSatoru.yy",}, + ], + "isDnd":false, + "layers":[ + {"$GMRInstanceLayer":"","%Name":"Instances","depth":0,"effectEnabled":true,"effectType":null,"gridX":32,"gridY":32,"hierarchyFrozen":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"inheritSubLayers":true,"inheritVisibility":true,"instances":[ + {"$GMRInstance":"v4","%Name":"inst_1B57A8DE","colour":4294967295,"frozen":false,"hasCreationCode":false,"ignore":false,"imageIndex":0,"imageSpeed":1.0,"inheritCode":false,"inheritedItemId":null,"inheritItemSettings":false,"isDnd":false,"name":"inst_1B57A8DE","objectId":{"name":"objSave","path":"objects/objSave/objSave.yy",},"properties":[],"resourceType":"GMRInstance","resourceVersion":"2.0","rotation":0.0,"scaleX":1.0,"scaleY":1.0,"x":896.0,"y":1984.0,}, + {"$GMRInstance":"v4","%Name":"inst_24A5E355","colour":4294967295,"frozen":false,"hasCreationCode":false,"ignore":false,"imageIndex":0,"imageSpeed":1.0,"inheritCode":false,"inheritedItemId":null,"inheritItemSettings":false,"isDnd":false,"name":"inst_24A5E355","objectId":{"name":"objPlayerStart","path":"objects/objPlayerStart/objPlayerStart.yy",},"properties":[],"resourceType":"GMRInstance","resourceVersion":"2.0","rotation":0.0,"scaleX":1.0,"scaleY":1.0,"x":928.0,"y":1312.0,}, + ],"layers":[],"name":"Instances","properties":[],"resourceType":"GMRInstanceLayer","resourceVersion":"2.0","userdefinedDepth":false,"visible":true,}, + {"$GMRTileLayer":"","%Name":"Tiles","depth":100,"effectEnabled":true,"effectType":null,"gridX":32,"gridY":32,"hierarchyFrozen":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"inheritSubLayers":true,"inheritVisibility":true,"layers":[],"name":"Tiles","properties":[],"resourceType":"GMRTileLayer","resourceVersion":"2.0","tiles":{"SerialiseHeight":190,"SerialiseWidth":150,"TileCompressedData":[ + -54,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648,-3,0,2,18, + 19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648,-3,0,2, + 18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648,-3, + 0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,5,2,3,0,0,-2147483648,-3,0,2,2,3,-140,-2147483648,5,18,19,0,0,-2147483648, + -3,0,2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,4,18,19,0,0,-4,-2147483648, + 2,18,19,-140,-2147483648,4,2,3,0,0,-4,-2147483648,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648, + 2,18,19,-6,0,2,18,19,-140,-2147483648,2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-140,-2147483648, + 2,2,3,-6,0,2,2,3,-140,-2147483648,2,18,19,-6,0,2,18,19,-136,-2147483648,6,2,3,2,3,2,3,-6,0,2,2,3,-136, + -2147483648,6,18,19,18,19,18,19,-6,0,2,18,19,-136,-2147483648,-2,0,-4,-2147483648,-6,0,2,2,3,-4,-2147483648, + 2,2,3,-8,-2147483648,2,2,3,-8,-2147483648,4,2,3,2,3,-108,-2147483648,-2,0,-6,-2147483648,-4,0,2,18,19, + -4,-2147483648,2,18,19,-8,-2147483648,2,18,19,-8,-2147483648,4,18,19,18,19,-108,-2147483648,-2,0,-6, + -2147483648,-4,0,2,2,3,-4,-2147483648,4,2,3,2,3,-4,-2147483648,4,2,3,2,3,-8,-2147483648,2,2,3,-110,-2147483648, + -2,0,-6,-2147483648,-4,0,2,18,19,-4,-2147483648,4,18,19,18,19,-4,-2147483648,4,18,19,18,19,-8,-2147483648, + 2,18,19,-110,-2147483648,-2,0,-10,-2147483648,4,2,3,2,3,-10,-2147483648,2,2,3,-122,-2147483648,-2,0, + -10,-2147483648,4,18,19,18,19,-10,-2147483648,2,18,19,-122,-2147483648,-2,0,-148,-2147483648,-2,0,-34, + -2147483648,2,2,3,-112,-2147483648,-2,0,-25,-2147483648,5,0,2,3,2,3,-4,-2147483648,2,18,19,-112,-2147483648, + -2,0,-25,-2147483648,5,0,18,19,18,19,-118,-2147483648,-2,0,-15,-2147483648,4,2,3,2,3,-129,-2147483648, + -2,0,-15,-2147483648,4,18,19,18,19,-129,-2147483648,-2,0,10,2,3,2,3,2,3,2,3,2,3,-7,-2147483648,6,2,3, + 2,3,2,3,-125,-2147483648,-2,0,10,18,19,18,19,18,19,18,19,18,19,-7,-2147483648,6,18,19,18,19,18,19,-125, + -2147483648,12,2,3,2,3,2,3,2,3,2,3,2,3,-138,-2147483648,12,18,19,18,19,18,19,18,19,18,19,18,19,-138, + -2147483648,8,2,3,2,3,2,3,2,3,-142,-2147483648,8,18,19,18,19,18,19,18,19,-142,-2147483648,6,2,3,2,3, + 2,3,-144,-2147483648,6,18,19,18,19,18,19,-144,-2147483648,6,2,3,2,3,2,3,-144,-2147483648,6,18,19,18, + 19,18,19,-144,-2147483648,4,2,3,2,3,-146,-2147483648,4,18,19,18,19,-146,-2147483648,4,2,3,2,3,-44,-2147483648, + 2,2,3,-100,-2147483648,4,18,19,18,19,-44,-2147483648,2,18,19,-100,-2147483648,4,2,3,2,3,-146,-2147483648, + 4,18,19,18,19,-146,-2147483648,4,2,3,2,3,-146,-2147483648,4,18,19,18,19,-146,-2147483648,4,2,3,2,3,-146, + -2147483648,4,18,19,18,19,-146,-2147483648,4,2,3,2,3,-44,-2147483648,2,2,3,-100,-2147483648,4,18,19, + 18,19,-44,-2147483648,2,18,19,-100,-2147483648,4,2,3,2,3,-146,-2147483648,4,18,19,18,19,-146,-2147483648, + 4,2,3,2,3,-146,-2147483648,4,18,19,18,19,-5796,-2147483648, + ],"TileDataFormat":1,},"tilesetId":{"name":"tilSatoru","path":"tilesets/tilSatoru/tilSatoru.yy",},"userdefinedDepth":false,"visible":true,"x":0,"y":0,}, + {"$GMRBackgroundLayer":"","%Name":"Background","animationFPS":15.0,"animationSpeedType":0,"colour":4278190080,"depth":200,"effectEnabled":true,"effectType":null,"gridX":32,"gridY":32,"hierarchyFrozen":false,"hspeed":0.0,"htiled":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"inheritSubLayers":true,"inheritVisibility":true,"layers":[],"name":"Background","properties":[],"resourceType":"GMRBackgroundLayer","resourceVersion":"2.0","spriteId":null,"stretch":false,"userdefinedAnimFPS":false,"userdefinedDepth":false,"visible":true,"vspeed":0.0,"vtiled":false,"x":0,"y":0,}, + ], + "name":"rSatoru", + "parent":{ + "name":"Satoru", + "path":"folders/Game/Rooms/Satoru.yy", + }, + "parentRoom":null, + "physicsSettings":{ + "inheritPhysicsSettings":false, + "PhysicsWorld":false, + "PhysicsWorldGravityX":0.0, + "PhysicsWorldGravityY":10.0, + "PhysicsWorldPixToMetres":0.1, + }, + "resourceType":"GMRoom", + "resourceVersion":"2.0", + "roomSettings":{ + "Height":3040, + "inheritRoomSettings":false, + "persistent":false, + "Width":2400, + }, + "sequenceId":null, + "views":[ + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":true,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":800,"yport":0,"yview":1824,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + {"hborder":32,"hport":608,"hspeed":-1,"hview":608,"inherit":false,"objectId":null,"vborder":32,"visible":false,"vspeed":-1,"wport":800,"wview":800,"xport":0,"xview":0,"yport":0,"yview":0,}, + ], + "viewSettings":{ + "clearDisplayBuffer":true, + "clearViewBackground":false, + "enableViews":true, + "inheritViewSettings":false, + }, + "volume":1.0, +} diff --git a/rSatoru.yy b/rSatoru.yy index 5a408e4..96fcc43 100644 --- a/rSatoru.yy +++ b/rSatoru.yy @@ -125,4 +125,4 @@ "inheritViewSettings":false, }, "volume":1.0, -} \ No newline at end of file +}