This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SCsub
86 lines (67 loc) · 2.59 KB
/
SCsub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
Import('env')
Import('env_modules')
env_tove = env_modules.Clone()
env_tove.add_source_files(env.modules_sources, "*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/cpp/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/cpp/mesh/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/cpp/shader/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/cpp/gpux/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/thirdparty/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/thirdparty/polypartition/src/*.cpp")
env_tove.add_source_files(env.modules_sources, "tove2d/src/thirdparty/tinyxml2/tinyxml2.cpp")
import os
dir_path = Dir('.').abspath
env_tove.Append(CXXFLAGS=[
'-std=c++11',
'-DTOVE_GODOT',
'-I' + os.path.join(dir_path, 'tove2d/src/thirdparty/fp16/include')])
def package_sl(target, source, env):
with open(source[0].abspath, "r") as sl:
with open(target[0].abspath, "w") as out:
out.write('w << R"GLSL(\n')
out.write(sl.read())
out.write(')GLSL";\n')
env_tove.Append(BUILDERS={
'PackageSL':Builder(action=package_sl)})
env_tove.PackageSL(
'tove2d/src/glsl/fill.frag.inc',
Glob('tove2d/src/glsl/fill.frag'))
env_tove.PackageSL(
'tove2d/src/glsl/line.vert.inc',
Glob('tove2d/src/glsl/line.vert'))
# patching.
env_vars = Variables(None, ARGUMENTS)
env_vars.Add(EnumVariable(
'svg',
'patch for vector graphics svg support?',
'nopatch', allowed_values=('patch', 'nopatch')))
env_vars.Update(env)
if env['svg'] == 'patch':
declare_vector_sprite = '''
Node *createVectorSprite(Ref<Resource> p_resource);
void configureVectorSprite(Node *p_child, Ref<Resource> p_texture);
'''
replace_create = (
('child = memnew(Sprite);',
'child = createVectorSprite(texture);'),
('_create_nodes(target_node, child, path, drop_pos);',
'_create_nodes(target_node, child, path, drop_pos); configureVectorSprite(child, texture);')
)
editor_plugins_path = Dir('../../editor/plugins').abspath
file_path = os.path.join(editor_plugins_path, 'canvas_item_editor_plugin.cpp')
with open(file_path, 'r+') as f:
source_code = f.read()
if declare_vector_sprite not in source_code:
lines = source_code.split("\n")
include_index = None
for i, line in enumerate(lines):
if line.strip().startswith('#include'):
include_index = i
lines.insert(include_index + 1, declare_vector_sprite)
source_code = "\n".join(lines)
for a, b in replace_create:
source_code = source_code.replace(a, b)
f.seek(0)
f.write(source_code)
print("patched %s" % file_path)