This commit is contained in:
Lubos Lenco 2017-05-26 11:51:08 +02:00
parent 2632cabd50
commit d8da49bded
5 changed files with 14 additions and 76 deletions

View file

@ -2729,7 +2729,7 @@ class ArmoryExporter:
if t.type_prop == 'Logic Nodes' and t.nodes_name_prop != '':
x['type'] = 'Script'
x['class_name'] = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package) + '.node.' + arm.utils.safesrc(t.nodes_name_prop)
elif t.type_prop == 'JS Script' or t.type_prop == 'Python Script':
elif t.type_prop == 'JS Script':
basename = t.jsscript_prop.split('.')[0]
x['type'] = 'Script'
x['class_name'] = 'armory.trait.internal.JSScript'
@ -2737,32 +2737,12 @@ class ArmoryExporter:
scriptspath = arm.utils.get_fp_build() + '/compiled/scripts/'
if not os.path.exists(scriptspath):
os.makedirs(scriptspath)
# Compile to JS
if t.type_prop == 'Python Script':
# Write py to file
basename_ext = basename + '.py'
targetpath = scriptspath + basename_ext
with open(targetpath, 'w') as f:
f.write(bpy.data.texts[t.jsscript_prop].as_string())
sdk_path = arm.utils.get_sdk_path()
python_path = bpy.app.binary_path_python
cwd = os.getcwd()
os.chdir(scriptspath)
# Disable minification for now, too slow
transproc = subprocess.Popen([python_path + ' ' + sdk_path + '/lib/transcrypt/__main__.py' + ' ' + basename_ext + ' --nomin'], shell=True)
transproc.wait()
if transproc.poll() != 0:
log.print_info('Compiling ' + t.jsscript_prop + ' failed, check console')
os.chdir(cwd)
# Compiled file
assets.add(arm.utils.build_dir() + '/compiled/scripts/__javascript__/' + basename + '.js')
else:
# Write js to file
assetpath = arm.utils.build_dir() + '/compiled/scripts/' + t.jsscript_prop + '.js'
targetpath = arm.utils.get_fp() + '/' + assetpath
with open(targetpath, 'w') as f:
f.write(bpy.data.texts[t.jsscript_prop].as_string())
assets.add(assetpath)
# Write js to file
assetpath = arm.utils.build_dir() + '/compiled/scripts/' + t.jsscript_prop + '.js'
targetpath = arm.utils.get_fp() + '/' + assetpath
with open(targetpath, 'w') as f:
f.write(bpy.data.texts[t.jsscript_prop].as_string())
assets.add(assetpath)
else: # Haxe/Bundled Script
if t.class_name_prop == '': # Empty class name, skip
continue

View file

@ -269,7 +269,7 @@ def build_project(is_play=False, is_publish=False, in_viewport=False, target=Non
if state.target == 'html5':
w, h = arm.utils.get_render_resolution(arm.utils.get_active_scene())
write_data.write_electronjs(w, h)
# write_data.write_electronjs(w, h)
write_data.write_indexhtml(w, h)
# Bundle files from include dir
if os.path.isdir('include'):
@ -339,7 +339,7 @@ def get_khajs_path(in_viewport, target):
return arm.utils.build_dir() + '/krom/krom.js'
elif target == 'krom':
return arm.utils.build_dir() + '/window/krom/krom.js'
else: # browser, electron
else: # browser
return arm.utils.build_dir() + '/html5/kha.js'
def play_project(in_viewport):
@ -393,7 +393,7 @@ def play_project(in_viewport):
if in_viewport:
mode = 'play_viewport'
state.compileproc = compile_project(target_name='krom')
else: # Electron, Browser
else: # Browser
state.compileproc = compile_project(target_name='html5')
threading.Timer(0.1, watch_compile, [mode]).start()
else: # kha.js up to date
@ -423,19 +423,7 @@ def on_compiled(mode): # build, play, play_viewport, publish
# Launch project in new window
elif mode =='play':
if wrd.arm_play_runtime == 'Electron':
electron_app_path = './' + arm.utils.build_dir() + '/electron.js'
if arm.utils.get_os() == 'win':
electron_path = sdk_path + 'win32/Kode Studio.exe'
elif arm.utils.get_os() == 'mac':
electron_path = sdk_path + 'Kode Studio.app/Contents/MacOS/Electron'
else:
electron_path = sdk_path + 'linux64/kodestudio'
state.playproc = subprocess.Popen([electron_path, '--chromedebug', '--remote-debugging-port=9222', '--enable-logging', electron_app_path], stderr=subprocess.PIPE)
watch_play()
elif wrd.arm_play_runtime == 'Browser':
if wrd.arm_play_runtime == 'Browser':
# Start server
os.chdir(arm.utils.get_fp())
t = threading.Thread(name='localserver', target=arm.lib.server.run)

View file

@ -169,8 +169,7 @@ def init_properties():
name="Navigation", description="Enable camera controls", default='Walk')
bpy.types.World.arm_play_console = BoolProperty(name="Debug Console", description="Show inspector in player", default=False)
bpy.types.World.arm_play_runtime = EnumProperty(
items=[('Electron', 'Electron', 'Electron'),
('Browser', 'Browser', 'Browser'),
items=[('Browser', 'Browser', 'Browser'),
('Native', 'C++', 'Native'),
('Krom', 'Krom', 'Krom')],
name="Runtime", description="Player runtime used when launching in new window", default='Krom', update=assets.invalidate_shader_cache)

View file

@ -23,18 +23,12 @@ class ListTraitItem(bpy.types.PropertyGroup):
type_prop = bpy.props.EnumProperty(
items = [('Haxe Script', 'Haxe Script', 'Haxe Script'),
('Python Script', 'Python Script', 'Python Script'),
('JS Script', 'JS Script', 'JS Script'),
('Bundled Script', 'Bundled Script', 'Bundled Script'),
('Logic Nodes', 'Logic Nodes', 'Logic Nodes')
],
name = "Type")
# data_prop = bpy.props.StringProperty(
# name="Data",
# description="A name for this item",
# default="")
class_name_prop = bpy.props.StringProperty(
name="Class",
description="A name for this item",
@ -320,8 +314,8 @@ class ToolsTraitsPanel(bpy.types.Panel):
else: # Bundled
layout.operator("arm.edit_bundled_script")
# JS/Python Script
elif item.type_prop == 'JS Script' or item.type_prop == 'Python Script':
# JS Script
elif item.type_prop == 'JS Script':
item.name = item.jsscript_prop
row = layout.row()
row.prop_search(item, "jsscript_prop", bpy.data, "texts", "Text")

View file

@ -201,29 +201,6 @@ class Main {
}
""")
# Write electron.js
def write_electronjs(w, h):
wrd = bpy.data.worlds['Arm']
with open(arm.utils.build_dir() + '/electron.js', 'w') as f:
f.write(
"""// Auto-generated
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({width: """ + str(int(w)) + """, height: """ + str(int(h)) + """, autoHideMenuBar: true, useContentSize: true});
mainWindow.loadURL('file://' + __dirname + '/html5/index.html');
//mainWindow.loadURL('http://localhost:8040/""" + arm.utils.build_dir() + """/html5/index.html');
mainWindow.on('closed', function() { mainWindow = null; });
}
app.on('ready', createWindow);
app.on('window-all-closed', function () { app.quit(); });
app.on('activate', function () { if (mainWindow === null) { createWindow(); } });
""")
# Write index.html
def write_indexhtml(w, h):
if not os.path.exists(arm.utils.build_dir() + '/html5'):