-module(dfjson). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([encode_particle_cluster/1, encode_particle_data/1, encode_df_json/1, particle_cluster_decoder/0, particle_data_decoder/0, df_json_decoder/0]). -export_type([df_json/0, particle_cluster/0, particle_data/0]). -type df_json() :: {dict, gleam@dict:dict(binary(), df_json())} | {list, list(df_json())} | {comp, binary()} | {str, binary()} | {num, float()} | {loc, float(), float(), float(), float(), float()} | {vec, float(), float(), float()} | {sound, binary(), gleam@option:option(binary()), float(), float()} | {custom_sound, binary(), float(), float()} | {particle, binary(), particle_cluster(), particle_data()} | {potion, binary(), integer(), integer()}. -type particle_cluster() :: {particle_cluster, float(), float(), integer()}. -type particle_data() :: {particle_data, gleam@option:option(float()), gleam@option:option(float()), gleam@option:option(float()), gleam@option:option(float()), gleam@option:option(float()), gleam@option:option(float()), gleam@option:option(binary()), gleam@option:option(float()), gleam@option:option(binary()), gleam@option:option(float()), gleam@option:option(binary()), gleam@option:option(float())}. -file("src/dfjson.gleam", 116). -spec encode_particle_cluster(particle_cluster()) -> gleam@json:json(). encode_particle_cluster(Particle_cluster) -> {particle_cluster, Horizontal, Vertical, Amount} = Particle_cluster, gleam@json:object( [{<<"horizontal"/utf8>>, gleam@json:float(Horizontal)}, {<<"vertical"/utf8>>, gleam@json:float(Vertical)}, {<<"amount"/utf8>>, gleam@json:int(Amount)}] ). -file("src/dfjson.gleam", 125). -spec encode_particle_data(particle_data()) -> gleam@json:json(). encode_particle_data(Particle_data) -> {particle_data, X, Y, Z, Motion_variation, Size, Size_variation, Color, Color_variation, Color_fade, Roll, Material, Opacity} = Particle_data, gleam@json:object([{<<"x"/utf8>>, case X of none -> gleam@json:null(); {some, Value} -> gleam@json:float(Value) end}, {<<"y"/utf8>>, case Y of none -> gleam@json:null(); {some, Value@1} -> gleam@json:float(Value@1) end}, {<<"z"/utf8>>, case Z of none -> gleam@json:null(); {some, Value@2} -> gleam@json:float(Value@2) end}, {<<"motion_variation"/utf8>>, case Motion_variation of none -> gleam@json:null(); {some, Value@3} -> gleam@json:float(Value@3) end}, {<<"size"/utf8>>, case Size of none -> gleam@json:null(); {some, Value@4} -> gleam@json:float(Value@4) end}, {<<"size_variation"/utf8>>, case Size_variation of none -> gleam@json:null(); {some, Value@5} -> gleam@json:float(Value@5) end}, {<<"color"/utf8>>, case Color of none -> gleam@json:null(); {some, Value@6} -> gleam@json:string(Value@6) end}, {<<"color_variation"/utf8>>, case Color_variation of none -> gleam@json:null(); {some, Value@7} -> gleam@json:float(Value@7) end}, {<<"color_fade"/utf8>>, case Color_fade of none -> gleam@json:null(); {some, Value@8} -> gleam@json:string(Value@8) end}, {<<"roll"/utf8>>, case Roll of none -> gleam@json:null(); {some, Value@9} -> gleam@json:float(Value@9) end}, {<<"material"/utf8>>, case Material of none -> gleam@json:null(); {some, Value@10} -> gleam@json:string(Value@10) end}, {<<"opacity"/utf8>>, case Opacity of none -> gleam@json:null(); {some, Value@11} -> gleam@json:float(Value@11) end}]). -file("src/dfjson.gleam", 47). -spec encode_df_json(df_json()) -> gleam@json:json(). encode_df_json(Df_json) -> case Df_json of {dict, Val} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"dict"/utf8>>)}, {<<"val"/utf8>>, gleam@json:dict( Val, fun(String) -> String end, fun encode_df_json/1 )}] ); {list, Val@1} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"list"/utf8>>)}, {<<"val"/utf8>>, gleam@json:array(Val@1, fun encode_df_json/1)}] ); {comp, Val@2} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"comp"/utf8>>)}, {<<"val"/utf8>>, gleam@json:string(Val@2)}] ); {str, Val@3} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"str"/utf8>>)}, {<<"val"/utf8>>, gleam@json:string(Val@3)}] ); {num, Val@4} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"num"/utf8>>)}, {<<"val"/utf8>>, gleam@json:float(Val@4)}] ); {loc, X, Y, Z, Pitch, Yaw} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"loc"/utf8>>)}, {<<"x"/utf8>>, gleam@json:float(X)}, {<<"y"/utf8>>, gleam@json:float(Y)}, {<<"z"/utf8>>, gleam@json:float(Z)}, {<<"pitch"/utf8>>, gleam@json:float(Pitch)}, {<<"yaw"/utf8>>, gleam@json:float(Yaw)}] ); {vec, X@1, Y@1, Z@1} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"vec"/utf8>>)}, {<<"x"/utf8>>, gleam@json:float(X@1)}, {<<"y"/utf8>>, gleam@json:float(Y@1)}, {<<"z"/utf8>>, gleam@json:float(Z@1)}] ); {sound, Sound, Variant, Pitch@1, Volume} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"snd"/utf8>>)}, {<<"sound"/utf8>>, gleam@json:string(Sound)}, {<<"variant"/utf8>>, case Variant of none -> gleam@json:null(); {some, Value} -> gleam@json:string(Value) end}, {<<"pitch"/utf8>>, gleam@json:float(Pitch@1)}, {<<"volume"/utf8>>, gleam@json:float(Volume)}] ); {custom_sound, Sound@1, Pitch@2, Volume@1} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"csnd"/utf8>>)}, {<<"sound"/utf8>>, gleam@json:string(Sound@1)}, {<<"pitch"/utf8>>, gleam@json:float(Pitch@2)}, {<<"volume"/utf8>>, gleam@json:float(Volume@1)}] ); {particle, Particle, Cluster, Data} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"particle"/utf8>>)}, {<<"particle"/utf8>>, gleam@json:string(Particle)}, {<<"cluster"/utf8>>, encode_particle_cluster(Cluster)}, {<<"data"/utf8>>, encode_particle_data(Data)}] ); {potion, Potion, Duration, Amplifier} -> gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(<<"potion"/utf8>>)}, {<<"potion"/utf8>>, gleam@json:string(Potion)}, {<<"duration"/utf8>>, gleam@json:int(Duration)}, {<<"amplifier"/utf8>>, gleam@json:int(Amplifier)}] ) end. -file("src/dfjson.gleam", 261). -spec particle_cluster_decoder() -> gleam@dynamic@decode:decoder(particle_cluster()). particle_cluster_decoder() -> gleam@dynamic@decode:field( <<"horizontal"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Horizontal) -> gleam@dynamic@decode:field( <<"vertical"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Vertical) -> gleam@dynamic@decode:field( <<"amount"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Amount) -> gleam@dynamic@decode:success( {particle_cluster, Horizontal, Vertical, Amount} ) end ) end ) end ). -file("src/dfjson.gleam", 268). -spec particle_data_decoder() -> gleam@dynamic@decode:decoder(particle_data()). particle_data_decoder() -> gleam@dynamic@decode:field( <<"x"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(X) -> gleam@dynamic@decode:field( <<"y"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Y) -> gleam@dynamic@decode:field( <<"z"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Z) -> gleam@dynamic@decode:field( <<"motion_variation"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Motion_variation) -> gleam@dynamic@decode:field( <<"size"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Size) -> gleam@dynamic@decode:field( <<"size_variation"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Size_variation) -> gleam@dynamic@decode:field( <<"color"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Color) -> gleam@dynamic@decode:field( <<"color_variation"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun( Color_variation ) -> gleam@dynamic@decode:field( <<"color_fade"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun( Color_fade ) -> gleam@dynamic@decode:field( <<"roll"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun( Roll ) -> gleam@dynamic@decode:field( <<"material"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun( Material ) -> gleam@dynamic@decode:field( <<"opacity"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun( Opacity ) -> gleam@dynamic@decode:success( {particle_data, X, Y, Z, Motion_variation, Size, Size_variation, Color, Color_variation, Color_fade, Roll, Material, Opacity} ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ). -file("src/dfjson.gleam", 192). -spec df_json_decoder() -> gleam@dynamic@decode:decoder(df_json()). df_json_decoder() -> gleam@dynamic@decode:field( <<"id"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Variant) -> case Variant of <<"dict"/utf8>> -> gleam@dynamic@decode:field( <<"val"/utf8>>, gleam@dynamic@decode:dict( {decoder, fun gleam@dynamic@decode:decode_string/1}, df_json_decoder() ), fun(Val) -> gleam@dynamic@decode:success({dict, Val}) end ); <<"list"/utf8>> -> gleam@dynamic@decode:field( <<"val"/utf8>>, gleam@dynamic@decode:list(df_json_decoder()), fun(Val@1) -> gleam@dynamic@decode:success({list, Val@1}) end ); <<"comp"/utf8>> -> gleam@dynamic@decode:field( <<"val"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Val@2) -> gleam@dynamic@decode:success({comp, Val@2}) end ); <<"str"/utf8>> -> gleam@dynamic@decode:field( <<"val"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Val@3) -> gleam@dynamic@decode:success({str, Val@3}) end ); <<"num"/utf8>> -> gleam@dynamic@decode:field( <<"val"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Val@4) -> gleam@dynamic@decode:success({num, Val@4}) end ); <<"loc"/utf8>> -> gleam@dynamic@decode:field( <<"x"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(X) -> gleam@dynamic@decode:field( <<"y"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Y) -> gleam@dynamic@decode:field( <<"z"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Z) -> gleam@dynamic@decode:field( <<"pitch"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Pitch) -> gleam@dynamic@decode:field( <<"yaw"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Yaw) -> gleam@dynamic@decode:success( {loc, X, Y, Z, Pitch, Yaw} ) end ) end ) end ) end ) end ); <<"vec"/utf8>> -> gleam@dynamic@decode:field( <<"x"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(X@1) -> gleam@dynamic@decode:field( <<"y"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Y@1) -> gleam@dynamic@decode:field( <<"z"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Z@1) -> gleam@dynamic@decode:success( {vec, X@1, Y@1, Z@1} ) end ) end ) end ); <<"snd"/utf8>> -> gleam@dynamic@decode:field( <<"sound"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Sound) -> gleam@dynamic@decode:field( <<"variant"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Variant@1) -> gleam@dynamic@decode:field( <<"pitch"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Pitch@1) -> gleam@dynamic@decode:field( <<"volume"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Volume) -> gleam@dynamic@decode:success( {sound, Sound, Variant@1, Pitch@1, Volume} ) end ) end ) end ) end ); <<"csnd"/utf8>> -> gleam@dynamic@decode:field( <<"sound"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Sound@1) -> gleam@dynamic@decode:field( <<"pitch"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Pitch@2) -> gleam@dynamic@decode:field( <<"volume"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_float/1}, fun(Volume@1) -> gleam@dynamic@decode:success( {custom_sound, Sound@1, Pitch@2, Volume@1} ) end ) end ) end ); <<"particle"/utf8>> -> gleam@dynamic@decode:field( <<"particle"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Particle) -> gleam@dynamic@decode:field( <<"cluster"/utf8>>, particle_cluster_decoder(), fun(Cluster) -> gleam@dynamic@decode:field( <<"data"/utf8>>, particle_data_decoder(), fun(Data) -> gleam@dynamic@decode:success( {particle, Particle, Cluster, Data} ) end ) end ) end ); <<"potion"/utf8>> -> gleam@dynamic@decode:field( <<"potion"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Potion) -> gleam@dynamic@decode:field( <<"duration"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Duration) -> gleam@dynamic@decode:field( <<"amplifier"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Amplifier) -> gleam@dynamic@decode:success( {potion, Potion, Duration, Amplifier} ) end ) end ) end ); _ -> gleam@dynamic@decode:failure({num, +0.0}, <<"DFJson"/utf8>>) end end ).