;;-*-Lisp-*-
(in-package goal)

;; name: text-h.gc
;; name in dgo: text-h
;; dgos: ENGINE, GAME

;; NOTE - for progress
(define-extern disable-level-text-file-loading "Disables [[*level-text-file-load-flag*]]" (function none))
(define-extern enable-level-text-file-loading "Disables [[*level-text-file-load-flag*]]" (function none))
(define-extern load-game-text-info
  "Load text, if needed. txt-name is the group name, curr-text is the _symbol_ for
   the game-text-info, and heap is the heap to load to. The heap will be cleared."
  (function string (pointer object) kheap int))
(define-extern print-game-text "Print text." (function string font-context symbol int bucket-id float))

;; DECOMP BEGINS

(deftype game-text (structure)
  ((id    text-id)
   (text  string)
   )
  :pack-me
  )


(deftype game-text-info (basic)
  ((length       int32)
   (language-id  int32)
   (group-name   string)
   (data         game-text  :inline :dynamic)
   )
  (:methods
    (lookup-text! (_type_ text-id symbol) string)
    )
  )


(define *text-group-names* (new 'static 'boxed-array :type string "common"))

(define *common-text-heap* (new 'global 'kheap))

(define *common-text* (the-as game-text-info #f))

;; og:preserve-this
;; NOTE - PC PORT difference
;; Partial translations are a thing that we should support. Parts of translating the game are intentionally made
;; difficult for normal translators due to not wanting to make all the strings public (or in the case of subtitles,
;; we straight up didn't have them yet)
;;
;; So to remedy this, we always load the english text as a fallback so that if there is only a partial translation
;; the UX won't be horrible with everything displaying as UNKNOWN.
;;
;; One of the reasons we didn't do this is because it makes it obvious which strings are remaining,
;; but there are better ways to keep track or check if strings are missing.
(#when PC_PORT
  (kheap-alloc (define *fallback-text-heap* (new 'global 'kheap)) (* 48 1024)) ;; 48K heap, should be plenty
  (define *fallback-text* (the-as game-text-info #f)))
