Skip to content

Commit 45b6dbd

Browse files
committed
tpt++: pavg0 / pavg1 properties can be set through the console and prop ca0eece
1 parent cce32ed commit 45b6dbd

3 files changed

Lines changed: 38 additions & 59 deletions

File tree

src/interface.cpp

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,17 +1645,15 @@ char propValue[255] = "";
16451645
void prop_edit_ui(pixel *vid_buf)
16461646
{
16471647
pixel * o_vid_buf;
1648-
int format;
1649-
size_t propoffset;
1650-
char *listitems[] = {"type", "life", "ctype", "temp", "tmp", "tmp2", "vy", "vx", "x", "y", "dcolour", "flags"};
1651-
int listitemscount = 12;
1648+
int format, propoffset = -1;
1649+
char *listitems[] = {"type", "life", "ctype", "temp", "tmp", "tmp2", "vy", "vx", "x", "y", "dcolour", "flags", "pavg0", "pavg1"};
1650+
int listitemscount = 14;
16521651
int xsize = 244;
16531652
int ysize = 87;
16541653
int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my;
16551654
ui_list ed;
16561655
ui_edit ed2;
16571656
PropTool* propTool = (PropTool*)GetToolFromIdentifier("DEFAULT_UI_PROPERTY");
1658-
bool name = false;
16591657

16601658
ed.x = x0+8;
16611659
ed.y = y0+25;
@@ -1731,60 +1729,18 @@ void prop_edit_ui(pixel *vid_buf)
17311729
}
17321730
}
17331731

1734-
if(ed.selected != -1)
1735-
{
1736-
if (!strcmp(ed.str, "type")) {
1737-
propoffset = offsetof(particle, type);
1738-
format = 1;
1739-
name = true;
1740-
} else if (!strcmp(ed.str,"life")) {
1741-
propoffset = offsetof(particle, life);
1742-
format = 0;
1743-
} else if (!strcmp(ed.str,"ctype")) {
1744-
propoffset = offsetof(particle, ctype);
1745-
format = 1;
1746-
} else if (!strcmp(ed.str,"temp")) {
1747-
propoffset = offsetof(particle, temp);
1748-
format = 2;
1749-
} else if (!strcmp(ed.str,"tmp")) {
1750-
propoffset = offsetof(particle, tmp);
1751-
format = 0;
1752-
} else if (!strcmp(ed.str,"tmp2")) {
1753-
propoffset = offsetof(particle, tmp2);
1754-
format = 0;
1755-
} else if (!strcmp(ed.str,"vy")) {
1756-
propoffset = offsetof(particle, vy);
1757-
format = 2;
1758-
} else if (!strcmp(ed.str,"vx")) {
1759-
propoffset = offsetof(particle, vx);
1760-
format = 2;
1761-
} else if (!strcmp(ed.str,"x")) {
1762-
propoffset = offsetof(particle, x);
1763-
format = 2;
1764-
} else if (!strcmp(ed.str,"y")) {
1765-
propoffset = offsetof(particle, y);
1766-
format = 2;
1767-
} else if (!strcmp(ed.str,"dcolour")) {
1768-
propoffset = offsetof(particle, dcolour);
1769-
format = 3;
1770-
} else if (!strcmp(ed.str,"flags")) {
1771-
propoffset = offsetof(particle, flags);
1772-
format = 3;
1773-
}
1774-
} else {
1732+
if (ed.selected != -1)
1733+
{
1734+
propoffset = luacon_particle_getproperty(ed.str, &format);
1735+
}
1736+
if (propoffset == -1)
1737+
{
17751738
error_ui(vid_buf, 0, "Invalid property");
17761739
goto exit;
17771740
}
17781741

1779-
propTool->propOffset = propoffset;
1780-
if (format == 0)
1781-
{
1782-
int value;
1783-
sscanf(ed2.str, "%d", &value);
1784-
propTool->propValue.Integer = value;
1785-
propTool->propType = Integer;
1786-
}
1787-
else if (format == 1)
1742+
propTool->propOffset = (size_t)propoffset;
1743+
if (format == 2 || !strcmp(ed.str, "ctype")) //ctype is special here
17881744
{
17891745
unsigned int value;
17901746
int isint = 1;
@@ -1809,15 +1765,22 @@ void prop_edit_ui(pixel *vid_buf)
18091765
goto exit;
18101766
}
18111767
}
1812-
if (name && (value < 0 || value > PT_NUM || !ptypes[value].enabled))
1768+
if (format == 2 && (value < 0 || value > PT_NUM || !ptypes[value].enabled))
18131769
{
18141770
error_ui(vid_buf, 0, "Invalid element number");
18151771
goto exit;
18161772
}
18171773
propTool->propValue.UInteger = value;
18181774
propTool->propType = UInteger;
18191775
}
1820-
else if (format == 2)
1776+
else if (format == 0)
1777+
{
1778+
int value;
1779+
sscanf(ed2.str, "%d", &value);
1780+
propTool->propValue.Integer = value;
1781+
propTool->propType = Integer;
1782+
}
1783+
else if (format == 1)
18211784
{
18221785
float value;
18231786
sscanf(ed2.str, "%f", &value);

src/luaconsole.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ int luacon_partread(lua_State* l)
344344
{
345345
case 0:
346346
case 2:
347+
case 3:
347348
tempinteger = *((int*)(((char*)&parts[i])+offset));
348349
lua_pushnumber(l, tempinteger);
349350
break;
@@ -375,6 +376,7 @@ int luacon_partwrite(lua_State* l)
375376
switch(format)
376377
{
377378
case 0:
379+
case 3:
378380
*((int*)(((char*)&parts[i])+offset)) = luaL_optinteger(l, 3, 0);
379381
break;
380382
case 1:
@@ -441,10 +443,19 @@ int luacon_particle_getproperty(const char * key, int * format)
441443
*format = 1;
442444
} else if (!strcmp(key, "dcolour")) {
443445
offset = offsetof(particle, dcolour);
444-
*format = 0;
446+
*format = 3;
445447
} else if (!strcmp(key, "dcolor")) {
446448
offset = offsetof(particle, dcolour);
447-
*format = 0;
449+
*format = 3;
450+
} else if (!strcmp(key, "flags")) {
451+
offset = offsetof(particle, flags);
452+
*format = 3;
453+
} else if (!strcmp(key, "pavg0")) {
454+
offset = offsetof(particle, pavg[0]);
455+
*format = 1;
456+
} else if (!strcmp(key, "pavg1")) {
457+
offset = offsetof(particle, pavg[1]);
458+
*format = 1;
448459
} else {
449460
offset = -1;
450461
}
@@ -1685,6 +1696,8 @@ int luatpt_set_property(lua_State* l)
16851696
offset = luacon_particle_getproperty(prop, &format);
16861697
if (offset == -1)
16871698
return luaL_error(l, "Invalid property '%s'", prop);
1699+
else if (format == 3)
1700+
format = 0;
16881701

16891702
if (acount > 2)
16901703
{
@@ -1832,6 +1845,7 @@ int luatpt_get_property(lua_State* l)
18321845
{
18331846
case 0:
18341847
case 2:
1848+
case 3:
18351849
tempinteger = *((int*)(((unsigned char*)&parts[i])+offset));
18361850
lua_pushnumber(l, tempinteger);
18371851
break;

src/luascriptinterface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ int simulation_partProperty(lua_State * l)
435435
switch(format)
436436
{
437437
case 0:
438+
case 3:
438439
*((int*)(((unsigned char*)&parts[particleID])+offset)) = lua_tointeger(l, 3);
439440
break;
440441
case 1:
@@ -453,6 +454,7 @@ int simulation_partProperty(lua_State * l)
453454
{
454455
case 0:
455456
case 2:
457+
case 3:
456458
lua_pushnumber(l, *((int*)(((unsigned char*)&parts[particleID])+offset)));
457459
break;
458460
case 1:

0 commit comments

Comments
 (0)