Skip to content

Commit 7234919

Browse files
committed
add 'resource list to table'
1 parent bfea623 commit 7234919

File tree

11 files changed

+6169
-0
lines changed

11 files changed

+6169
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ A web tool for The Sims 2 modders that converts [SimPe](https://modthesims.info/
66
Hover over interface elements (e.g. buttons, icons, text areas) to see explanations of what they do.
77

88
![BHAV to Mermaid diagram tool appearance](readme-images/bhav-to-diagram.png)
9+
10+
# Resource list to table
11+
https://cosmatevs.github.io/resource-list-to-table.html
12+
13+
A web tool for The Sims 2 modders that converts [SimPe](https://modthesims.info/showthread.php?t=630456) resource lists to HTML and [Mod The Sims](https://modthesims.info/) BBCode tables. The tool includes group and type names, and allows to sort the rows of the generated code.
14+
15+
It's intended to make preparing technical descriptions for mods easier. [See an example of how it can be used.](https://modthesims.info/d/688444#overridden%20resources)
16+
17+
Hover over interface elements (e.g. buttons, icons, text areas) to see explanations of what they do.
18+
19+
![Resource list to table tool appearance](readme-images/resource-list-to-table.png)

assets/icons/mod-the-sims.svg

Lines changed: 4 additions & 0 deletions
Loading

assets/icons/sort-ascending.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/icons/sort-descending.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/icons/sort.svg

Lines changed: 4 additions & 0 deletions
Loading

assets/ts2-resource-info.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict';
2+
3+
const ts2ResourceInfo = {};
4+
5+
/** Parses a tsv/csv file with data into an array and a map.
6+
*
7+
* The file must have column names in its first row.
8+
* The column 'id' must be a hex number. It will be used in the map as the key. */
9+
ts2ResourceInfo.parseToArrayAndMap = async function (fileUrl, valueSeparator, entryLoadedCallback = entry => {}) {
10+
let fileFetchResponse = await fetch(fileUrl);
11+
let fileContents = await fileFetchResponse.text();
12+
13+
let fileLines = fileContents.split(/\r?\n/g);
14+
let columnNames = fileLines.shift().split(valueSeparator); // the first line
15+
16+
let valueArray = [];
17+
let valueMap = new Map();
18+
19+
fileLines.forEach(line => {
20+
line = line.trim();
21+
if (line.length == 0)
22+
return;
23+
24+
let values = line.split(valueSeparator).map(value => value.trim());
25+
let entry = {};
26+
for (let i = 0; i < columnNames.length; i++) {
27+
entry[columnNames[i]] =
28+
values[i] === undefined || values[i].length == 0
29+
? null
30+
: values[i];
31+
}
32+
valueArray.push(entry);
33+
entryLoadedCallback(entry);
34+
35+
let entryId = parseInt(entry.id, 16);
36+
valueMap.set(entryId, entry);
37+
});
38+
39+
return {
40+
array: valueArray,
41+
map: valueMap
42+
};
43+
}
44+
45+
/* Groups */
46+
47+
ts2ResourceInfo.initializeGroups = async function () {
48+
let groupInfos = await ts2ResourceInfo.parseToArrayAndMap('database/ts2-group-info.txt', '\t');
49+
50+
groupInfos.array.forEach(groupInfo =>
51+
groupInfo.parent = groupInfos.map.get(parseInt(groupInfo.parentId, 16)) ?? null
52+
);
53+
54+
ts2ResourceInfo.groupInfoArray = groupInfos.array;
55+
ts2ResourceInfo.groupInfoMap = groupInfos.map;
56+
}
57+
58+
ts2ResourceInfo.getAllGroups = function () {
59+
if (ts2ResourceInfo.groupInfoArray === undefined)
60+
throw Error('Group info must be initialized first with initializeGroups()');
61+
62+
return ts2ResourceInfo.groupInfoArray;
63+
}
64+
65+
ts2ResourceInfo.getGroupById = function (id) {
66+
if (ts2ResourceInfo.groupInfoMap === undefined)
67+
throw Error('Group info must be initialized first with initializeGroups()');
68+
69+
return ts2ResourceInfo.groupInfoMap.get(Number(id));
70+
}
71+
72+
/* Types
73+
ts2-type-info.txt is based on https://github.com/sims-hacker-zone/SimPE/blob/autinerd/avalonia/SimPe/SimPe/Data/FileTypes.cs */
74+
75+
ts2ResourceInfo.initializeTypes = async function () {
76+
let typeInfos = await ts2ResourceInfo.parseToArrayAndMap(
77+
'database/ts2-type-info.txt',
78+
'\t',
79+
entry => entry.canHaveName = !!entry.canHaveName // convert to bool
80+
);
81+
82+
ts2ResourceInfo.typeInfoArray = typeInfos.array;
83+
ts2ResourceInfo.typeInfoMap = typeInfos.map;
84+
}
85+
86+
ts2ResourceInfo.getAllTypes = function () {
87+
if (ts2ResourceInfo.typeInfoArray === undefined)
88+
throw Error('Type info must be initialized first with initializeTypes()');
89+
90+
return ts2ResourceInfo.typeInfoArray;
91+
}
92+
93+
ts2ResourceInfo.getTypeById = function (id) {
94+
if (ts2ResourceInfo.typeInfoMap === undefined)
95+
throw Error('Type info must be initialized first with initializeTypes()');
96+
97+
return ts2ResourceInfo.typeInfoMap.get(Number(id));
98+
}

0 commit comments

Comments
 (0)