From e4427c41d029449f681e3badf2c7a8895adfe068 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Sat, 13 Aug 2022 22:51:29 +0800 Subject: [PATCH 1/4] Add files via upload --- programs/libraries/rjson.scl | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 programs/libraries/rjson.scl diff --git a/programs/libraries/rjson.scl b/programs/libraries/rjson.scl new file mode 100644 index 00000000..7ccb405e --- /dev/null +++ b/programs/libraries/rjson.scl @@ -0,0 +1,98 @@ +//raw-json string to text +rjson(rj)->( +barname='chyxrjson:rjson'+(rand(0.9)-'.'); +if(bossbar(barname)==false,return(rjson(rj))); +command=run('bossbar set '+barname+' name '+rj); +res=bossbar(barname,'name'); +bossbar(barname,'remove'); +if (command:1,res,throw('not valid r-json')) +); + +//turns text-like values to a real text +//will accept a [id, count, nbt] in the future +__argument_rcv=(_(value)->( +if(type(value)=='string',pure_text(value), +type(value)=='text',value, +type(value)=='entity',value~'display_name', +throw('not a text-like value')) +)); + +//string to text +pure_text(str)->( +if(type(str)!='string',throw('not string')); +rjson(encode_json(str)) +); + +//text to raw json string +text2rjson(text)->( +if(type(text)!='text',throw('not text')); +encode_json(text) +); + +//modify a text-like value +for(['color','font','insertion'], +call('fset_'+_,text,color,outer(_),outer(__argument_rcv))->( +text=call(__argument_rcv,text); +obj=decode_json(encode_json(text)); +obj:_=color; +rjson(encode_json(obj)) +); +); + +//same format as format() +fset_click(text,event,outer(__argument_rcv))->( +if(split('!?&@')~slice(event,0,1)==null,throw('not correct')); +text=call(__argument_rcv,text); +obj1=decode_json(encode_json(format(' dummy',event))); +obj2=decode_json(encode_json(text)); +obj2:'clickEvent'=obj1:'extra':0:'clickEvent'; +rjson(encode_json(obj2)) +); + +//format should be a string of biuso=>false or BIUSO=>true +fset_format(text,format,outer(__argument_rcv))->( +fmts=['bold','italic','underlined','strikethrough','obfuscated']; +fmts1=['b','i','u','s','o']; +fmts2=['B','I','U','S','O']; +text=call(__argument_rcv,text); +obj=decode_json(encode_json(text)); +loop(5,( +if(format~(fmts1:_),obj:(fmts:_)=false); +if(format~(fmts2:_),obj:(fmts:_)=true) +)); +rjson(encode_json(obj)) +); +//join 2 text-like values +hovertext(base,hover,outer(__argument_rcv))->( +base=call(__argument_rcv,base); +hover=call(__argument_rcv,hover); +obj1=decode_json(encode_json(base)); +obj2=decode_json(encode_json(hover)); +obj1:'hoverEvent'={'action'->'show_text','contents'->obj2}; +rjson(encode_json(obj1)) +); + + +//'with' can be any text-like argument +translate(key,outer(__argument_rcv),...with)->( +with=map(with,call(__argument_rcv,_)); +rjson(encode_json({'translate'->key,'with'->with})) +); + +say(player,text)->translate('chat.type.text',player,text); +bra(text)->translate('chat.square_brackets',text); + + +keybind(key)->( +rjson(encode_json({'keybind'->key})) +) + + +//script run import('rjson',...import('rjson')) +//script run x=''+fset_color('eee','red')+fset_insertion(format('e eee'),'click!');print(hovertext(x,x)) + +//script run print(translate('death.attack.fireworks.item',p,'who',format('e apple'))) + +//script run print(fset_font(keybind('key.inventory'),'alt')) + +//script run print(fset_format(p,'IBo')) \ No newline at end of file From 9043f1e0f88c3e7e9051b381617b1313ad7c391c Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 30 Aug 2022 19:28:31 +0800 Subject: [PATCH 2/4] Update rjson.scl --- programs/libraries/rjson.scl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/programs/libraries/rjson.scl b/programs/libraries/rjson.scl index 7ccb405e..6fe0fcc3 100644 --- a/programs/libraries/rjson.scl +++ b/programs/libraries/rjson.scl @@ -1,4 +1,5 @@ //raw-json string to text +if(0, rjson(rj)->( barname='chyxrjson:rjson'+(rand(0.9)-'.'); if(bossbar(barname)==false,return(rjson(rj))); @@ -8,12 +9,22 @@ bossbar(barname,'remove'); if (command:1,res,throw('not valid r-json')) ); + +, +rjson(rj)->( +r1=item_display_name(['apple',1,encode_nbt({'display'->{'Name'->rj}})]); +r2=item_display_name(['stone',1,encode_nbt({'display'->{'Name'->rj}})]); +if(r1==r2,r1,throw('not valid r-json')) +); +); + //turns text-like values to a real text //will accept a [id, count, nbt] in the future __argument_rcv=(_(value)->( if(type(value)=='string',pure_text(value), type(value)=='text',value, type(value)=='entity',value~'display_name', +type(value)=='list',item_display_name(value), throw('not a text-like value')) )); @@ -95,4 +106,4 @@ rjson(encode_json({'keybind'->key})) //script run print(fset_font(keybind('key.inventory'),'alt')) -//script run print(fset_format(p,'IBo')) \ No newline at end of file +//script run print(fset_format(p,'IBo')) From 8ea3c59e858b1478a55d02762e002fd1df02404d Mon Sep 17 00:00:00 2001 From: ch-yx Date: Wed, 31 Aug 2022 20:46:05 +0800 Subject: [PATCH 3/4] Update rjson.scl --- programs/libraries/rjson.scl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/libraries/rjson.scl b/programs/libraries/rjson.scl index 6fe0fcc3..b5327871 100644 --- a/programs/libraries/rjson.scl +++ b/programs/libraries/rjson.scl @@ -1,5 +1,5 @@ //raw-json string to text -if(0, +if(0, //if you are using an old version, change it to 1 rjson(rj)->( barname='chyxrjson:rjson'+(rand(0.9)-'.'); if(bossbar(barname)==false,return(rjson(rj))); From 657531c84e6ac1a952f0ab6f5990ffd08e55dd09 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 15 Nov 2022 15:05:43 +0800 Subject: [PATCH 4/4] indent --- programs/libraries/rjson.scl | 113 ++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/programs/libraries/rjson.scl b/programs/libraries/rjson.scl index b5327871..f6d1c68f 100644 --- a/programs/libraries/rjson.scl +++ b/programs/libraries/rjson.scl @@ -1,93 +1,94 @@ -//raw-json string to text -if(0, //if you are using an old version, change it to 1 -rjson(rj)->( -barname='chyxrjson:rjson'+(rand(0.9)-'.'); -if(bossbar(barname)==false,return(rjson(rj))); -command=run('bossbar set '+barname+' name '+rj); -res=bossbar(barname,'name'); -bossbar(barname,'remove'); -if (command:1,res,throw('not valid r-json')) -); - +if(0, //if you are using an old version, change it to 1 + //workaround for old version + //raw-json string to text + rjson(rj)->( + barname='chyxrjson:rjson'+(rand(0.9)-'.'); + if(bossbar(barname)==false,return(rjson(rj))); + command=run('bossbar set '+barname+' name '+rj); + res=bossbar(barname,'name'); + bossbar(barname,'remove'); + if (command:1,res,throw('not valid r-json')) + ); , -rjson(rj)->( -r1=item_display_name(['apple',1,encode_nbt({'display'->{'Name'->rj}})]); -r2=item_display_name(['stone',1,encode_nbt({'display'->{'Name'->rj}})]); -if(r1==r2,r1,throw('not valid r-json')) -); + //raw-json string to text + rjson(rj)->( + r1=item_display_name(['apple',1,encode_nbt({'display'->{'Name'->rj}})]); + r2=item_display_name(['stone',1,encode_nbt({'display'->{'Name'->rj}})]); + if(r1==r2,r1,throw('not valid r-json')) + ); ); //turns text-like values to a real text //will accept a [id, count, nbt] in the future __argument_rcv=(_(value)->( -if(type(value)=='string',pure_text(value), -type(value)=='text',value, -type(value)=='entity',value~'display_name', -type(value)=='list',item_display_name(value), -throw('not a text-like value')) + if(type(value)=='string',pure_text(value), + type(value)=='text',value, + type(value)=='entity',value~'display_name', + type(value)=='list',item_display_name(value), + throw('not a text-like value')) )); //string to text pure_text(str)->( -if(type(str)!='string',throw('not string')); -rjson(encode_json(str)) + if(type(str)!='string',throw('not string')); + rjson(encode_json(str)) ); //text to raw json string text2rjson(text)->( -if(type(text)!='text',throw('not text')); -encode_json(text) + if(type(text)!='text',throw('not text')); + encode_json(text) ); //modify a text-like value for(['color','font','insertion'], -call('fset_'+_,text,color,outer(_),outer(__argument_rcv))->( -text=call(__argument_rcv,text); -obj=decode_json(encode_json(text)); -obj:_=color; -rjson(encode_json(obj)) -); + call('fset_'+_,text,color,outer(_),outer(__argument_rcv))->( + text=call(__argument_rcv,text); + obj=decode_json(encode_json(text)); + obj:_=color; + rjson(encode_json(obj)) + ); ); //same format as format() fset_click(text,event,outer(__argument_rcv))->( -if(split('!?&@')~slice(event,0,1)==null,throw('not correct')); -text=call(__argument_rcv,text); -obj1=decode_json(encode_json(format(' dummy',event))); -obj2=decode_json(encode_json(text)); -obj2:'clickEvent'=obj1:'extra':0:'clickEvent'; -rjson(encode_json(obj2)) + if(split('!?&@')~slice(event,0,1)==null,throw('not correct')); + text=call(__argument_rcv,text); + obj1=decode_json(encode_json(format(' dummy',event))); + obj2=decode_json(encode_json(text)); + obj2:'clickEvent'=obj1:'extra':0:'clickEvent'; + rjson(encode_json(obj2)) ); //format should be a string of biuso=>false or BIUSO=>true fset_format(text,format,outer(__argument_rcv))->( -fmts=['bold','italic','underlined','strikethrough','obfuscated']; -fmts1=['b','i','u','s','o']; -fmts2=['B','I','U','S','O']; -text=call(__argument_rcv,text); -obj=decode_json(encode_json(text)); -loop(5,( -if(format~(fmts1:_),obj:(fmts:_)=false); -if(format~(fmts2:_),obj:(fmts:_)=true) -)); -rjson(encode_json(obj)) + fmts=['bold','italic','underlined','strikethrough','obfuscated']; + fmts1=['b','i','u','s','o']; + fmts2=['B','I','U','S','O']; + text=call(__argument_rcv,text); + obj=decode_json(encode_json(text)); + loop(5,( + if(format~(fmts1:_),obj:(fmts:_)=false); + if(format~(fmts2:_),obj:(fmts:_)=true) + )); + rjson(encode_json(obj)) ); //join 2 text-like values hovertext(base,hover,outer(__argument_rcv))->( -base=call(__argument_rcv,base); -hover=call(__argument_rcv,hover); -obj1=decode_json(encode_json(base)); -obj2=decode_json(encode_json(hover)); -obj1:'hoverEvent'={'action'->'show_text','contents'->obj2}; -rjson(encode_json(obj1)) + base=call(__argument_rcv,base); + hover=call(__argument_rcv,hover); + obj1=decode_json(encode_json(base)); + obj2=decode_json(encode_json(hover)); + obj1:'hoverEvent'={'action'->'show_text','contents'->obj2}; + rjson(encode_json(obj1)) ); //'with' can be any text-like argument translate(key,outer(__argument_rcv),...with)->( -with=map(with,call(__argument_rcv,_)); -rjson(encode_json({'translate'->key,'with'->with})) + with=map(with,call(__argument_rcv,_)); + rjson(encode_json({'translate'->key,'with'->with})) ); say(player,text)->translate('chat.type.text',player,text); @@ -95,7 +96,7 @@ bra(text)->translate('chat.square_brackets',text); keybind(key)->( -rjson(encode_json({'keybind'->key})) + rjson(encode_json({'keybind'->key})) )