Merge remote-tracking branch 'upstream/develop' into docs

develop
myk002 2022-07-20 16:33:50 -07:00
commit 0b88922ffc
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 71 additions and 216 deletions

@ -1,12 +1,13 @@
#!/usr/bin/env python3
import os
from os.path import basename, dirname, join, splitext
from os.path import basename, dirname, exists, join, splitext
import sys
SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts'
DOCS_PATH = join(SCRIPT_PATH, 'docs')
IS_GITHUB_ACTIONS = bool(os.environ.get('GITHUB_ACTIONS'))
def expected_cmd(path):
def get_cmd(path):
"""Get the command from the name of a script."""
dname, fname = basename(dirname(path)), splitext(basename(path))[0]
if dname in ('devel', 'fix', 'gui', 'modtools'):
@ -14,16 +15,6 @@ def expected_cmd(path):
return fname
def check_ls(fname, line):
"""Check length & existence of leading comment for "ls" builtin command."""
line = line.strip()
comment = '--' if fname.endswith('.lua') else '#'
if '[====[' in line or not line.startswith(comment):
print_error('missing leading comment (requred for `ls`)', fname)
return 1
return 0
def print_error(message, filename, line=None):
if not isinstance(line, int):
line = 1
@ -32,48 +23,42 @@ def print_error(message, filename, line=None):
print('::error file=%s,line=%i::%s' % (filename, line, message))
def check_ls(docfile, lines):
"""Check length & existence of first sentence for "ls" builtin command."""
# TODO
return 0
def check_file(fname):
errors, doclines = 0, []
tok1, tok2 = ('=begin', '=end') if fname.endswith('.rb') else \
('[====[', ']====]')
doc_start_line = None
with open(fname, errors='ignore') as f:
errors, doc_start_line = 0, None
docfile = join(DOCS_PATH, get_cmd(fname)+'.rst')
if not exists(docfile):
print_error('missing documentation file: {!r}'.format(docfile), fname)
return 1
with open(docfile, errors='ignore') as f:
lines = f.readlines()
if not lines:
print_error('empty file', fname)
print_error('empty documentation file', docfile)
return 1
errors += check_ls(fname, lines[0])
for i, l in enumerate(lines):
if doclines or l.strip().endswith(tok1):
if not doclines:
doc_start_line = i + 1
doclines.append(l.rstrip())
if l.startswith(tok2):
break
else:
if doclines:
print_error('docs start but do not end', fname, doc_start_line)
else:
print_error('no documentation found', fname)
return 1
if not doclines:
print_error('missing or malformed documentation', fname)
return 1
l = l.strip()
if l and not doc_start_line and doc_start_line != 0:
doc_start_line = i
doc_end_line = i
lines[i] = l
title, underline = [d for d in doclines
if d and '=begin' not in d and '[====[' not in d][:2]
title_line = doc_start_line + doclines.index(title)
errors += check_ls(docfile, lines)
title, underline = lines[doc_start_line:doc_start_line+2]
expected_underline = '=' * len(title)
if underline != expected_underline:
print_error('title/underline mismatch: expected {!r}, got {!r}'.format(
expected_underline, underline),
fname, title_line + 1)
docfile, doc_start_line+1)
errors += 1
if title != expected_cmd(fname):
if title != get_cmd(fname):
print_error('expected script title {!r}, got {!r}'.format(
expected_cmd(fname), title),
fname, title_line)
get_cmd(fname), title),
docfile, doc_start_line)
errors += 1
return errors

@ -1 +1 @@
Subproject commit 2196764977011991127244b28ff13b90cef19af3
Subproject commit a04727cc4ec350399ce4d2ded4425f33c50cea50

@ -153,55 +153,19 @@ void selectWord (const df::language_word_table &table, int32_t &word, df::part_o
}
}
void generateName(df::language_name &output, int language, df::language_name_type mode, const df::language_word_table &table1, const df::language_word_table &table2)
void generateName(df::language_name &output, int language, const df::language_word_table &table1, const df::language_word_table &table2)
{
for (int i = 0; i < 100; i++)
{
if (mode != 8 && mode != 9)
{
output = df::language_name();
if (language == -1)
language = rng.df_trandom(world->raws.language.translations.size());
output.type = mode;
output.type = language_name_type::Artifact;
output.language = language;
}
output.has_name = 1;
if (output.language == -1)
output.language = rng.df_trandom(world->raws.language.translations.size());
int r, r2, r3;
switch (mode)
{
case language_name_type::Figure:
case language_name_type::FigureNoFirst:
case language_name_type::FigureFirstOnly:
if (mode != 9)
{
int32_t word; df::part_of_speech part;
output.first_name.clear();
selectWord(table1, word, part, 2);
if (word >= 0 && size_t(word) < world->raws.language.words.size())
output.first_name = *world->raws.language.translations[language]->words[word];
}
if (mode != 10)
{
case language_name_type::Site:
case language_name_type::Monument:
if (rng.df_trandom(2))
{
selectWord(table2, output.words[0], output.parts_of_speech[0], 0);
selectWord(table1, output.words[1], output.parts_of_speech[1], 1);
}
else
{
selectWord(table1, output.words[0], output.parts_of_speech[0], 0);
selectWord(table2, output.words[1], output.parts_of_speech[1], 1);
}
}
break;
case language_name_type::Artifact:
case language_name_type::Unk13:
case language_name_type::River:
r = rng.df_trandom(3);
if (r == 0 || r == 1)
{
@ -218,9 +182,6 @@ void generateName(df::language_name &output, int language, df::language_name_typ
}
if (r == 1 || r == 2)
{
case language_name_type::Squad:
case language_name_type::LegendaryFigure:
case language_name_type::ArtImage: // this is not a typo either
r2 = rng.df_trandom(2);
if (r2)
selectWord(table1, output.words[5], output.parts_of_speech[5], 2);
@ -259,97 +220,6 @@ void generateName(df::language_name &output, int language, df::language_name_typ
else
selectWord(table2, output.words[4], output.parts_of_speech[4], 4);
}
if ((mode == 3) && (output.parts_of_speech[5] == part_of_speech::Noun) && (output.words[5] != -1) && (world->raws.language.words[output.words[5]]->forms[1].length()))
output.parts_of_speech[5] = part_of_speech::NounPlural;
break;
case language_name_type::Civilization:
case language_name_type::World:
case language_name_type::Region:
case language_name_type::AdventuringGroup:
case language_name_type::SiteGovernment:
case language_name_type::NomadicGroup:
case language_name_type::Vessel:
case language_name_type::MilitaryUnit:
case language_name_type::Religion:
case language_name_type::MountainPeak:
case language_name_type::Temple:
case language_name_type::Keep:
case language_name_type::MeadHall:
case language_name_type::Unk24:
case language_name_type::Unk25:
case language_name_type::Unk26:
case language_name_type::Market:
case language_name_type::Tavern:
case language_name_type::War:
case language_name_type::Battle:
case language_name_type::Siege:
case language_name_type::Road:
case language_name_type::Wall:
case language_name_type::Bridge:
case language_name_type::Tunnel:
case language_name_type::PretentiousEntityPosition:
case language_name_type::Tomb:
case language_name_type::OutcastGroup:
selectWord(table1, output.words[5], output.parts_of_speech[5], 2);
r3 = rng.df_trandom(3);
if (rng.df_trandom(50))
r3 = rng.df_trandom(2);
switch (r3)
{
case 0:
case 2:
selectWord(table2, output.words[6], output.parts_of_speech[6], 5);
if (r3 == 0)
break;
case 1:
selectWord(table2, output.words[2], output.parts_of_speech[2], 3);
if (!(rng.df_trandom(100)))
selectWord(table2, output.words[3], output.parts_of_speech[3], 3);
break;
}
if (rng.df_trandom(100))
selectWord(table2, output.words[4], output.parts_of_speech[4], 4);
break;
case language_name_type::Dungeon:
r = rng.df_trandom(3);
if (r == 0 || r == 1)
{
selectWord(table2, output.words[0], output.parts_of_speech[0], 0);
selectWord(table1, output.words[1], output.parts_of_speech[1], 1);
}
if (r == 1 || r == 2)
{
r2 = rng.df_trandom(2);
if (r == 2 || r2 == 1)
selectWord(table1, output.words[5], output.parts_of_speech[5], 2);
else
selectWord(table2, output.words[5], output.parts_of_speech[5], 2);
r3 = rng.df_trandom(3);
if (rng.df_trandom(50))
r3 = rng.df_trandom(2);
switch (r3)
{
case 0:
case 2:
selectWord(table1, output.words[6], output.parts_of_speech[6], 5);
if (r3 == 0)
break;
case 1:
selectWord(table2, output.words[2], output.parts_of_speech[2], 3);
if (!(rng.df_trandom(100)))
selectWord(table2, output.words[3], output.parts_of_speech[3], 3);
break;
}
}
if (rng.df_trandom(100))
selectWord(table2, output.words[4], output.parts_of_speech[4], 4);
break;
default:
// not handled yet
break;
}
if (output.words[2] != -1 && output.words[3] != -1 &&
world->raws.language.words[output.words[3]]->adj_dist < world->raws.language.words[output.words[2]]->adj_dist)
{
@ -1351,10 +1221,10 @@ command_result df_strangemood (color_ostream &out, vector <string> & parameters)
// Generate the artifact's name
if (type == mood_type::Fell || type == mood_type::Macabre)
generateName(unit->status.artifact_name, unit->name.language, language_name_type::Artifact, world->raws.language.word_table[0][2], world->raws.language.word_table[1][2]);
generateName(unit->status.artifact_name, unit->name.language, world->raws.language.word_table[0][2], world->raws.language.word_table[1][2]);
else
{
generateName(unit->status.artifact_name, unit->name.language, language_name_type::Artifact, world->raws.language.word_table[0][1], world->raws.language.word_table[1][1]);
generateName(unit->status.artifact_name, unit->name.language, world->raws.language.word_table[0][1], world->raws.language.word_table[1][1]);
if (!rng.df_trandom(100))
unit->status.artifact_name = unit->name;
}

@ -1 +1 @@
Subproject commit ef5fc459c4f0a65a9fd709c14fed0c5892c9eebd
Subproject commit dbdfacd33a213f081fbb1d6c85c11424ce3df234