mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
PixelPaint: Replace uses of JsonObject::get_deprecated()/get_ptr()
This commit is contained in:
parent
ecbe317413
commit
c36de98223
3 changed files with 22 additions and 21 deletions
|
@ -82,37 +82,38 @@ ErrorOr<NonnullRefPtr<Image>> Image::try_create_from_bitmap(NonnullRefPtr<Gfx::B
|
|||
|
||||
ErrorOr<NonnullRefPtr<Image>> 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;
|
||||
|
|
|
@ -1237,15 +1237,15 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> 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> image)
|
|||
else
|
||||
return;
|
||||
|
||||
image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value.to_number<float>()));
|
||||
image_editor.add_guide(PixelPaint::Guide::construct(orientation, offset_value->to_number<float>()));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ ErrorOr<void> ProjectLoader::try_load_from_file(NonnullOwnPtr<Core::Stream::File
|
|||
auto& json = json_or_error.value().as_object();
|
||||
auto image = TRY(Image::try_create_from_pixel_paint_json(json));
|
||||
|
||||
if (json.has("guides"sv))
|
||||
m_json_metadata = json.get_deprecated("guides"sv).as_array();
|
||||
if (json.has_array("guides"sv))
|
||||
m_json_metadata = json.get_array("guides"sv).value();
|
||||
|
||||
m_image = image;
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue