Skip to content

Commit

Permalink
Spends 6 hours teaching Papercode how to conform to better standards …
Browse files Browse the repository at this point in the history
…and practices, and also fixes a trivial 5 minute bug with command reports. (tgstation#69071)
  • Loading branch information
Timberpoes authored Aug 11, 2022
1 parent 68ba146 commit 5a4f85f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 28 deletions.
5 changes: 4 additions & 1 deletion code/game/gamemodes/game_mode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@
if(!GLOB.station_goals.len)
return
. = "<hr><b>Special Orders for [station_name()]:</b><BR>"
var/list/goal_reports = list()
for(var/datum/station_goal/station_goal as anything in GLOB.station_goals)
station_goal.on_report()
. += station_goal.get_report()
goal_reports += station_goal.get_report()

. += goal_reports.Join("<hr>")
return

/*
Expand Down
12 changes: 7 additions & 5 deletions code/modules/station_goals/bsa.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ GLOBAL_VAR_INIT(bsa_unlock, FALSE)
name = "Bluespace Artillery"

/datum/station_goal/bluespace_cannon/get_report()
return {"Our military presence is inadequate in your sector.
We need you to construct BSA-[rand(1,99)] Artillery position aboard your station.

Base parts are available for shipping via cargo.
-Nanotrasen Naval Command"}
return list(
"<blockquote>Our military presence is inadequate in your sector.",
"We need you to construct BSA-[rand(1,99)] Artillery position aboard your station.",
"",
"Base parts are available for shipping via cargo.",
"-Nanotrasen Naval Command</blockquote>",
).Join("\n")

/datum/station_goal/bluespace_cannon/on_report()
//Unlock BSA parts
Expand Down
20 changes: 11 additions & 9 deletions code/modules/station_goals/dna_vault.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
.++

/datum/station_goal/dna_vault/get_report()
return {"Our long term prediction systems indicate a 99% chance of system-wide cataclysm in the near future.
We need you to construct a DNA Vault aboard your station.

The DNA Vault needs to contain samples of:
[animal_count] unique animal data
[plant_count] unique non-standard plant data
[human_count] unique sapient humanoid DNA data

Base vault parts are available for shipping via cargo."}
return list(
"<blockquote>Our long term prediction systems indicate a 99% chance of system-wide cataclysm in the near future.",
"We need you to construct a DNA Vault aboard your station.",
"",
"The DNA Vault needs to contain samples of:",
"* [animal_count] unique animal data",
"* [plant_count] unique non-standard plant data",
"* [human_count] unique sapient humanoid DNA data",
"",
"Base vault parts are available for shipping via cargo.</blockquote>",
).Join("\n")


/datum/station_goal/dna_vault/on_report()
Expand Down
11 changes: 6 additions & 5 deletions code/modules/station_goals/shield.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
requires_space = TRUE

/datum/station_goal/station_shield/get_report()
return {"The station is located in a zone full of space debris.
We have a prototype shielding system you must deploy to reduce collision-related accidents.

You can order the satellites and control systems at cargo.
"}
return list(
"<blockquote>The station is located in a zone full of space debris.",
"We have a prototype shielding system you must deploy to reduce collision-related accidents.",
"",
"You can order the satellites and control systems at cargo.</blockquote>",
).Join("\n")


/datum/station_goal/station_shield/on_report()
Expand Down
52 changes: 44 additions & 8 deletions tgui/packages/tgui/interfaces/PaperSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,43 @@ export class PreviewView extends Component<PreviewViewProps> {
break;
}
};
return marked(rawText, {

// This is an extension for marked defining a complete custom tokenizer.
// This tokenizer should run before the the non-custom ones, and gives us
// the ability to handle [_____] fields before the em/strong tokenizers
// mangle them, since underscores are used for italic/bold.
// This massively improves the order of operations, allowing us to run
// marked, THEN sanitise the output (much safer) and finally insert fields
// manually afterwards.
const inputField = {
name: 'inputField',
level: 'inline',

start(src) {
return src.match(/\[/)?.index;
},

tokenizer(src: string) {
const rule = /^\[_+\]/;
const match = src.match(rule);
if (match) {
const token = {
type: 'inputField',
raw: match[0],
};
return token;
}
},

renderer(token) {
return `${token.raw}`;
},
};

// marked.use({ tokenizer });
marked.use({ extensions: [inputField] });

return marked.parse(rawText, {
breaks: true,
smartypants: true,
smartLists: true,
Expand All @@ -615,10 +651,13 @@ export class PreviewView extends Component<PreviewViewProps> {
// First lets make sure it ends in a new line
rawText += rawText[rawText.length] === '\n' ? '\n' : '\n\n';

// Second, we sanitize the text of html
const sanitizedText = sanitizeText(rawText);
// Second, parse the text using markup
const parsedText = this.runMarkedDefault(rawText);

// Third we replace the [__] with fields as markedjs fucks them up
// Third, we sanitize the text of html
const sanitizedText = sanitizeText(parsedText);

// Fourth we replace the [__] with fields
const fieldedText = this.createFields(
sanitizedText,
font,
Expand All @@ -629,11 +668,8 @@ export class PreviewView extends Component<PreviewViewProps> {
fieldCounter
);

// Fourth, parse the text using markup
const parsedText = this.runMarkedDefault(fieldedText.text);

// Fifth, we wrap the created text in the writing implement properties.
const fontedText = this.setFontInText(parsedText, font, color, bold);
const fontedText = this.setFontInText(fieldedText.text, font, color, bold);

return { text: fontedText, nextCounter: fieldedText.nextCounter };
};
Expand Down
1 change: 1 addition & 0 deletions tgui/packages/tgui/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DOMPurify from 'dompurify';
// Default values
const defTag = [
'b',
'blockquote',
'br',
'center',
'code',
Expand Down

0 comments on commit 5a4f85f

Please sign in to comment.