Skip to content

Commit

Permalink
Better fix for Import via ${}. deep import plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dougreichard committed Oct 20, 2020
1 parent b11f3ec commit 7ce95a4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/mission-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ class MissionFile {
}
if (!name) {
this.error({ message: `Import without a name` })
} else {
name = await interpolate(name, this.data)
}
if (path.extname(name) === ".js") {
await this.fromScript(name)
Expand Down Expand Up @@ -1065,6 +1067,9 @@ class MissionFile {
/////////////////////////////////////////////
//
this.removePluginsFromImport(mission)
if (mission.plugins) {
Object.assign(this.plugins, mission.plugins)
}
Object.assign(this.data, mission.data)
Object.assign(this.templates, mission.templates)
//main.addErrors(mission)
Expand All @@ -1082,6 +1087,7 @@ class MissionFile {
* @param {MissionFile} mission The Imported Data
*/
removePluginsFromImport(mission) {
delete mission.data._
delete mission.data.utils
delete mission.data.int
delete mission.data.float
Expand Down
4 changes: 2 additions & 2 deletions test/fragments/xml/expected/import-script-simple-fragment.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<mission_data version="1.0">
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
<start>
<big-message/>
<big-message title="Hello, Javascript"/>
<big-message title="template Hello, Javascript"/>
<big-message title="template Hello, Javascript"/>
<big-message title="inline Hello, Javascript"/>
<big-message title="Instance Hello, Plugin"/>
<big-message title="Property Hello, property"/>
Expand Down
6 changes: 6 additions & 0 deletions test/fragments/xml/expected/import-value-import-fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<mission_data version="1.0">
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
<start>
<big_message title="Indirect" subtitle1="Import"/>
</start>
</mission_data>
2 changes: 1 addition & 1 deletion test/fragments/xml/expected/script-simple-fragment.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<mission_data version="1.0">
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
<start>
<big-message title="Hello, Javascript"/>
<big-message title="template Hello, Javascript"/>
<big-message title="inline Hello, Javascript"/>
<big-message title="Instance Hello, Plugin"/>
<big-message title="Property Hello, property"/>
Expand Down
7 changes: 7 additions & 0 deletions test/fragments/xml/import-value-import-fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<mission_data version="1.0">
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
<imports>
<import name="import-value-import-value.xml" />
<import name="import-value-import-${indirect}.xml" />
</imports>
</mission_data>
7 changes: 7 additions & 0 deletions test/fragments/xml/import-value-import-import.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<mission_data version="1.0">
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
<start>
<big_message title="Indirect" subtitle1="Import"/>

</start>
</mission_data>
5 changes: 5 additions & 0 deletions test/fragments/xml/import-value-import-value.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<mission_data version="1.0">
<values>
<value indirect="import"/>
</values>
</mission_data>
2 changes: 1 addition & 1 deletion test/fragments/xml/script-simple-fragment.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<mission_data version="1.0">
<templates>
<template name="test">
<big-message title="${plugins.MyPlugin.message}"/>
<big-message title="template ${plugins.MyPlugin.message}"/>
</template>
</templates>
<mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description>
Expand Down

0 comments on commit 7ce95a4

Please sign in to comment.