Skip to content
Snippets Groups Projects
Commit 9927f1c8 authored by Stuffed's avatar Stuffed
Browse files

Adapt startingGirls to the <<options>> macro

parent 2dae17a4
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,13 @@ $GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- src/*.tw | gr
$GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord"
# check for $ sign at beginning of macro
$GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart"
# check our custom option macro is either options,option,optionlt,optionlte,optiongt,optiongte,optiondefault
$GREP -e '<<option' --and --not -e "<<option\(\|s\|lt\|lte\|gt\|gte\|default\)[ >]" -- 'src/*' | myprint "OptionUnrecognized"
# check our custom option macro is: <<option variable "somestring"
$GREP -e "<<option[lg]te\? " --and --not -e "<<option[lg]te\? *-\?[0-9]\+ *-\?[0-9]\+ *[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments"
$GREP -e "<<optiondefault " --and --not -e "<<optiondefault *\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\) *[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments"
$GREP -e "<<option\([lg]t\?\|default\) *>" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments"
$GREP -e "<<option " --and --not -e "<<option *\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\) *[\`\'\"].*[\'\"\`]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments"
# check for missing ; before statement
$GREP 'if $ ' -- 'src/*' | myprint "missing ; before statement"
$GREP 'elseif $ ' -- 'src/*' | myprint "missing ; before statement"
......@@ -96,6 +103,7 @@ $GREP 'elseif $ ' -- 'src/*' | myprint "missing ; before statement"
$GREP "<<[a-zA-Z]\([^\"'>]\|[^\"'>]>[^\"'>]\)*[a-zA-Z][.][^a-zA-Z]" | myprint "StrangeCharacterAfterDot"
# Check for @@. instead of .@@
$GREP -E "@@(\.|,|;|:)\s" -- src/*.tw | myprint "WrongSelectorPunctuation"
$GREP "@@[a-z]\+;" -- 'src/*' | myprint "@@MisingDot"
# Check that we do not have any variables that we use only once. e.g. $onlyUsedOnce
# Ignore *Nationalities
......
......@@ -1275,7 +1275,7 @@ __''Mods''__
@@.cyan;ENABLED.@@ [[Disable|Intro Summary][$SF.Facility.Toggle = 0]]
<</if>> //Prep for future content.*/
<br><br>
<br>
<<options $cyberMod>>
Cybernetics mod is
......@@ -1288,8 +1288,6 @@ __''Mods''__
<</options>>
<br>
<br><br>
<<options $secExp>>
The Security Expansion Mod is
<<option 0 "Disable">>
......
......@@ -17,6 +17,7 @@
.optionDescription {
display: block;
width: unset;
text-align: left;
}
.optionMacro {
......@@ -72,13 +73,23 @@
box-sizing: border-box;
}
.optionValue {
display: inline-flex;
flex-wrap: wrap;
}
.optionValue input {
padding: 3px;
background: linear-gradient(transparent,#222);
border: #555 solid 0.5px;
border-top-width: 0;
min-width: reset;
min-width: unset;
width: 140px;
height: 22px;
}
.optionMacroNumber input {
width: 50px;
}
.optionValue input:last-child {
......
......@@ -7,17 +7,25 @@
<<comment>>
Some comment to add at the end
<</option>>
optionlt and optionslte lets you also specifiy a 'less than' or 'less than or
equal' value, to show an option as selected if it is less than this amount
(and not selected by a previous option)
<<optionlt "less than value" "value_to_set_varname_to" "English text to show user" "additional variables to set when clicked" "Extra english text to show, but not as a link">>
*/
Macro.add('options', {
skipArgs : false,
tags : ['option', 'comment'],
tags : ['option', 'comment', 'optionlt', 'optionlte', 'optiongt', 'optiongte', 'optiondefault'],
handler : function () {
try {
var currentOption = this.payload[0].args[0];
var currentOptionIsNumber = typeof currentOption === "number";
var variable = null;
var title = this.payload[0].contents || '';
var passageName = this.payload[0].args[1] || passage();
var found = false;
var found_index = 0;
var comment = null;
var hasMultipleOptionsWithSameValue = false;
var description = "";
......@@ -44,9 +52,41 @@ Macro.add('options', {
if (this.payload[i].args[0] === currentOption) {
if (found) {
hasMultipleOptionsWithSameValue = true;
} else {
description = this.payload[i].contents;
found_index = i;
found = true;
}
}
} else if (this.payload[i].name === 'optionlt') {
if (!found && this.payload[i].args[0] > currentOption) {
description = this.payload[i].contents;
found = true;
found_index = i;
}
} else if (this.payload[i].name === 'optionlte') {
if (!found && this.payload[i].args[0] >= currentOption) {
description = this.payload[i].contents;
found = true;
found_index = i;
}
} else if (this.payload[i].name === 'optiongt') {
if (!found && this.payload[i].args[0] < currentOption) {
description = this.payload[i].contents;
found = true;
found_index = i;
}
} else if (this.payload[i].name === 'optiongte') {
if (!found && this.payload[i].args[0] <= currentOption) {
description = this.payload[i].contents;
found = true;
found_index = i;
}
} else if (this.payload[i].name === 'optiondefault') {
if (!found) {
description = this.payload[i].contents;
found = true;
found_index = i;
}
} else if (this.payload[i].name === 'comment') {
comment = this.payload[i].contents;
......@@ -61,28 +101,32 @@ Macro.add('options', {
/* Now print out the list of options */
var output = "";
for (var i = 1, len = this.payload.length; i < len; ++i) {
if (this.payload[i].name === 'option') {
if (this.payload[i].name.startsWith('option')) {
var args = this.payload[i].args;
var hasComparitor = this.payload[i].name !== "option" && this.payload[i].name !== "optiondefault";
var argText = args[hasComparitor ? 2 : 1] || "";
if (args.length === 0) {
output += this.payload[i].contents.trim();
} else {
var extraComment = args[3] ? (' ' + args[3]) : '';
var extraComment = args[hasComparitor ? 4: 3];
extraComment = extraComment ? ' ' + extraComment : '';
// We use a very crude heuristic for styling 'Enable'
// and 'Disable' buttons differently.
const isEnableOption = args[1].startsWith("Enable") || args[1] === "Yes" || args[1].startsWith("Allow");
const isDisableOption = args[1].startsWith("Disable") || args[1] === "No" || args[1].startsWith("Deny");
const isEnableOption = argText && (argText.startsWith("Enable") || argText === "Yes" || argText.startsWith("Allow"));
const isDisableOption = argText && (argText.startsWith("Disable") || argText === "No" || argText.startsWith("Deny"));
var className = "optionMacroOption " + (isEnableOption ? "optionMacroEnable" : isDisableOption ? "optionMacroDisable" : "");
if (args[0] !== currentOption || hasMultipleOptionsWithSameValue) {
var onClickChange = args[2] ? (', ' + args[2]) : '';
output += '<span class="' + className + '">[[' + args[1] + extraComment + '|' + passageName + "][" + variable + " = " + JSON.stringify(args[0]) + onClickChange + "]]" + "</span>";
if (found_index !== i || hasMultipleOptionsWithSameValue) {
var onClickChange = args[hasComparitor ? 3 : 2];
onClickChange = onClickChange ? ', ' + onClickChange : '';
output += '<span class="' + className + '">[[' + argText + extraComment + '|' + passageName + "][" + variable + " = " + JSON.stringify(args[hasComparitor ? 1 : 0]) + onClickChange + "]]" + "</span>";
} else if (showSelectedOption) {
output +='<span class="optionMacroSelected ' + className + '">' + args[1] + extraComment + '</span>';
output +='<span class="optionMacroSelected ' + className + '">' + argText + extraComment + '</span>';
}
}
}
}
jQuery(this.output).wiki(
'<span class="optionMacro">' +
'<span class="optionMacro ' + (currentOptionIsNumber ? 'optionMacroNumber' : '') + '">' +
'<span class="optionDescription">' + title + ' ' + description + "</span>" +
'<span class="optionValue">' + output + "</span>" +
(comment ? '<span class="optionComment">//' + comment + "//</span>" : '') +
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment