From 16dd19ab7f7b2e5e953ad567f6e0907c87b5aa5f Mon Sep 17 00:00:00 2001 From: szdytom Date: Sat, 7 Oct 2023 08:23:22 +0800 Subject: [PATCH] Fix i18n strings with format Signed-off-by: szdytom --- src/ica-admin.sc | 34 ++++++----------------- src/ica-effect-applier.sc | 6 ++--- src/ica-i18n.sc | 57 ++++++++++++++++++++++++++++----------- src/ica-libs.sc | 13 ++++++++- src/ica-settings.sc | 33 +++++++++++------------ src/ica-vote.sc | 2 +- src/ica.sc | 37 +++++++++++-------------- 7 files changed, 98 insertions(+), 84 deletions(-) diff --git a/src/ica-admin.sc b/src/ica-admin.sc index 8aff1c9..16ef755 100644 --- a/src/ica-admin.sc +++ b/src/ica-admin.sc @@ -4,13 +4,13 @@ __config() -> { 'commands' -> { 'list' -> 'cmdList', 'confirm' -> 'cmdStart', - 'reset clear' -> 'cmdResetClear', - 'reset schedule' -> 'cmdReschedule' + 'reset' -> 'cmdResetClear' }, }; import('ica-libs', 'shuffleList', 'countCareer', 'playerListNbt' - , 'findVoteMax', 'resetVotes'); + , 'findVoteMax', 'resetVotes', 'getFirstUnsetGoal', 'useIcaInstead' + , 'startedReject'); import('ica-i18n', 'getLocaleKey'); __on_start() -> ( @@ -121,16 +121,6 @@ endFinish() -> ( endCleanup(); ); -getFirstUnsetGoal() -> ( - c_for(i = 0, i <= 5, i = i + 1, ( - p = nbt_storage('ica:data'):str('Goals[{Slot: %db}]', i); - if(p == null, ( - return(i); - )) - )); - return(6); -); - actionbarMessage(msg) -> ( display_title(player('all'), 'actionbar', msg, 100, 100, 100); ); @@ -201,9 +191,9 @@ startCollectStage() -> ( schedule(20, 'runUpdateCollect'); clearBossbars(); - createBossbar('ica:time_counter', format(getLocaleKey('bossbar.time.title')) + createBossbar('ica:time_counter', format('b ' + getLocaleKey('bossbar.time.title')) , tm_total(), 'notched_6'); - createBossbar('ica:collected', format(getLocaleKey('bossbar.progress.title')) + createBossbar('ica:collected', format('b ' + getLocaleKey('bossbar.progress.title')) , 6, 'notched_6'); bossbar('ica:collected', 'value', 0); @@ -243,14 +233,6 @@ cmdResetClear() -> ( endCleanup(); ); -cmdReschedule() -> ( - if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); - return(false) - )); - schedule('runUpdateCollect', 20); -); - runUpdatePrepare() -> ( if(!nbt_storage('ica:data'):'Started', return()); if(!nbt_storage('ica:data'):'Preparing', return()); @@ -271,7 +253,7 @@ cmdStart() -> ( )); if(nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.started'))); + startedReject(); return(false) )); @@ -290,7 +272,7 @@ cmdStart() -> ( put(nbt_storage('ica:data'):'Preparing', '1b'); put(nbt_storage('ica:data'):'Goals[].Completed', '0b'); - createBossbar('ica:prepare_counter', format(getLocaleKey('bossbar.prepare.title')) + createBossbar('ica:prepare_counter', format('b ' + getLocaleKey('bossbar.prepare.title')) , tm_prepare(), null); schedule(20, 'runUpdatePrepare'); @@ -320,6 +302,6 @@ cmdStart() -> ( ); cmdList() -> ( - print(format(getLocaleKey('instead'))); + useIcaInstead(); run('/ica'); ); diff --git a/src/ica-effect-applier.sc b/src/ica-effect-applier.sc index 93d8825..0cbf8c1 100644 --- a/src/ica-effect-applier.sc +++ b/src/ica-effect-applier.sc @@ -21,11 +21,11 @@ getStatus() -> ( updateEffects() -> ( if(global_enabled, ( for(player('all'), ( - modify(_, 'effect', 'regeneration', 600, 1, false, true); - modify(_, 'effect', 'absorption', 600, 2, false, true); + modify(_, 'effect', 'regeneration', 400, 1, false, true); + modify(_, 'effect', 'absorption', 400, 2, false, true); )); )); - schedule(400, 'updateEffects'); + schedule(200, 'updateEffects'); ); setBlock(pos, use_upper_half) -> ( diff --git a/src/ica-i18n.sc b/src/ica-i18n.sc index 9e5e887..63bcace 100644 --- a/src/ica-i18n.sc +++ b/src/ica-i18n.sc @@ -1,6 +1,6 @@ __config() -> { 'scope' -> 'global', - 'exports' -> ['getLocaleKey'], + 'exports' -> ['getLocaleKey', 'useIcaInstead', 'startedReject', 'pendingReject'], }; global_TranslateKeysEnUS = { @@ -18,10 +18,10 @@ global_TranslateKeysEnUS = { 'submit.ddl.2' -> '[WARN] Submission deadline in %d seconds.', 'submit.ddl.3' -> '[WARN] Submission deadline in %d second.', 'submit.success' -> 'OK.', - 'submit.missing.before' -> ' Item ', - 'submit.missing.after' -> ' not found.', - 'submit.already.before' -> ' Item ', - 'submit.already.after' -> ' has already been collected.', + 'submit.missing.before' -> 'Item ', + 'submit.missing.after' -> ' not found.', + 'submit.already.before' -> 'Item ', + 'submit.already.after' -> ' has already been collected.', 'election.kill' -> 'Election victim %s killed.', 'election.ddl' -> '[WARN] Vote ends in 1 minute.', @@ -30,18 +30,24 @@ global_TranslateKeysEnUS = { 'election.new' -> 'New election round started.', 'election.result' -> 'Election result: %s.', - 'instead' -> 'd Please use /ica instead.', + 'hint.instead.before' -> 'Please use ', + 'hint.instead.after' -> ' instead.', + 'hint.allset.before' -> 'All goals are set, you can use ', + 'hint.allset.after' -> ' to start.', - 'bossbar.prepare.title' -> 'b Preparing', - 'bossbar.time.title' -> 'b Time Left', - 'bossbar.progress.title' -> 'b Collected', + 'goal.set.before' -> 'Goal #%d set to ', + 'goal.set.after' -> '.', + + 'bossbar.prepare.title' -> 'Preparing', + 'bossbar.time.title' -> 'Time Left', + 'bossbar.progress.title' -> 'Collected', 'career.display.title' -> 'Career configs are:', 'career.display.wolf' -> ' - Wolf: %d participants.', 'career.display.hunter' -> ' - Hunter(Fireball): %d participants.', 'career.display.firework_hunter' -> ' - Hunter(Firework): %d participants.', 'career.display.builder' -> ' - Builder: %d participants.', - 'career.display.piggy' -> 'Career configs are:', + 'career.display.piggy' -> '- Piggies: whatever the rest.', 'career.set' -> 'Career %s set to %d participants.', 'career.title.bystander' -> 'Bystander', @@ -76,11 +82,14 @@ global_TranslateKeysEnUS = { 'ablity.format' -> '[ablity] %s: %s', - 'reject.pending' -> [' Not started. use ', 'mb /ica-admin confirm', '?/ica-admin confirm', ' to start.'], - 'reject.started' -> [' Already started, use ', 'mb /ica-admin reset clear', '?/ica-admin reset clear', ' to cancel.'], + 'reject.pending.before' -> 'Not started, use ', + 'reject.pending.after' -> ' to start.', + 'reject.started.before' -> 'Already started, use ', + 'reject.started.after' -> ' to cancel.', 'reject.leckplayer' -> ' Not enough players are online.', 'reject.goal.missing' -> 'Goal #%d is unset.', - 'reject.goal.enough' -> [' All are goals set, please use ', 'mb /ica-settings set ', ' to replace.'], + 'reject.goal.enough.before' -> 'All are goals set, please use ', + 'reject.goal.enough.after' -> ' to replace.', 'reject.spyglass' -> 'Spyglass too hot, please wait another %.2f seconds to use again.', 'reject.unable' -> 'You don\'t have this ability.', 'reject.bystand' -> 'You can only bystand.', @@ -117,9 +126,27 @@ global_TranslateKeysEnUS = { 'misc.clipboard' -> 'Click To Copy', - 'license.header' -> 'ICollect-Alpha, Copyright (C) 2023 方而静\nICollect-Alpha comes with ABSOLUTELY NO WARRANTY;\nfor details type \'/ica-loader show w\'.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; type \'/ica-loader show c\' for details.', + 'license.header' -> 'ICollect-Alpha, Copyright (C) 2023 方而静\nICollect-Alpha comes with ABSOLUTELY NO WARRANTY;\nfor details type \'/ica-loader show w\'.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; type \'/ica-loader show c\' for details.' }; getLocaleKey(keyid) -> ( if(has(global_TranslateKeysEnUS:keyid), global_TranslateKeysEnUS:keyid, 'tkey:' + keyid) -); \ No newline at end of file +); + +useIcaInstead() -> ( + print(format('d ' + getLocaleKey('hint.instead.before') + , 'mb /ica', '?/ica' + , 'd ' + getLocaleKey('hint.instead.after'))); +); + +startedReject() -> ( + print(format(' ' + getLocaleKey('reject.started.before') + , 'mb /ica-admin reset', '?/ica-admin reset' + , ' ' + getLocaleKey('reject.started.after'))); +); + +pendingReject() -> ( + print(format(' ' + getLocaleKey('reject.pending.before') + , 'mb /ica-admin confirm', '?/ica-admin confirm' + , ' ' + getLocaleKey('reject.pending.after'))); +); diff --git a/src/ica-libs.sc b/src/ica-libs.sc index 198e99d..5b8b30c 100644 --- a/src/ica-libs.sc +++ b/src/ica-libs.sc @@ -1,7 +1,8 @@ __config() -> { 'scope' -> 'global', 'exports' -> ['shuffleList', 'countCareer', 'findVoteMax', 'resetVotes' - , 'playerListNbt', 'listContain', 'countVotes', 'countAbstainVotes'], + , 'playerListNbt', 'listContain', 'countVotes', 'countAbstainVotes' + , 'getFirstUnsetGoal'], }; shuffleList(list) -> ( @@ -75,3 +76,13 @@ findVoteMax() -> ( resetVotes() -> ( put(nbt_storage('ica:voting'), 'Votes', '[]'); ); + +getFirstUnsetGoal() -> ( + c_for(i = 0, i <= 5, i = i + 1, ( + p = nbt_storage('ica:data'):str('Goals[{Slot: %db}]', i); + if(p == null, ( + return(i); + )) + )); + return(6); +); \ No newline at end of file diff --git a/src/ica-settings.sc b/src/ica-settings.sc index fec5e5b..9917e8c 100644 --- a/src/ica-settings.sc +++ b/src/ica-settings.sc @@ -18,27 +18,17 @@ __config() -> { }, }; -import('ica-i18n', 'getLocaleKey'); -import('ica-libs', 'countCareer'); - -getFirstUnsetGoal() -> ( - c_for(i = 0, i <= 5, i = i + 1, ( - p = nbt_storage('ica:data'):str('Goals[{Slot: %db}]', i); - if(p == null, ( - return(i); - )) - )); - return(6); -); +import('ica-i18n', 'getLocaleKey', 'useIcaInstead', 'startedReject', 'pendingReject'); +import('ica-libs', 'countCareer', 'getFirstUnsetGoal'); cmdList() -> ( - print(format(getLocaleKey('instead'))); + useIcaInstead(); run('/ica'); ); cmdSet(slot_id, goal_item_tuple) -> ( if(nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.started'))); + startedReject(); return(false) )); pkey = str('Goals[{Slot: %db}]', slot_id); @@ -46,7 +36,14 @@ cmdSet(slot_id, goal_item_tuple) -> ( if(nbt_storage('ica:data'):pkey != null, delete(nbt_storage('ica:data'):pkey)); put(nbt_storage('ica:data'), 'Goals', etag, -1); - print(str('Goal #%d set to %s.', slot_id, goal_item_tuple:0)) + print(format(' ' + str(getLocaleKey('goal.set.before'), slot_id) + , 'b ' + item_display_name(goal_item_tuple:0), '^ minecraft:' + goal_item_tuple:0 + , ' ' + getLocaleKey('goal.set.after')); + if(getFirstUnsetGoal() > 5, ( + print(format(' ' + getLocaleKey('hint.allset.before') + , 'mb /ica-admin confirm', '?/ica-admin confirm' + , ' ' + getLocaleKey('hint.allset.after'))); + )); ); cmdSetAppend(goal_item_tuple) -> ( @@ -54,7 +51,9 @@ cmdSetAppend(goal_item_tuple) -> ( if(missing_goal <= 5, ( cmdSet(missing_goal, goal_item_tuple) ), ( - print(format(getLocaleKey('reject.goal.enough'))) + print(format(' ' + getLocaleKey('reject.goal.enough.before') + , 'mb /ica-settings set ', '?/ica-settings set ' + , ' ' + getLocaleKey('reject.goal.enough.after'))); )); ); @@ -68,7 +67,7 @@ cmdListCareers() -> ( cmdConfigCareer(cartype, ccount) -> ( if(nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.started'))); + startedReject(); return(false) )); pkey = str('Config[{Type: "%s"}].Count', cartype); diff --git a/src/ica-vote.sc b/src/ica-vote.sc index 454359d..2f1e805 100644 --- a/src/ica-vote.sc +++ b/src/ica-vote.sc @@ -26,7 +26,7 @@ cmdInfo() -> ( )); cand_names = parse_nbt(nbt_storage('ica:voting'):'Candidates'); cand_n = length(cand_names); - print(str(getLocaleKey('vote.title', cand_n)); + print(str(getLocaleKey('vote.title', cand_n))); for(cand_names, ( p = player(_); v_cnt = countVotes(_); diff --git a/src/ica.sc b/src/ica.sc index 768995a..f125e30 100644 --- a/src/ica.sc +++ b/src/ica.sc @@ -25,7 +25,7 @@ __config() -> { }; import('ica-libs', 'listContain'); -import('ica-i18n', 'getLocaleKey'); +import('ica-i18n', 'getLocaleKey', 'startedReject', 'pendingReject'); global_capMarkerMap = { 'builder' -> 'ica.build_spyglasser', @@ -33,14 +33,6 @@ global_capMarkerMap = { 'firework' -> 'ica.firework_spyglasser', }; -tm_total() -> ( - 72000 -); - -tm_per_goal() -> ( - 12000 -); - lackOfAbilityReject() -> ( print(getLocaleKey('reject.unable')); ); @@ -51,7 +43,7 @@ bystandReject() -> ( cmdLocate(pname) -> ( if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); + pendingReject(); return(false) )); myself = player(); @@ -101,7 +93,7 @@ cmdSeed() -> ( cmdRefill() -> ( if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); + pendingReject(); return(false) )); myself = player(); @@ -162,7 +154,7 @@ cmdList() -> ( cmdMe() -> ( if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); + pendingReject(); return(false) )); myself = player(); @@ -193,7 +185,7 @@ disableAllSpyglassAbilities(me) -> ( cmdSpyglassSwitch(feature_id) -> ( if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); + pendingReject(); return(false) )); me = player(); @@ -216,7 +208,7 @@ cmdSpyglassSwitch(feature_id) -> ( cmdSubmit(slot_id) -> ( if(!nbt_storage('ica:data'):'Started', ( - print(format(getLocaleKey('reject.pending'))); + pendingReject(); return(false) )); if(nbt_storage('ica:data'):'Preparing', ( @@ -230,17 +222,20 @@ cmdSubmit(slot_id) -> ( )); pkey = str('Goals[{Slot: %db}]', slot_id); + g_item = nbt_storage('ica:data'):pkey:'Item'; if(nbt_storage('ica:data'):pkey:'Completed', ( - print(format(getLocaleKey('submit.already.before')) - + item_display_name(nbt_storage('ica:data'):pkey:'Item') - + format(getLocaleKey('submit.already.after'))); + print(format(' ' + getLocaleKey('submit.already.before') + , 'b ' + item_display_name(g_item) + , '^ minecraft:' + g_item + , ' ' + getLocaleKey('submit.already.after'))); return() )); - if(inventory_remove(me, nbt_storage('ica:data'):pkey:'Item', 1) == 0, ( - print(format(getLocaleKey('submit.missing.before')) - + item_display_name(nbt_storage('ica:data'):pkey:'Item') - + format(getLocaleKey('submit.missing.after'))); + if(inventory_remove(me, g_item, 1) == 0, ( + print(format(' ' + getLocaleKey('submit.missing.before') + , 'b ' + item_display_name(g_item) + , '^ mincraft:' + g_item + , ' ' + getLocaleKey('submit.missing.after'))); return() )); put(nbt_storage('ica:data'):(pkey+'.Completed'), '1b');