Difference between revisions of "SoC2011 Student Page Aethaeryn"

From The Battle for Wesnoth Wiki
(linking to GSOC application)
m (a bunch of comments to remind me where I still need to finish)
Line 37: Line 37:
  
 
===Phase 1: Complex Interface Changes===
 
===Phase 1: Complex Interface Changes===
 +
<!-- fixme: rewrite in the style of the two phases and expand -->
 +
 
* Implement improved Lua access to the in-scenario GUI stuff, again without WML table hacks.
 
* Implement improved Lua access to the in-scenario GUI stuff, again without WML table hacks.
 
** This includes improving the syntax and implementation of the [http://wiki.wesnoth.org/LuaWML:Display#wesnoth.show_dialog dialog Lua].
 
** This includes improving the syntax and implementation of the [http://wiki.wesnoth.org/LuaWML:Display#wesnoth.show_dialog dialog Lua].
Line 47: Line 49:
  
 
==The Implementation: Details==
 
==The Implementation: Details==
''I'm sleeping. This section will be filled out when I can think again.
+
<!-- expand -->
  
 
===Phase 0===
 
===Phase 0===
 +
<!-- expand -->
 +
 
====Sample Syntax====
 
====Sample Syntax====
 
  local msg = gui_message{
 
  local msg = gui_message{
Line 82: Line 86:
  
 
===Phase 1===
 
===Phase 1===
 +
<!-- expand -->
 +
 
====Dialog Improvements====
 
====Dialog Improvements====
 
====GUI 2 Access====
 
====GUI 2 Access====
Line 87: Line 93:
  
 
===Phase 2===
 
===Phase 2===
 +
<!-- expand -->
 +
 
====Sample syntax====
 
====Sample syntax====
 
The final goal is to use wesnoth.ui.show() to hide almost all of the interface details by providing a syntactical shortcut to the functions in Phase 0 and Phase 1. More complexity will be possible, as in sample2, but the extremely basic sample1 will be legal syntax as well.
 
The final goal is to use wesnoth.ui.show() to hide almost all of the interface details by providing a syntactical shortcut to the functions in Phase 0 and Phase 1. More complexity will be possible, as in sample2, but the extremely basic sample1 will be legal syntax as well.
Line 144: Line 152:
  
 
==Goals==
 
==Goals==
 +
<!-- expand -->
  
 
==Patches==
 
==Patches==
 +
<!-- expand -->
 
''Work on the Phase 0 patches will resume immediately after this document is finished and submitted.
 
''Work on the Phase 0 patches will resume immediately after this document is finished and submitted.
  

Revision as of 19:11, 8 April 2011


This page is related to Summer of Code 2011
See the list of Summer of Code 2011 Ideas



This is a Summer of Code 2011 student page
Project: SoC_Ideas_Your_Own_Ideas2011



Description

Michael Babich - Improving Lua's User Interface Capabilities

I intend to improve the ability for add-ons to customize the user interface through Lua. I will focus on providing simple, but powerful syntax for a set of functions that will enable add-on creators to have improved, easier access to features that already exist within the game engine so that they are free to creatively provide more innovative content.

The purpose of this project is to act as a middleman between the game engine and the add-on creators using the Lua scripting language so that simple and powerful add-on creation can help revolutionize future MP, just as [set_menu_item] and [option] allowed for a great evolution in the quality of add-ons since 1.3. This interface framework needs to be as broad as possible in the time given and the scope allowed so that creative add-on authors themselves can stretch Wesnoth content far beyond its traditional style, but it also must provide a simplified Lua helper library so that everyone can use it without necessarily having to delve deeply into the complexity that exists in the currently-existing GUI.

IRC

Aethaeryn

Introduction

I have been making content for Wesnoth since 2007 and I have been gradually porting much of my more advanced content to Lua since late 2009. While doing so, I have noticed certain limitations to the current implementation of Lua as it relates to add-on creation, especially with certain elements only possible through WML or the rather poorly readable WML tables. As the title suggests, I wish to simply and extend the add-on creation capabilities in Lua. In particular, I will be working with various elements of the interface code because this is currently where Lua is weak and often just relying on WML tables. There are several problems with using WML tables in these areas:

  • Poor readability, clumsy syntax, and verbosity. The metatable in the helper library helps with readability, but does not always work (for instance on [or] and [and] boxes, where those words are reserved in Lua) and it still hides the underlying issue that true native Lua support is not there. It also is fairly difficult in certain applications where the XML-style WML syntax is clearly inferior and much more verbose than something done in pure Lua.
  • You're essentially using WML. This defeats the purpose of using Lua in the first place if the majority of your code in a particular area is in WML. This is made even more severe when one realizes that many of the areas that must currently be done via WML tables are complex things that are the kind of things best done in a real language in the first place. In particular, the [message], [option], and [set_menu_item] have no real Lua equivalent.
  • Calling Lua from WML tables is hacky. Currently, if one wants to call a Lua function from T.option {}, one has to set a string that is a call on a global Lua function.

An ideal scenario or campaign would be one that uses WML to define the basic structure and then call on Lua for any more advanced elements. As I spend most of my Wesnoth time making -- or playing -- content for MP that do things that WML was not originally intended to do, such as making Wesnoth an RPG instead of a TBS, I have noticed that WML does not scale very well as a general purpose language doing advanced scripting. Any traditional language, such as Lua, can handle certain advanced things in a much more readable and efficient manner, but there are certain gaps in Lua where WML tables must be integrated with the Lua, which defeats many of the primary reasons to use Lua in the first place.

Fortunately, the solution is rather obvious to the WML table problem. Lua needs to be extended to access features that almost all already exist in the game engine and these must be implemented through Lua functions and tables instead of WML tables so that the full benefits of using Lua for scripting can be realized. Although the problem and solution are fairly easy to describe, certain precautions must be taken to make ensure that save games are not broken and no new issues are introduced. In addition, the individual proposed changes must be enumerated for clarity as to the scope of the project.

The Implementation: Overview

The information can roughly be broken down into three separate phases, 0 through 2. First, I shall go through an overview so as to be straightforward with the overall planned changes, then I shall provide the details of each individual section, and finally I shall propose a detailed timeline as to when each part can be accomplished.

Phase 0: The Initial Changes

First, src/scripting/lua.cpp should be split into smaller, logically-organized files so that the file does not grow too large and unmanageable with the improvements planned. This has the additional effect of allowing me to get familiar with the core Lua code.

Next, various UI tags shall be implemented in native Lua without WML tables. The hardest portion of this is ensuring that the Lua changes can be implemented without breaking save files. Most of the existing WML code can be reused, so a key purpose of this is to get rid of the need for WML tables for this portion of the code so that it better interacts with files written purely in Lua and so it is in a consistent style with code in the later portion of this project. The trickiest part will be implementing the callback, which will allow menu options to trigger Lua functions.

Because the code already exists to handle the WML tags, most of the work is allowing these Lua functions to utilize already-existing code in the engine. In this phase, the Lua functions to be created more or less map one-to-one with WML tags, which is why this would be a "Phase 0". On the surface, the changes may seem subtle, but it will allow for a more Lua way of implementing these than WML tables, which will improve interaction with Lua scripting functions while also making the Lua side of Wesnoth scripting easier to learn. In addition, it will ensure that these very central UI actions are consistent with Phase 1 syntax.

The related WML tags that need to be ported to Lua functions:

  • [message]
    • [option]
    • [text_input]
  • [set_menu_item]

Phase 1: Complex Interface Changes

  • Implement improved Lua access to the in-scenario GUI stuff, again without WML table hacks.
    • This includes improving the syntax and implementation of the dialog Lua.
  • A way to take in text commands in a way similar to debug mode's :lua, but only using specific commands to do specific actions as defined by Lua code in the add-on.

Phase 2: Simplify Add-on Creation

Phase 0 and Phase 1 might seem somewhat unrelated, but Phase 2 is intended to unify them under a common, easily-accessible package of sorts that provides a highly-abstracted, clean syntax for add-on authors to manipulate various elements of the UI. The original implementation from Phases 0 and 1 will still exist for those who want more control and customization, while Phase 2 will make things available for those who do not wish to necessarily deal with the complexity. There are two areas that will allow the improvements to be immediately accessible in an easy manner to content authors:

  • I will implement a Lua "wesnoth.ui" that adds an additional abstraction layer on top of the already existing syntax, simplifying the appearance of the code at the expense of some finer control.
  • If I have the time, I will create new, defined-in-Lua WML tags that utilize wesnoth.ui so that one does not have to use Lua to benefit from the improvements to Lua.

The Implementation: Details

Phase 0

Sample Syntax

local msg = gui_message{
   message  = "Hello world!",
   settings = {
      speaker = "narrator",
      image   = "wesnoth.png"
   },
   options  = {
         { text='hello', callback = foobar() },
         { text='goodbye', callback = say_goodbye() }
    }}

local msg2 = gui_message{
   message = "What's your name?",
   -- no "settings =" makes it set reasonable defaults
   -- text_input takes either a table containing the information, or a table of tables that are all valid text_input
   text_input = {variable = "foo", label = "Name: ", max_length = 42}
}

if side = host then
   msg.show

function foobar()
   msg2.show

gui_message()

option

callback

text_input

set_menu_item()

Phase 1

Dialog Improvements

GUI 2 Access

Commands?

Phase 2

Sample syntax

The final goal is to use wesnoth.ui.show() to hide almost all of the interface details by providing a syntactical shortcut to the functions in Phase 0 and Phase 1. More complexity will be possible, as in sample2, but the extremely basic sample1 will be legal syntax as well.

sample1  = {message = "Hello world"}
sample2 = {message = {"Hello world", options = {speaker = "Konrad", side_for = 1}}}
wesnoth.ui.show(sample1)
wesnoth.ui.show(sample2)

This will allow for possibilities like the following, where the GUI message is literally as simple as providing one string:

function message_all(messageText)
   wesnoth.ui.show{message = messageText}

wesnoth.ui

WML additions

The Implementation: Timeline

now April 08 - April 22  

Pre-Summer I

Discuss details of the implementation with various developers in order to finalize most of the project's design.

Work on basic patches, especially in the early areas of Phase 0, so that commit access can be granted before the designated GSOC period.

April 23 - May 08

Continue to familiarize myself with the project and its code by doing more of Phase 0.

May 09 - May 18 Spring semester ends. Availability may be limited during this period.
May 19 - May 30

Summer I

Phase 0 ends; Phase 1 beings. My schedule is be entirely free in this time span.

May 31 - June 30

Summer II

The entire month of June will be spent on Phase 1. I will balance my time with a summer semester, but should have Fridays through Sundays entirely free.

July 4 - July 8 Expected busy week as my one summer course wraps up.
July 9 - July 17

Middle of GSOC

Phase 1 ends. The largest portion of the project, Phase 1, should be concluding around this point.

Since this is around the middle evaluation point, part of the focus should be on reviewing the design and plans for the second half of GSOC. If I am ahead of schedule or behind schedule, adjustments can be made.

July 18 - July 22 Summer semester ends. Expected busy week as my other summer course wraps up.
July 23 - August 15 

Summer III

Phase 2 begins. Again, my schedule should be entirely free to focus on the project.

August 15

Pencils Down Date

According to Google: "Take a week to scrub code, write tests, improve documentation, etc."

lim t
t→∞
Continue to work on Wesnoth's Lua scripting capabilities because it certainly will take more than just one summer to perfect it.

By this time, I will have had enough experience with Wesnoth's Lua implementation that I'll find new things that bother me with the Lua, and hopefully that will provide something to do in summer 2012.

Goals

Patches

Work on the Phase 0 patches will resume immediately after this document is finished and submitted.

Questionnaire

SoC Application

Battle for Wesnoth - Google Summer of Code Application