代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
import sys
import re
if len(sys.argv) != 2:
name = input('element name: ')
else:
name = sys.argv[1]
if re.search('[^A-Z0-9-]', name):
sys.exit('element names should only contain uppercase letters, digits and hyphens (you can change the Name property of the element to whatever later though, which is what shows up in menus)')
path = 'src/simulation/elements/' + name + '.cpp'
def get_elements():
elements = dict()
with open('src/simulation/ElementNumbers.h', 'r') as numbers:
for nm, pt in re.findall('ELEMENT_DEFINE\\s*\\(\\s*(\\S+)\\s*,\\s*(\\d+)\\s*\\)', numbers.read()):
elements[nm] = int(pt)
return elements
elements = get_elements()
if name in elements:
sys.exit('element already exists')
max_id = 0
for nm, pt in elements.items():
pt_id = int(pt)
if max_id < pt_id:
max_id = pt_id
new_id = max_id + 1
with open(path, 'w') as elem:
elem.write(r"""#include "simulation/ElementCommon.h"
static int update(UPDATE_FUNC_ARGS);
static int graphics(GRAPHICS_FUNC_ARGS);
void Element::Element_{0}()
{{
Identifier = "DEFAULT_PT_{0}";
Name = "{0}";
Colour = PIXPACK(0xFFFFFF);
MenuVisible = 1;
MenuSection = SC_SPECIAL;
Enabled = 1;
// element properties here
Update = &update;
Graphics = &graphics;
}}
static int update(UPDATE_FUNC_ARGS)
{{
// update code here
return 0;
}}
static int graphics(GRAPHICS_FUNC_ARGS)
{{
// graphics code here
// return 1 if nothing dymanic happens here
return 0;
}}
""".format(name))
elem.close()
print('element file \'{0}\' successfully created '.format(path))
input('now add \'ELEMENT_DEFINE({0}, {1});\' to \'src/simulation/ElementNumbers.h\', then press enter'.format(name, str(new_id)))
while True:
elements = get_elements()
if name in elements and elements[name] == new_id:
break
input('nope; try doing that again, then press enter')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。