diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 004c1d938a..d83d41d0e1 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -82,37 +82,38 @@ ErrorOr> Image::try_create_from_bitmap(NonnullRefPtr> Image::try_create_from_pixel_paint_json(JsonObject const& json) { - auto image = TRY(try_create_with_size({ json.get_deprecated("width"sv).to_i32(), json.get_deprecated("height"sv).to_i32() })); + // FIXME: Handle invalid JSON data + auto image = TRY(try_create_with_size({ json.get_i32("width"sv).value_or(0), json.get_i32("height"sv).value_or(0) })); - auto layers_value = json.get_deprecated("layers"sv); - for (auto& layer_value : layers_value.as_array().values()) { + auto layers_value = json.get_array("layers"sv).value(); + for (auto& layer_value : layers_value.values()) { auto const& layer_object = layer_value.as_object(); - auto name = layer_object.get_deprecated("name"sv).as_string(); + auto name = layer_object.get_deprecated_string("name"sv).value(); - auto bitmap_base64_encoded = layer_object.get_deprecated("bitmap"sv).as_string(); + auto bitmap_base64_encoded = layer_object.get_deprecated_string("bitmap"sv).value(); auto bitmap_data = TRY(decode_base64(bitmap_base64_encoded)); auto bitmap = TRY(try_decode_bitmap(bitmap_data)); auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name)); - if (auto const& mask_object = layer_object.get_deprecated("mask"sv); !mask_object.is_null()) { - auto mask_base64_encoded = mask_object.as_string(); + if (auto const& mask_object = layer_object.get_deprecated_string("mask"sv); mask_object.has_value()) { + auto mask_base64_encoded = mask_object.value(); auto mask_data = TRY(decode_base64(mask_base64_encoded)); auto mask = TRY(try_decode_bitmap(mask_data)); TRY(layer->try_set_bitmaps(layer->content_bitmap(), mask)); } - auto width = layer_object.get_deprecated("width"sv).to_i32(); - auto height = layer_object.get_deprecated("height"sv).to_i32(); + auto width = layer_object.get_i32("width"sv).value_or(0); + auto height = layer_object.get_i32("height"sv).value_or(0); if (width != layer->size().width() || height != layer->size().height()) return Error::from_string_literal("Decoded layer bitmap has wrong size"); image->add_layer(*layer); - layer->set_location({ layer_object.get_deprecated("locationx"sv).to_i32(), layer_object.get_deprecated("locationy"sv).to_i32() }); - layer->set_opacity_percent(layer_object.get_deprecated("opacity_percent"sv).to_i32()); - layer->set_visible(layer_object.get_deprecated("visible"sv).as_bool()); - layer->set_selected(layer_object.get_deprecated("selected"sv).as_bool()); + layer->set_location({ layer_object.get_i32("locationx"sv).value_or(0), layer_object.get_i32("locationy"sv).value_or(0) }); + layer->set_opacity_percent(layer_object.get_i32("opacity_percent"sv).value()); + layer->set_visible(layer_object.get_bool("visible"sv).value()); + layer->set_selected(layer_object.get_bool("selected"sv).value()); } return image; diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index bcdb856732..88e4956430 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -1237,15 +1237,15 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr image) if (!value.is_object()) return; auto& json_object = value.as_object(); - auto orientation_value = json_object.get_deprecated("orientation"sv); - if (!orientation_value.is_string()) + auto orientation_value = json_object.get_deprecated_string("orientation"sv); + if (!orientation_value.has_value()) return; - auto offset_value = json_object.get_deprecated("offset"sv); - if (!offset_value.is_number()) + auto offset_value = json_object.get("offset"sv); + if (!offset_value.has_value() || !offset_value->is_number()) return; - auto orientation_string = orientation_value.as_string(); + auto orientation_string = orientation_value.value(); PixelPaint::Guide::Orientation orientation; if (orientation_string == "horizontal"sv) orientation = PixelPaint::Guide::Orientation::Horizontal; @@ -1254,7 +1254,7 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr image) else return; - image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value.to_number())); + image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value->to_number())); }); } diff --git a/Userland/Applications/PixelPaint/ProjectLoader.cpp b/Userland/Applications/PixelPaint/ProjectLoader.cpp index 8dd6ae0791..b26ca0900b 100644 --- a/Userland/Applications/PixelPaint/ProjectLoader.cpp +++ b/Userland/Applications/PixelPaint/ProjectLoader.cpp @@ -34,8 +34,8 @@ ErrorOr ProjectLoader::try_load_from_file(NonnullOwnPtr