9 Star 22 Fork 6

Powder-Toy-Sync/The-Powder-Toy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
newelement.py 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
#!/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')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Powder-Toy-Sync/the-powder-toy.git
[email protected]:Powder-Toy-Sync/the-powder-toy.git
Powder-Toy-Sync
the-powder-toy
The-Powder-Toy
master

搜索帮助