diff options
| author | Simon <simon@hardwired.org.uk> | 2011-01-31 22:10:34 (GMT) |
|---|---|---|
| committer | Simon <simon@hardwired.org.uk> | 2011-01-31 22:10:34 (GMT) |
| commit | b033a9655d8a6670d207a172329b54daa8f30493 (patch) | |
| tree | e15f94c374f3ad9b372359b2bc414e0993c04e88 /src/interface.c | |
| parent | 5ec884993f62a37ded46ff1008c31dc8e0b4e8f4 (diff) | |
| parent | d52fa30a45f24ad8cb5e8669c7128b193b517590 (diff) | |
| download | powder-b033a9655d8a6670d207a172329b54daa8f30493.zip powder-b033a9655d8a6670d207a172329b54daa8f30493.tar.gz | |
Fix for liquids - jacksonmj
Diffstat (limited to 'src/interface.c')
| -rw-r--r-- | src/interface.c | 137 |
1 files changed, 116 insertions, 21 deletions
diff --git a/src/interface.c b/src/interface.c index 43c66e8..5d23a5d 100644 --- a/src/interface.c +++ b/src/interface.c @@ -872,7 +872,7 @@ void login_ui(pixel *vid_buf) if (!s_id) goto fail; *(s_id++) = 0; - + u_e = strchr(s_id, ' '); if (!u_e){ u_e = malloc(1); @@ -884,9 +884,9 @@ void login_ui(pixel *vid_buf) strcpy(svf_user_id, res+3); strcpy(svf_session_id, s_id); nres = mystrdup(u_e); - + printf("\n{%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres); - + if (!strncmp(nres, "ADMIN", 5)) { svf_admin = 1; @@ -3862,17 +3862,20 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show mx /= sdl_scale; my /= sdl_scale; ed.focus = 1; - + clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); - drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.1 (by cracker64)\n" - "Current commands are quit, set, reset, load\n" - "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" - "You can also use 'all' instead of a particle number to do it to everything\n" - "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" - "To load a save use load saveID (ex. load 1337)" - ,255, 187, 187, 255); - + drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n" + "Current commands are quit, set, reset, load, create, file\n" + "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" + "You can also use 'all' instead of a particle number to do it to everything.\n" + "You can now use particle names (ex. set type all deut)\n" + "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" + "To load a save use load saveID (ex. load 1337)\n" + "Create particles with 'create deut x,y' where x and y are the coords\n" + "Run scripts from file 'file filename'" + ,255, 187, 187, 255); + cc = 0; currentcommand = last_command; while(cc < 10) @@ -3884,18 +3887,18 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show { if(cc<9) { currentcommand = currentcommand->prev_command; - } else if(currentcommand->prev_command!=NULL){ + } else if(currentcommand->prev_command!=NULL) { free(currentcommand->prev_command); currentcommand->prev_command = NULL; } cc++; - } + } else { break; } } - + if(error) drawtext(vid_buf, 15, 190, error,255, 187, 187, 255); ui_edit_draw(vid_buf, &ed); @@ -3927,18 +3930,18 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } else { - if(last_command!=NULL){ + if(last_command!=NULL) { currentcommand = last_command; for (cc = 0; cc<ci; cc++) { if(currentcommand->prev_command==NULL) ci = cc; - else + else currentcommand = currentcommand->prev_command; } strcpy(ed.str, currentcommand->command); ed.cursor = strlen(ed.str); } - else + else { ci = -1; strcpy(ed.str, ""); @@ -3946,9 +3949,101 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } } } - } - - + return NULL; } +int console_parse_type(char *txt, int *element, char *err) +{ + int i = atoi(txt); + char num[4]; + if (i>=0 && i<PT_NUM) + { + sprintf(num,"%d",i); + if (strcmp(txt,num)==0) + { + *element = i; + return 1; + } + } + i = -1; + // alternative names for some elements + if (strcasecmp(txt,"C4")==0) i = PT_PLEX; + else if (strcasecmp(txt,"C5")==0) i = PT_C5; + else if (strcasecmp(txt,"NONE")==0) i = PT_NONE; + if (i>=0) + { + *element = i; + return 1; + } + for (i=1; i<PT_NUM; i++) { + if (strcasecmp(txt,ptypes[i].name)==0) + { + *element = i; + return 1; + } + } + strcpy(err, "Particle type not recognised"); + return 0; +} +int console_parse_coords(char *txt, int *x, int *y, char *err) +{ + // TODO: use regex? + char *coordtxt; + char num[10] = ""; + int nx = -1, ny = -1; + txt = mystrdup(txt); + coordtxt = strtok(txt, ","); + if (coordtxt) nx = atoi(coordtxt); + if (nx>=0 && nx<XRES) sprintf(num,"%d",nx); + if (!coordtxt || strcmp(coordtxt, num)!=0) + { + strcpy(err,"Invalid coordinates"); + free(txt); + return 0; + } + strcpy(num,""); + coordtxt = strtok(NULL, ","); + if (coordtxt) ny = atoi(coordtxt); + if (ny>=0 && ny<YRES) sprintf(num,"%d",ny); + if (!coordtxt || strcmp(coordtxt, num)!=0) + { + strcpy(err,"Invalid coordinates"); + free(txt); + return 0; + } + *x = nx; + *y = ny; + free(txt); + return 1; +} +int console_parse_partref(char *txt, int *which, char *err) +{ + // TODO: use regex? + int i = -1, nx, ny; + if (console_parse_coords(txt, &nx, &ny, err)) + { + i = pmap[ny][nx]; + if (!i || (i>>8)>=NPART) + i = -1; + else + i = i>>8; + } + else if (txt) + { + char *num = (char*)malloc(strlen(txt)+3); + strcpy(err,""); // suppress error message from failed coordinate parsing + i = atoi(txt); + sprintf(num,"%d",i); + if (!txt || strcmp(txt,num)!=0) + i = -1; + free(num); + } + if (i>=0 && i<NPART && parts[i].type) + { + *which = i; + return 1; + } + strcpy(err,"Particle does not exist"); + return 0; +} |
