]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow exporting menu credits to data/data/credits.txt with the menu_credits_export...
authorterencehill <piuntn@gmail.com>
Wed, 9 Mar 2022 16:14:36 +0000 (17:14 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 9 Mar 2022 16:14:36 +0000 (17:14 +0100)
qcsrc/menu/xonotic/credits.qc
xonotic-client.cfg

index 7d096a90ad35d8d0ecb98d9d5f19cb98e14d7eaa..0c15803fe761f52aaff04eaad290fb828ce095ca 100644 (file)
                PERSON(... and a goat) \
                /**/
 
-int credits_get()
+
+int CREDITS_TYPE_TITLE = 2;
+int CREDITS_TYPE_FUNCTION = 1;
+int CREDITS_TYPE_PERSON = 0;
+int CREDITS_TYPE_NL = -1;
+void credits_add_line(int fh, int n, int type, string line)
 {
-       int n = buf_create();
-       #define CREDITS_TITLE(t) bufstr_add(n, strcat("**", t), 0);
-       #define CREDITS_FUNCTION(f) bufstr_add(n, strcat("*", f), 0);
-       #define CREDITS_PERSON(p) bufstr_add(n, p, 0);
+       if (type == CREDITS_TYPE_TITLE)
+               line = strcat("**", line);
+       else if (type == CREDITS_TYPE_FUNCTION)
+               line = strcat("*", line);
+
+       if (fh >= 0)
+               fputs(fh, strcat(line, "\n"));
+       if (n >= 0)
+               bufstr_add(n, line, 0);
+}
+
+void credits_build(int fh, int n)
+{
+       #define CREDITS_TITLE(t) credits_add_line(fh, n, CREDITS_TYPE_TITLE, t);
+       #define CREDITS_FUNCTION(f) credits_add_line(fh, n, CREDITS_TYPE_FUNCTION, f);
+       #define CREDITS_PERSON(p) credits_add_line(fh, n, CREDITS_TYPE_PERSON, p);
        #define _CREDITS_PERSON(p) CREDITS_PERSON(#p)
-       #define CREDITS_NL() bufstr_add(n, "", 0);
-    CREDITS(CREDITS_TITLE, CREDITS_FUNCTION, _CREDITS_PERSON, CREDITS_PERSON, CREDITS_NL)
+       #define CREDITS_NL() credits_add_line(fh, n, CREDITS_TYPE_NL, "");
+       CREDITS(CREDITS_TITLE, CREDITS_FUNCTION, _CREDITS_PERSON, CREDITS_PERSON, CREDITS_NL)
        #undef CREDITS_TITLE
        #undef CREDITS_FUNCTION
        #undef CREDITS_PERSON
        #undef _CREDITS_PERSON
        #undef CREDITS_NL
+}
+
+int credits_get()
+{
+       int n = buf_create();
+       credits_build(-1, n);
        return n;
 }
 
+void credits_export()
+{
+       int fh = fopen("credits.txt", FILE_WRITE);
+       if(fh < 0)
+               return;
+       credits_build(fh, -1);
+}
+
 #undef CREDITS
 
 entity makeXonoticCreditsList()
@@ -435,8 +466,13 @@ entity makeXonoticCreditsList()
 void XonoticCreditsList_configureXonoticCreditsList(entity me)
 {
        me.configureXonoticListBox(me);
-    me.bufferIndex = credits_get();
+       me.bufferIndex = credits_get();
        me.nItems = buf_getsize(me.bufferIndex);
+       if (cvar("_menu_credits_export")) // set by the menu_credits_export alias
+       {
+               credits_export();
+               cvar_set("_menu_credits_export", "0");
+       }
 }
 void XonoticCreditsList_destroy(entity me)
 {
index c5777051871e81e8e8c6fce4f8fc7fff04835ab6..09602a54325dfac4dce504df1bea44e8570d6087 100644 (file)
@@ -487,6 +487,9 @@ set menu_showboxes 0 "show item bounding boxes (debug)"
 set menu_cvarlist_onlymodified 0 "show only modified cvars in the cvar list"
 set menu_force_on_disconnection 1 "force to show the menu this number of seconds after you get disconnected (0 to disable)"
 
+set _menu_credits_export 0 "set to 1 and restart the menu to export credits to credits.txt (menu will automatically reset to 0)"
+alias menu_credits_export "_menu_credits_export 1; menu_restart"
+
 r_textbrightness 0.2
 r_textcontrast 0.8
 r_textshadow 0