From d13336bbe6daade5efe8af0b3cb8577953dd6792 Mon Sep 17 00:00:00 2001 From: Atermonera Date: Sat, 29 Feb 2020 15:05:02 -0800 Subject: [PATCH] Fixes communicator newsfeed app. (#6713) * Fixes communicator newsfeed app. Fixes non-terminal while loop in get_latest_news(), helper.dm Newscaster posts now have a world.time-esque timestamp number, so they can be (almost) uniquely identified * whoopsie --- code/game/machinery/newscaster.dm | 2 + .../objects/items/devices/communicator/UI.dm | 5 ++ .../devices/communicator/communicator.dm | 1 + .../items/devices/communicator/helper.dm | 35 ++++---- nano/templates/communicator.tmpl | 86 ++++++++++++------- 5 files changed, 81 insertions(+), 48 deletions(-) diff --git a/code/game/machinery/newscaster.dm b/code/game/machinery/newscaster.dm index aa9278ab03..11caff28de 100644 --- a/code/game/machinery/newscaster.dm +++ b/code/game/machinery/newscaster.dm @@ -15,6 +15,7 @@ var/backup_author = "" var/icon/backup_img = null var/icon/backup_caption = "" + var/post_time = 0 /datum/feed_channel var/channel_name="" @@ -78,6 +79,7 @@ newMsg.body = msg newMsg.time_stamp = "[stationtime2text()]" newMsg.is_admin_message = adminMessage + newMsg.post_time = round_duration_in_ticks // Should be almost universally unique if(message_type) newMsg.message_type = message_type if(photo) diff --git a/code/game/objects/items/devices/communicator/UI.dm b/code/game/objects/items/devices/communicator/UI.dm index e5b1304be5..a4686e39de 100644 --- a/code/game/objects/items/devices/communicator/UI.dm +++ b/code/game/objects/items/devices/communicator/UI.dm @@ -122,6 +122,8 @@ data["manifest"] = PDA_Manifest data["feeds"] = compile_news() data["latest_news"] = get_recent_news() + if(newsfeed_channel) + data["target_feed"] = data["feeds"][newsfeed_channel] if(cartridge) // If there's a cartridge, we need to grab the information from it data["cart_devices"] = cartridge.get_device_status() data["cart_templates"] = cartridge.ui_templates @@ -280,6 +282,9 @@ var/obj/O = cartridge.internal_devices[text2num(href_list["toggle_device"])] cartridge.active_devices ^= list(O) // Exclusive or, will toggle its presence + if(href_list["newsfeed"]) + newsfeed_channel = text2num(href_list["newsfeed"]) + if(href_list["cartridge_topic"] && cartridge) // Has to have a cartridge to perform these functions cartridge.Topic(href, href_list) diff --git a/code/game/objects/items/devices/communicator/communicator.dm b/code/game/objects/items/devices/communicator/communicator.dm index b9a8eff8a4..af3ae77ef5 100644 --- a/code/game/objects/items/devices/communicator/communicator.dm +++ b/code/game/objects/items/devices/communicator/communicator.dm @@ -72,6 +72,7 @@ var/global/list/obj/item/device/communicator/all_communicators = list() var/datum/exonet_protocol/exonet = null var/list/communicating = list() var/update_ticks = 0 + var/newsfeed_channel = 0 // Proc: New() // Parameters: None diff --git a/code/game/objects/items/devices/communicator/helper.dm b/code/game/objects/items/devices/communicator/helper.dm index 273686fb46..25db45b666 100644 --- a/code/game/objects/items/devices/communicator/helper.dm +++ b/code/game/objects/items/devices/communicator/helper.dm @@ -46,23 +46,24 @@ index++ if(FM.img) usr << browse_rsc(FM.img, "pda_news_tmp_photo_[feeds["channel"]]_[index].png") - // News stories are HTML-stripped but require newline replacement to be properly displayed in NanoUI - var/body = replacetext(FM.body, "\n", "
") - messages[++messages.len] = list( - "author" = FM.author, - "body" = body, - "message_type" = FM.message_type, - "time_stamp" = FM.time_stamp, - "has_image" = (FM.img != null), - "caption" = FM.caption, - "index" = index - ) + // News stories are HTML-stripped but require newline replacement to be properly displayed in NanoUI + var/body = replacetext(FM.body, "\n", "
") + messages[++messages.len] = list( + "author" = FM.author, + "body" = body, + "message_type" = FM.message_type, + "time_stamp" = FM.time_stamp, + "has_image" = (FM.img != null), + "caption" = FM.caption, + "index" = index + ) feeds[++feeds.len] = list( "name" = channel.channel_name, "censored" = channel.censored, "author" = channel.author, - "messages" = messages + "messages" = messages, + "index" = feeds.len + 1 // actually align them, since I guess the population of the list doesn't occur until after the evaluation of the new entry's contents ) return feeds @@ -85,14 +86,14 @@ "time_stamp" = FM.time_stamp, "has_image" = (FM.img != null), "caption" = FM.caption, + "time" = FM.post_time ) // Cut out all but the youngest three - while(news.len > 3) - var/oldest = min(news[0]["time_stamp"], news[1]["time_stamp"], news[2]["time_stamp"], news[3]["time_stamp"]) - for(var/i = 0, i < 4, i++) - if(news[i]["time_stamp"] == oldest) - news.Remove(news[i]) + if(news.len > 3) + sortByKey(news, "time") + news.Cut(1, news.len - 2) // Last three have largest timestamps, youngest posts + news.Swap(1, 3) // List is sorted in ascending order of timestamp, we want descending return news diff --git a/nano/templates/communicator.tmpl b/nano/templates/communicator.tmpl index ed28ab828e..3a81b0fc45 100644 --- a/nano/templates/communicator.tmpl +++ b/nano/templates/communicator.tmpl @@ -195,37 +195,61 @@ Used In File(s): code\game\objects\items\devices\communicator\communicator.dm

News


- {{if data.feeds.length}} - -

Recent News

-
- {{for data.latest_news}} -
{{:value.channel}}
- -{{:value.body}}
- {{if value.has_image}} -
- {{if value.caption}} - {{:value.caption}}
- {{/if}} - {{/if}} - - {{:helper.link('Go to', 'arrow', {'newsfeed' : value.channel})}} - [{{:value.message_type}} by {{:value.author}} - {{:value.time_stamp}}] -
- {{empty}} - {{/for}} -
-
- - -

News Feeds

-
- {{for data.feeds}} -
- {{:helper.link(value.name, 'arrow', {'newsfeed' : value.name})}} + {{if data.feeds.length}} + {{if data.target_feed}} + {{:helper.link('Back', 'arrow', {'newsfeed' : 0})}} +

{{:data.target_feed.name}}

+
By: {{:data.target_feed.author}}
+
+ {{for data.target_feed.messages}} + -{{:value.body}}
+ {{if value.has_image}} +
+ {{if value.caption}} + {{:value.caption}}
+ {{/if}} + {{/if}} + + [{{:value.message_type}} by {{:value.author}} - {{:value.time_stamp}}] + +
+ {{empty}} + {{/for}}
- {{/for}} -
+ + {{else}} + +

Recent News

+
+ {{for data.latest_news}} +
{{:value.channel}}
+ -{{:value.body}}
+ {{if value.has_image}} +
+ {{if value.caption}} + {{:value.caption}}
+ {{/if}} + {{/if}} + + {{:helper.link('Go to', 'arrow', {'newsfeed' : value.channel})}} + [{{:value.message_type}} by {{:value.author}} - {{:value.time_stamp}}] + +
+ {{empty}} + {{/for}} +
+
+ + +

News Feeds

+
+ {{for data.feeds}} +
+ {{:helper.link(value.name, 'arrow', {'newsfeed' : value.index})}} +
+ {{/for}} +
+ {{/if}} {{else}}
@@ -233,7 +257,7 @@ Used In File(s): code\game\objects\items\devices\communicator\communicator.dm Error
- No weather reports available. Please try again later. + No newsfeeds available. Please try again later.
{{/if}}