Changeset View
Standalone View
binaries/data/mods/public/autostart/entrypoint.js
- This file was added.
/** | |||||
* Implement autostart for the public mod. | |||||
* We want to avoid relying on too many specific files, so we'll mock a few engine functions. | |||||
* Depending on the path, these may get overwritten with the real function. | |||||
*/ | |||||
Engine.HasXmppClient = () => false; | |||||
Engine.SetRankedGame = () => {}; | |||||
Engine.TextureExists = () => false; | |||||
lyv: A JS Proxy might clean this up as you could just handle all these no-ops without explicitly… | |||||
Done Inline ActionsYou mean make Engine a proxy ? TBH I think I can remove a fair number of those now. wraitii: You mean make Engine a proxy ?
TBH I think I can remove a fair number of those now. | |||||
Not Done Inline ActionsPhab was laggy and didn't post. Something like const PolyfilledEngine = new Proxy(Engine, handlers): Just a pure JS level abstraction. lyv: Phab was laggy and didn't post.
Something like
`const PolyfilledEngine = new Proxy(Engine… | |||||
Done Inline ActionsAh right, it's not possible to reassign. I assumed since the object isn't deep frozen, it's not const. lyv: Ah right, it's not possible to reassign. I assumed since the object isn't deep frozen, it's not… | |||||
Engine.PushGuiPage = () => {}; | |||||
Engine.SwitchGuiPage = () => {}; | |||||
var translateObjectKeys = () => {} | |||||
var translate = x => x; | |||||
var translateWithContext = x => x; | |||||
// MsgBox is used in the failure path. | |||||
// TODO: clean this up and show errors better in the non-visual path. | |||||
Engine.LoadScript("gui/common/functions_msgbox.js"); | |||||
lyvUnsubmitted Not Done Inline ActionsIf this is here, Engine.LoadScript("globalscripts/"); ought to be here too. lyv: If this is here, `Engine.LoadScript("globalscripts/");` ought to be here too. | |||||
var autostartInstance; | |||||
function autostartClient(initData) | |||||
{ | |||||
Engine.LoadScript("globalscripts/"); | |||||
autostartInstance = new AutoStartClient(initData); | |||||
Not Done Inline ActionsDoesn't this also need globalscripts? There is a sprintf and translate call in there. lyv: Doesn't this also need `globalscripts`? There is a sprintf and translate call in there. | |||||
} | |||||
/** | |||||
* This path depends on files currently stored under gui/, which should be moved. | |||||
* The best place would probably be a new 'engine' mod, independent from the 'mod' mod and the public mod. | |||||
*/ | |||||
function autostartHost(initData, networked = false) | |||||
{ | |||||
Engine.LoadScript("globalscripts/"); | |||||
Not Done Inline ActionsI would find Init.js : Init() more helpful in describing these are invoked natively. lyv: I would find Init.js : Init() more helpful in describing these are invoked natively. | |||||
Done Inline ActionsI don't think I understand what you mean exactly here:
wraitii: I don't think I understand what you mean exactly here:
- rename the functions?
- rename the… | |||||
Not Done Inline ActionsBoth to be honest, but since there is no consistency, no strong opinion. rmgen loads library.js, the ai loads everything in [ai_name]/ and call a constructor. What I had in mind was an init.js file with init(data) that conditionally calls either autostartClient or autostartHost. lyv: Both to be honest, but since there is no consistency, no strong opinion. rmgen loads library.js… | |||||
Done Inline ActionsCan't say I have a very strong opinion on this. The GUI uses init(data) but I actually wanted to differentiate this from the GUI path, since we're _not_ using the GUI. Think I'll keep as is. wraitii: Can't say I have a very strong opinion on this. The GUI uses `init(data)` but I actually wanted… | |||||
Engine.LoadScript("gui/common/color.js"); | |||||
Not Done Inline ActionsShouldn't this be implicitly loaded? lyv: Shouldn't this be implicitly loaded? | |||||
Done Inline ActionsCould load it C++ side, but by itself the global scripts aren't loaded in all script interfaces. wraitii: Could load it C++ side, but by itself the global scripts aren't loaded in all script interfaces. | |||||
Engine.LoadScript("gui/common/functions_utility.js"); | |||||
Engine.LoadScript("gui/common/Observable.js"); | |||||
Engine.LoadScript("gui/common/settings.js"); | |||||
Not Done Inline ActionsThese might end up cleaner with ES modules. Semantically it wouldn't really make a difference, but such dependencies could be imported more cleanly as the loading code would be implicit. Allowed directories could be made explicit. In this case, imports would resolve in gamesettings or gui/common I guess. I proposed D4575 for usage in a map library in the future, but maybe it could be applicable elsewhere. lyv: These might end up cleaner with ES modules. Semantically it wouldn't really make a difference… | |||||
Done Inline ActionsYeah I think using modules in general would be good, particularly in the GUI. There's a little C++ implementation work to do, and then we need to consider how we want to handle scoping, hotloading and things like that. I hadn't seen your diff, I think I have a POC somewhere as well. wraitii: Yeah I think using modules in general would be good, particularly in the GUI. There's a little… | |||||
Engine.LoadScript("gui/maps/MapCache.js") | |||||
Engine.LoadScript("gamesettings/"); | |||||
Engine.LoadScript("gamesettings/attributes/"); | |||||
if (networked) | |||||
autostartInstance = new AutoStartHost(initData); | |||||
else | |||||
autostartInstance = new AutoStart(initData); | |||||
} | |||||
/** | |||||
* @returns false if the loop should carry on. | |||||
*/ | |||||
function onTick() | |||||
{ | |||||
return autostartInstance.onTick(); | |||||
} |
A JS Proxy might clean this up as you could just handle all these no-ops without explicitly defining these. Seems like yet another place to keep in sync.