1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-16 22:14:23 +03:00
inform7/inter/index-module/Chapter 3/Alphabetic Element.w

108 lines
4 KiB
OpenEdge ABL
Raw Normal View History

2021-06-20 15:59:38 +03:00
[AlphabeticElement::] Alphabetic Element.
To write the Alphabetic actions element (A2) in the index.
2021-07-22 01:21:56 +03:00
@ This element is a simple three-column table.
=
2021-07-26 15:48:49 +03:00
void AlphabeticElement::render(OUTPUT_STREAM, index_session *session) {
localisation_dictionary *LD = Indexing::get_localisation(session);
tree_inventory *inv = Indexing::get_inventory(session);
2022-02-03 01:35:38 +02:00
InterNodeList::array_sort(inv->action_nodes, AlphabeticElement::alphabetical_order);
2021-06-20 15:59:38 +03:00
HTML::begin_html_table(OUT, NULL, FALSE, 0, 0, 0, 0, 0);
HTML::first_html_column(OUT, 0);
2021-07-24 01:32:44 +03:00
AlphabeticElement::column(OUT, I"ActionColumn", LD);
2021-06-20 15:59:38 +03:00
HTML::next_html_column(OUT, 0);
2021-07-24 01:32:44 +03:00
AlphabeticElement::column(OUT, I"NounColumn", LD);
2021-06-20 15:59:38 +03:00
HTML::next_html_column(OUT, 0);
2021-07-24 01:32:44 +03:00
AlphabeticElement::column(OUT, I"SecondColumn", LD);
2021-06-20 15:59:38 +03:00
HTML::end_html_row(OUT);
2021-07-25 00:04:35 +03:00
inter_package *an_pack;
LOOP_OVER_INVENTORY_PACKAGES(an_pack, i, inv->action_nodes) {
inter_ti assim = Metadata::read_optional_numeric(an_pack, I"^action_assimilated");
if (assim) continue;
inter_ti id = Metadata::read_numeric(an_pack, I"action_id");
inter_ti oow = Metadata::read_numeric(an_pack, I"^out_of_world");
2021-06-20 15:59:38 +03:00
inter_ti requires_light = Metadata::read_numeric(an_pack, I"^requires_light");
inter_ti can_have_noun = Metadata::read_numeric(an_pack, I"^can_have_noun");
inter_ti can_have_second = Metadata::read_numeric(an_pack, I"^can_have_second");
inter_ti noun_access = Metadata::read_numeric(an_pack, I"^noun_access");
inter_ti second_access = Metadata::read_numeric(an_pack, I"^second_access");
inter_symbol *noun_kind = Metadata::required_symbol(an_pack, I"^noun_kind");
inter_symbol *second_kind = Metadata::required_symbol(an_pack, I"^second_kind");
2021-06-20 15:59:38 +03:00
2021-07-22 01:21:56 +03:00
HTML::first_html_column(OUT, 0);
@<Action column@>;
2021-06-20 15:59:38 +03:00
HTML::next_html_column(OUT, 0);
2021-07-22 01:21:56 +03:00
@<Noun column@>;
2021-06-20 15:59:38 +03:00
HTML::next_html_column(OUT, 0);
2021-07-22 01:21:56 +03:00
@<Second noun column@>;
2021-06-20 15:59:38 +03:00
HTML::end_html_row(OUT);
}
HTML::end_html_table(OUT);
}
2021-07-22 01:21:56 +03:00
@<Action column@> =
if (oow) HTML::begin_span(OUT, I"indexdullred");
WRITE("%S", Metadata::optional_textual(an_pack, I"^name"));
if (oow) HTML::end_span(OUT);
IndexUtilities::detail_link(OUT, "A", (int) id, TRUE);
if (requires_light) { WRITE(" "); AlphabeticElement::note(OUT, I"Light", LD); }
2021-07-22 01:21:56 +03:00
@<Noun column@> =
if (can_have_noun == 0) {
WRITE("&mdash;");
} else {
if (noun_access == REQUIRES_ACCESS) AlphabeticElement::note(OUT, I"Touchable", LD);
if (noun_access == REQUIRES_POSSESSION) AlphabeticElement::note(OUT, I"Carried", LD);
WRITE("<b>");
2022-01-31 01:49:12 +02:00
IndexUtilities::kind_name(OUT, InterPackage::container(noun_kind->definition), FALSE, FALSE);
2021-07-22 01:21:56 +03:00
WRITE("</b>");
}
@<Second noun column@> =
if (can_have_second == 0) {
WRITE("&mdash;");
} else {
if (second_access == REQUIRES_ACCESS) AlphabeticElement::note(OUT, I"Touchable", LD);
if (second_access == REQUIRES_POSSESSION) AlphabeticElement::note(OUT, I"Carried", LD);
WRITE("<b>");
2022-01-31 01:49:12 +02:00
IndexUtilities::kind_name(OUT, InterPackage::container(second_kind->definition), FALSE, FALSE);
2021-07-22 01:21:56 +03:00
WRITE("</b>");
}
2021-07-24 01:32:44 +03:00
@ =
void AlphabeticElement::column(OUTPUT_STREAM, text_stream *key, localisation_dictionary *LD) {
TEMPORARY_TEXT(full)
WRITE_TO(full, "Index.Elements.A2.%S", key);
2021-07-26 02:34:51 +03:00
Localisation::bold(OUT, LD, full);
2021-07-24 01:32:44 +03:00
DISCARD_TEXT(full)
}
2021-07-22 01:21:56 +03:00
@ =
2021-07-21 02:38:26 +03:00
void AlphabeticElement::note(OUTPUT_STREAM, text_stream *key, localisation_dictionary *LD) {
2021-07-22 01:21:56 +03:00
TEMPORARY_TEXT(full)
WRITE_TO(full, "Index.Elements.A2.%S", key);
2021-07-26 02:34:51 +03:00
Localisation::italic(OUT, LD, full);
2021-07-22 01:21:56 +03:00
DISCARD_TEXT(full)
WRITE(" ");
2021-07-21 02:38:26 +03:00
}
2021-07-22 01:21:56 +03:00
@ This comparison function sorts actions in alphabetical order of name; by
default the inventory would have them in declaration order.
=
2021-06-20 15:59:38 +03:00
int AlphabeticElement::alphabetical_order(const void *ent1, const void *ent2) {
2022-02-03 01:35:38 +02:00
ina_entry *E1 = (ina_entry *) ent1;
ina_entry *E2 = (ina_entry *) ent2;
2021-06-20 15:59:38 +03:00
if (E1 == E2) return 0;
inter_tree_node *P1 = E1->node;
inter_tree_node *P2 = E2->node;
2022-03-01 02:41:22 +02:00
inter_package *an1_pack = PackageInstruction::at_this_head(P1);
inter_package *an2_pack = PackageInstruction::at_this_head(P2);
text_stream *an1_name = Metadata::optional_textual(an1_pack, I"^name");
text_stream *an2_name = Metadata::optional_textual(an2_pack, I"^name");
2021-06-20 15:59:38 +03:00
return Str::cmp(an1_name, an2_name);
}