From: Carl Worth Date: Fri, 18 Jan 2008 18:41:13 +0000 (-0800) Subject: Add a fancy HTML-based board display so it's possible to play with pidgin, say. X-Git-Url: https://git.cworth.org/git?p=loudgame;a=commitdiff_plain;h=2d34d2899a2a20e08675a17158daf73db188c54a Add a fancy HTML-based board display so it's possible to play with pidgin, say. --- diff --git a/lg-set.c b/lg-set.c index 94bebc3..fa0e5dd 100644 --- a/lg-set.c +++ b/lg-set.c @@ -249,18 +249,71 @@ static void set_game_handle_show (set_game_t *game, const char *peer) { + LmMessage *reply; + LmMessageNode *html, *body, *span; + gboolean result; + GError *error = NULL; board_t *board = &game->board; char board_str[BOARD_MAX_SLOTS * (NUM_ATTRIBUTES + 1)]; char *s; - int i, j; + int slot, pos, attr; + + reply = lm_message_new (peer, LM_MESSAGE_TYPE_MESSAGE); + html = lm_message_node_add_child (reply->node, "html", ""); + lm_message_node_set_attribute (html, + "xmlns", + "http://jabber.org/protocol/xhtml-im"); + body = lm_message_node_add_child (html, "body", ""); + lm_message_node_set_attribute (body, + "xmlns", + "http://www.w3.org/1999/xhtml"); s = board_str; - for (i = 0; i < board->num_slots; i++) { - if (board->slots[i].has_card) { - for (j = 0; j < NUM_ATTRIBUTES; j++) - *s++ = '0' + board->slots[i].card.attributes[j]; + for (slot = 0; slot < board->num_slots; slot++) { + if (slot % 4 == 0) + lm_message_node_add_child (body, "br", ""); + if (board->slots[slot].has_card) { + char card_str[5]; + char *style; + card_t card = board->slots[slot].card; + for (pos = 0; pos < 3; pos++) { + if (pos <= card.attributes[ATTRIBUTE_INDEX_NUMBER]) { + switch (card.attributes[ATTRIBUTE_INDEX_SYMBOL]) { + case SYMBOL_OVAL: + card_str[pos] = 'O'; + break; + case SYMBOL_SQUIGGLE: + card_str[pos] = 'S'; + break; + case SYMBOL_DIAMOND: + default: + card_str[pos] = 'X'; + break; + } + } else { + card_str[pos] = ' '; + } + } + card_str[3] = ' '; + card_str[4] = '\0'; + span = lm_message_node_add_child (body, "span", + card_str); + style = g_strdup_printf ("font-family: Monospace; color: %s;%s%s", + attribute_values[ATTRIBUTE_INDEX_COLOR][ + card.attributes[ATTRIBUTE_INDEX_COLOR]], + card.attributes[ATTRIBUTE_INDEX_SHADING] + == SHADING_SOLID ? "font-weight: bold;" : "", + card.attributes[ATTRIBUTE_INDEX_SHADING] + == SHADING_STRIPED ? "text-decoration: underline;" : ""); + lm_message_node_set_attribute (span, "style", style); + free (style); + for (attr = 0; attr < NUM_ATTRIBUTES; attr++) + *s++ = '0' + board->slots[slot].card.attributes[attr]; *s++ = ' '; } else { + span = lm_message_node_add_child (body, "span", " "); + lm_message_node_set_attribute (span, "style", + "font-family: Monospace;"); *s++ = '-'; *s++ = '-'; *s++ = '-'; @@ -269,7 +322,16 @@ set_game_handle_show (set_game_t *game, } *s = '\0'; - loudgame_send (&game->lg, peer, board_str); + lm_message_node_add_child (reply->node, "body", board_str); + + result = lm_connection_send (game->lg.connection, reply, &error); + lm_message_unref (reply); + + if (! result) { + g_error ("lm_connection_send failed: %s\n", + error->message); + loudgame_quit (&game->lg, 1); + } } static void