Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog System #22

Merged
merged 23 commits into from Sep 11, 2011
Merged

Dialog System #22

merged 23 commits into from Sep 11, 2011

Conversation

giselher
Copy link
Collaborator

@giselher giselher commented Sep 8, 2011

Yes the dialog system is finished (and partly tested).

The documentation is still missing and it needs more testing, but I like to have it in staging so that people can look at it and find mistakes or stuff that could be done better. It is also very error prone and it may segfault on broken dlg.xml (my suffix suggestion for dialog files) files. But still have a look it and tell me what you think.

In the next few days I like to build a proper test suite and more dialog files. Also better handling of wrong name nodes in the xml files.

#include "dialog.h"

/* set_speaker, set_player_exp, render_text, render_choices, get_choice and others are all
 * made up functions for demonstration */
int main (void)
{
    int choice = 0;
    req_t *req = NULL;  /* dialog requirement type */
    dlg_content_t *con = NULL;
    dlg_t *dlg = dlg_parse_file("path/to/file.xml"); /* dialog root type pulse file parsing*/

    /* check dialog requirements */
    while ((req = dlg_requirement_next(dlg)) != NULL) {
        if (req->type == EVENT)
            check_requirement_event (req->action.event);
        /* and so on */
     }

    /* dlg_content_next will return NULL if the conversation has ended */

    while ((con = dlg_content_next(dlg, choice)) != NULL) {

        if (con->type == TEXT) {
            set_speaker(con->action.text.actor_id);
            render_text("%s\n", con->action.text.text);
        }
        if (con->type == SET_EXP)
            set_player_exp(con->action.exp);

        if (con->type == CHOICES) {
            /* descriptions is a GPtrArray from glib */
            set_speaker(con->action.choices.actor_id);
            render_choices(con->action.choices.decscriptions); 
            choice = get_choice(); 
        }
    }

    /* and so on, look at dialog.h for more dialog types */
    dlg_free (dlg);
    return 0;
}

I hope this code example does a good job on explaining how it works.
EDIT: You have all rights to hurt me if you saw my earlier usage of the switch statement in my commit history.
EDIT2: I forgot that It also features requirments for dialogs.
EDIT3: More usable example with new function

Basic functions are:
 * xml_parse_doc  - Parse the xml file
 * xml_verify_doc - Verify if it is the right document by checking the
                    root node.
 * xml_free_doc   - Free the allocated memory by the use document
 * cleanup_xml    - Free all allocated memory used by the parser

Not used but confirmed for working.

Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
Most Improtant libxml2 types are:
 * XML_ELEMENT_NODE
 * XML_TEXT_NODE
 * XML_COMMENT_NODE

Also added documentation for xml_node_t and xml_type_t

Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
dlg_parse_file and dlg_free are the only functions at the moment

dlg_content_next (or similar) will be the next one to implement

Renamed functions in xml.c and xml.h
Segfaults on broken dialog files

Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
Documentation still missing.

Signed-off-by: Alexander Preisinger <alexander.preisinger@gmail.com>
@giselher
Copy link
Collaborator Author

giselher commented Sep 9, 2011

I also implemented the function dlg_requirement_next to be more consistent and you don't have to directly interact with glib2.

@MattWindsor91
Copy link
Owner

Yeah, I see no reason why not to merge this. Go!

MattWindsor91 added a commit that referenced this pull request Sep 11, 2011
@MattWindsor91 MattWindsor91 merged commit 8677e8c into staging Sep 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants