|
246 | 246 | ; me think that the U3REALITY and TRADINGCOST files are for backwards compatibility only. |
247 | 247 | ; Much investigation needed to figure out the right set. |
248 | 248 |
|
249 | | -; Strangely, loading build recipes from the items files did not cause conflicts with any of the build recipes I had hand-entered |
250 | | -; in recipes.rkt, which mostly came from the Wiki. Makes me wonder - need to test in-game. Are one of these two sources wrong? Am I missing a source? |
251 | | - |
252 | | -; File METADATA\REALITY\DEFAULTREALITY.EXML looks to have refiner recipes in it! Ooh, this actually looks like the right starting point |
253 | | -; for a lot of stuff! |
254 | | - |
255 | 249 | ; Read items first, put placeholder for name text. Then translate placeholders.(define build-recipes null) |
256 | 250 |
|
257 | 251 | (define (read-default-reality root) |
|
266 | 260 | (raise-argument-error 'read-default-reality |
267 | 261 | "Expected <Data template='GcRealityManagerData' ... " |
268 | 262 | (format "<~a template='~a'" (element-name doc) template-type))) |
| 263 | + |
| 264 | + ; Grab the names of the reality tables, which contain definitions for items. |
269 | 265 | (define technology-table (get-filename "TechnologyTable")) |
270 | 266 | (define substance-table (get-filename "SubstanceTable")) |
271 | 267 | (define product-table (get-filename "ProductTable")) |
| 268 | + |
| 269 | + ; Refiner recipes are stored directly in the default reality doc. |
272 | 270 | (define raw-refiner-recipes (read-refiner-recipes doc)) |
273 | | - (set! doc null) ; Free up memory immediately |
| 271 | + |
| 272 | + ; We're done with the top-level doc; free up the memory its XML rep uses. |
| 273 | + (set! doc null) |
| 274 | + |
| 275 | + ; Now we load all the item in. Items also often have a primary crafting recipe associated |
| 276 | + ; with them. The name-id-map is keyed by an identifier for a language-specific name. The |
| 277 | + ; mapping of these names to items is not unique, so each map entry is a list of data for |
| 278 | + ; multiple items. |
| 279 | + ; |
| 280 | + ; The save-id (often just called the id in this program) identifies items in the save file, |
| 281 | + ; and *is* a unique but not user-friendly identifier for each item. |
274 | 282 | (define name-id-map (make-hash)) |
275 | 283 | (define save-id-set (mutable-set)) |
276 | 284 | (load-item-table-doc technology-table "GcTechnologyTable" save-id-set name-id-map) |
277 | 285 | (load-item-table-doc substance-table "GcSubstanceTable" save-id-set name-id-map) |
278 | 286 | (load-item-table-doc product-table "GcProductTable" save-id-set name-id-map) |
279 | 287 | ;(load-item-table-doc (build-path root (names-value doc "ProceduralProductTable")) "GcProceduralProductTable" save-id-set name-id-map) |
| 288 | + |
| 289 | + ; Next, find English translations for each item based on the name-id. In the process |
| 290 | + ; of doing these, we also turn the item data into actual item$ struct objects. The |
| 291 | + ; English names are used to generate name-symbols that are used a lot in the program |
| 292 | + ; to identify items. (This was convenient when items were being defined manually, and is |
| 293 | + ; still useful when debugging, but is not strictly necessary anymore -- the save-ids would suffice.) |
280 | 294 | (define all-item-data (apply append (hash-values name-id-map))) ; Save for later... |
281 | 295 | (define id-map (make-hash)) |
| 296 | + ; By default, my game seems to be using U.K. English rather than U.S. English, so let's stick with that. |
282 | 297 | (scan-localization-table (build-path root "LANGUAGE/NMS_LOC1_ENGLISH.EXML") "English" name-id-map id-map) |
283 | 298 | (scan-localization-table (build-path root "LANGUAGE/NMS_LOC4_ENGLISH.EXML") "English" name-id-map id-map) |
284 | 299 | (scan-localization-table (build-path root "LANGUAGE/NMS_UPDATE3_ENGLISH.EXML") "English" name-id-map id-map) |
| 300 | + |
| 301 | + ; Report some results. |
285 | 302 | (printf "Found and translated ~a items.~n" (length (hash-keys id-map))) |
286 | 303 | (unless (null? (hash-keys name-id-map)) |
287 | 304 | (printf "Missing translations for ~a items:~n" (length (hash-keys name-id-map))) |
288 | 305 | (for ([(key value) name-id-map]) |
289 | 306 | (printf " ~a: ~a~n" key value))) |
290 | | - (define (id->name id) |
291 | | - (define item (hash-ref id-map id #f)) |
292 | | - (and item (item$-name item))) |
| 307 | + |
| 308 | + ; Make up fake names for the items for which we found no translation. Let's |
| 309 | + ; hope they don't show up in the UI, but if they do we might have to figure out |
| 310 | + ; why we didn't find user-friendly names for them. |
293 | 311 | (for ([lst (hash-values name-id-map)]) |
294 | 312 | (for ([i lst]) |
295 | 313 | (define item-fake-name (string->symbol (first i))) |
296 | 314 | (define id (first i)) |
297 | 315 | (hash-set! id-map id (item$ item-fake-name id (second i) (third i) id)))) |
| 316 | + |
| 317 | + ; The basic and refiner recipes are currently expressed in terms of save-ids. Translate |
| 318 | + ; these to item names. |
| 319 | + (define (id->name id) |
| 320 | + (define item (hash-ref id-map id #f)) |
| 321 | + (and item (item$-name item))) |
298 | 322 | (define build-recipes |
299 | 323 | (for/list ([item all-item-data] |
300 | 324 | #:when (> (length item) 3)) |
|
316 | 340 | result]))) |
317 | 341 | (values (hash-values id-map) build-recipes refiner-recipes)) |
318 | 342 |
|
319 | | -(define-values |
320 | | - (items build-recipes refiner-recipes) |
| 343 | +(define-values (items build-recipes refiner-recipes) |
321 | 344 | (read-default-reality root)) |
322 | | -(pretty-print (list 'Flags (sort (remove-duplicates (append-map (λ (v) (item$-flags v)) items)) symbol<?))) |
323 | | - |
324 | 345 |
|
325 | | -; By default, my game seems to be using U.K. English rather than U.S. English, so let's stick with that. |
326 | | - |
327 | | -; Attempted additional scans to find missing items; no luck. |
328 | | -;(scan-localization-table (build-path root "LANGUAGE/NMS_LOC4_ENGLISH.EXML") "English" name-id-map id-map) |
| 346 | +; Show developer what "flags" we found for items: |
| 347 | +(pretty-print (list 'Flags (sort (remove-duplicates (append-map (λ (v) (item$-flags v)) items)) symbol<?))) |
329 | 348 |
|
330 | 349 | (define (write-generated-items) |
331 | 350 | (call-with-output-file (build-path output-root "generated-items.rkt") #:mode 'text #:exists 'replace |
|
0 commit comments