Skip to content

Commit db7ec66

Browse files
author
danm
committed
Added more comments to parse-items.
Because of the forgetting thing.
1 parent e07272d commit db7ec66

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

parse-items.rkt

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@
246246
; me think that the U3REALITY and TRADINGCOST files are for backwards compatibility only.
247247
; Much investigation needed to figure out the right set.
248248

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-
255249
; Read items first, put placeholder for name text. Then translate placeholders.(define build-recipes null)
256250

257251
(define (read-default-reality root)
@@ -266,35 +260,65 @@
266260
(raise-argument-error 'read-default-reality
267261
"Expected <Data template='GcRealityManagerData' ... "
268262
(format "<~a template='~a'" (element-name doc) template-type)))
263+
264+
; Grab the names of the reality tables, which contain definitions for items.
269265
(define technology-table (get-filename "TechnologyTable"))
270266
(define substance-table (get-filename "SubstanceTable"))
271267
(define product-table (get-filename "ProductTable"))
268+
269+
; Refiner recipes are stored directly in the default reality doc.
272270
(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.
274282
(define name-id-map (make-hash))
275283
(define save-id-set (mutable-set))
276284
(load-item-table-doc technology-table "GcTechnologyTable" save-id-set name-id-map)
277285
(load-item-table-doc substance-table "GcSubstanceTable" save-id-set name-id-map)
278286
(load-item-table-doc product-table "GcProductTable" save-id-set name-id-map)
279287
;(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.)
280294
(define all-item-data (apply append (hash-values name-id-map))) ; Save for later...
281295
(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.
282297
(scan-localization-table (build-path root "LANGUAGE/NMS_LOC1_ENGLISH.EXML") "English" name-id-map id-map)
283298
(scan-localization-table (build-path root "LANGUAGE/NMS_LOC4_ENGLISH.EXML") "English" name-id-map id-map)
284299
(scan-localization-table (build-path root "LANGUAGE/NMS_UPDATE3_ENGLISH.EXML") "English" name-id-map id-map)
300+
301+
; Report some results.
285302
(printf "Found and translated ~a items.~n" (length (hash-keys id-map)))
286303
(unless (null? (hash-keys name-id-map))
287304
(printf "Missing translations for ~a items:~n" (length (hash-keys name-id-map)))
288305
(for ([(key value) name-id-map])
289306
(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.
293311
(for ([lst (hash-values name-id-map)])
294312
(for ([i lst])
295313
(define item-fake-name (string->symbol (first i)))
296314
(define id (first i))
297315
(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)))
298322
(define build-recipes
299323
(for/list ([item all-item-data]
300324
#:when (> (length item) 3))
@@ -316,16 +340,11 @@
316340
result])))
317341
(values (hash-values id-map) build-recipes refiner-recipes))
318342

319-
(define-values
320-
(items build-recipes refiner-recipes)
343+
(define-values (items build-recipes refiner-recipes)
321344
(read-default-reality root))
322-
(pretty-print (list 'Flags (sort (remove-duplicates (append-map (λ (v) (item$-flags v)) items)) symbol<?)))
323-
324345

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<?)))
329348

330349
(define (write-generated-items)
331350
(call-with-output-file (build-path output-root "generated-items.rkt") #:mode 'text #:exists 'replace

0 commit comments

Comments
 (0)