Changeset 9202152 in Readingame


Ignore:
Timestamp:
Apr 29, 2024, 7:05:34 PM (8 weeks ago)
Author:
PulkoMandy <pulkomandy@…>
Branches:
main
Children:
d6dc8dd
Parents:
2317cb2
Message:

Implement player identity

Have a startup window asking for name and gender before starting the
game. Fully implement @, {|}, %p and %n using these informations.

Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • main.cpp

    r2317cb2 r9202152  
    66
    77#include "HyperTextView.h"
     8#include "IdentityWindow.h"
    89
    910#include <Application.h>
     
    265266uint8_t gSavePC;
    266267uint8_t gGameStatus;
     268bool gGender;
     269BString gFirstName;
     270BString gLastName;
    267271
    268272uint32_t gLastRunScript;
     
    622626                                        {
    623627                                                // @ Gender mark (print an e if the player identifies as female)
    624                                                 // TODO we don't have a way to configure player gender yet
    625                                                 decoded += 'e';
     628                                                if (gGender)
     629                                                        decoded += 'e';
    626630                                                cursor++;
    627631                                                break;
     
    665669                        int icursor = cursor;
    666670                        // {%f3|%m2~%m3}
     671                        // {%c3|%m2|%m3|...}
     672                        // {male|female}
    667673                        cursor++;
    668                         if (message[cursor] != '%' || message[cursor + 1] != 'f') {
    669                                 fprintf(stderr, "Unknwown message conditional\n");
    670                                 return 1;
    671                         }
    672 
    673                         cursor += 2;
     674                        if (message[cursor] == '%') {
     675                                if ( message[cursor + 1] == 'f') {
     676                                        cursor += 2;
     677                                        return HandlePercentFConditional(message, cursor) + 3;
     678                                } else {
     679                                        fprintf(stderr, "Unknwown message conditional\n");
     680                                        return 2;
     681                                }
     682                        }
     683
     684                        int start, end;
     685
     686                        if (gGender) {
     687                                while(message[cursor] != '|')
     688                                        cursor++;
     689                                cursor++;
     690                                start = cursor;
     691                                while(message[cursor] != '}')
     692                                        cursor++;
     693                                end = cursor;
     694                                cursor++;
     695                        } else {
     696                                start = cursor;
     697                                while(message[cursor] != '|')
     698                                        cursor++;
     699                                end = cursor;
     700                                cursor++;
     701                                while(message[cursor] != '}')
     702                                        cursor++;
     703                                cursor++;
     704                        }
     705
     706                        std::string extracted = message.substr(start, end - start);
     707                        fMainText->Insert(extracted.c_str());
     708
     709                        return cursor - icursor;
     710                }
     711
     712                int HandlePercentFConditional(const std::string& message, int cursor)
     713                {
     714                        int icursor = cursor;
    674715
    675716                        int flagToCheck = ParseInt(message, cursor);
     
    718759                                i++;
    719760                        }
     761
     762                        // TODO links can contain escape sequences (for example @)
    720763
    721764                        while (message[cursor + i] != ']') {
     
    744787                                return 3;
    745788                        } else if (message[cursor] == 'p') {
    746                                 // Should show the player first name, not configurable yet
    747                                 decoded += "PRENOM";
     789                                decoded += gFirstName;
     790                                return 2;
     791                        } else if (message[cursor] == 'n') {
     792                                decoded += gLastName;
    748793                                return 2;
    749794                        } else {
     
    799844        void ReadyToRun() override
    800845        {
     846                BWindow* identity = new IdentityWindow();
     847                identity->Show();
     848                identity->CenterOnScreen();
     849
    801850                // TODO check if we have a game loaded
    802851                fMainWindow = new GameWindow();
     
    806855                fDebugWindow = new DebugWindow();
    807856
    808                 fMainWindow->Show();
    809                 fMainWindow->CenterOnScreen();
    810857
    811858                // TODO: only if asked from the command line
     
    816863                fDebugWindow->Update();
    817864
    818                 bool runNextLine = true;
    819                 int line = 0;
    820                 while (runNextLine && (line < gRooms[0].fScripts.size())) {
    821                         gSavePC = 0;
    822                         runNextLine = RunScriptLine(gRooms[0].fScripts[line]);
    823                         gLastRunScript = line;
    824                         line++;
    825                 }
    826                 fMainWindow->SetMainText(gRooms[gCurrentRoom].fMessages[gCurrentScreen - 1]);
    827                 fDebugWindow->Update();
    828865        }
    829866
    830867        void MessageReceived(BMessage* message) override
    831868        {
    832                 if (message->what < 256) {
     869                if (message->what == 'STRT') {
     870                        fMainWindow->Show();
     871                        fMainWindow->CenterOnScreen();
     872
     873                        bool runNextLine = true;
     874                        int line = 0;
     875                        while (runNextLine && (line < gRooms[0].fScripts.size())) {
     876                                gSavePC = 0;
     877                                runNextLine = RunScriptLine(gRooms[0].fScripts[line]);
     878                                gLastRunScript = line;
     879                                line++;
     880                        }
     881                        fMainWindow->SetMainText(gRooms[gCurrentRoom].fMessages[gCurrentScreen - 1]);
     882                        fDebugWindow->Update();
     883                } else if (message->what < 256) {
    833884                        gTrigger = message->what;
    834885
Note: See TracChangeset for help on using the changeset viewer.