Skip to content
This repository has been archived by the owner on Oct 13, 2018. It is now read-only.

Commit

Permalink
moved trigger meta data to triggers/, some simple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gajop committed Sep 24, 2013
1 parent e5db253 commit b1d35c6
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 34 deletions.
113 changes: 107 additions & 6 deletions scen_edit/command/save_command.lua
Expand Up @@ -106,13 +106,13 @@ local modinfo = {
name = "__NAME__",
shortName = "__SHORTNAME__",
version = "__VERSION__",
game = "__GAME__", --what
shortGame = "__SHORTGAME__", --what
mutator = "Official", --what
game = "__GAME__", --what is this?
shortGame = "__SHORTGAME__", --what is this?
mutator = "Official", --what is this?
description = "__DESCRIPTION__",
modtype = "1", --what
modtype = "1",
depend = {
"ToolBox v0.2" --FIXME: hardcoded version
"__GAME_NAME__ __GAME_VERSION__",
}
}
return modinfo]]
Expand All @@ -123,10 +123,111 @@ return modinfo]]
:gsub("__VERSION__", scenarioInfo.version)
:gsub("__GAME__", scenarioInfo.name)
:gsub("__SHORTGAME__", scenarioInfo.name)
:gsub("__DESCRIPTION__", scenarioInfo.description)
:gsub("__DESCRIPTION__", scenarioInfo.description)
:gsub("__GAME_NAME__", Game.gameName)
:gsub("__GAME_VERSION__", Game.gameVersion)

return modInfoTxt
end

local function GenerateScriptTxt()
local scriptTxt =
[[
[GAME]
{
MapName=Fields_Of_Isis;
StartMetal=1000;
StartEnergy=1000;
StartposType=3;
GameMode=0;
GameType=Tutorial - Running Start r184;
LimitDGun=0;
DiminishingMMs=0;
GhostedBuildings=1;
HostIP=127.0.0.1;
HostPort=8452;
IsHost=1;
MyPlayerNum=0;
MyPlayerName=Player;
NumPlayers=1;
NumTeams=3;
NumUsers=3;
NumRestrictions=0;
MaxSpeed=20;
MinSpeed=0.1;
[MODOPTIONS]
{
}
[PLAYER0]
{
Name=Player;
Spectator=0;
Team=0;
}
[AI1]
{
Name=Hostiles;
ShortName=NullAI;
Team=1;
IsFromDemo=0;
Host=0;
[Options] {}
}
[AI2]
{
Name=Allies;
ShortName=NullAI;
Team=2;
IsFromDemo=0;
Host=0;
[Options] {}
}
[TEAM0]
{
TeamLeader=0;
AllyTeam=0;
RGBColor=0 0 1;
Side=Robots;
Handicap=0;
StartPosX=0;
StartPosZ=0;
}
[TEAM1]
{
TeamLeader=0;
AllyTeam=1;
RGBColor=1 0 0;
Side=Robots;
Handicap=0;
StartPosX=0;
StartPosZ=0;
}
[TEAM2]
{
TeamLeader=0;
AllyTeam=0;
RGBColor=0.03560131 0.3231432 0.001214108;
Side=Robots;
Handicap=0;
StartPosX=0;
StartPosZ=0;
}
[ALLYTEAM0]
{
NumAllies=0;
}
[ALLYTEAM1]
{
NumAllies=0;
}
}
]]

return scriptTxt
end

local function ModInfoSave(path)
local modInfoTxt = GenerateModInfo()
local file = assert(io.open(path, "w"))
Expand Down
13 changes: 11 additions & 2 deletions scen_edit/conf/conf.lua
Expand Up @@ -2,8 +2,17 @@ Conf = LCS.class{}

function Conf:init()
self.C_HEIGHT = 16
self.B_HEIGHT = 26
self.metaModelFiles = { "core.lua" } -- default
self.B_HEIGHT = 26
self.metaModelFiles = {} -- { "core.lua" } default
self:initializeListOfMetaModelFiles()
end

function Conf:initializeListOfMetaModelFiles()
local files = VFS.DirList("triggers")
for i = 1, #files do
local file = files[i]
self.metaModelFiles[#self.metaModelFiles + 1] = file
end
end

function Conf:getMetaModelFiles()
Expand Down
61 changes: 39 additions & 22 deletions scen_edit/meta/meta_model_loader.lua
Expand Up @@ -4,6 +4,22 @@ function MetaModelLoader:init()
self.metaModelFiles = SCEN_EDIT.conf:getMetaModelFiles()
end

function MetaModelLoader:AttemptToLoadFile(metaModelFile)
local success, data = pcall(function() return VFS.LoadFile(metaModelFile) end)
if not success then
Spring.Echo("Failed to load file " .. metaModelFile .. ": " .. data)
return nil
end

local success, data = pcall(function() return assert(loadstring(data))() end)
if not success then
Spring.Echo("Failed to load file " .. metaModelFile .. ": " .. data)
return nil
end

return data
end

function MetaModelLoader:Load()
local metaTypes = {"functions", "actions", "orders", "events"}
local metaModels = {}
Expand All @@ -15,29 +31,30 @@ function MetaModelLoader:Load()
for _, metaType in pairs(metaTypes) do
metaModel[metaType] = {}
end

local data = self:AttemptToLoadFile(metaModelFile)

local data = VFS.LoadFile('scen_edit/meta/' .. metaModelFile)
data = loadstring(data)()

for _, metaType in pairs(metaTypes) do
if data[metaType] then
--Spring.Echo("Loading " .. metaType)
local values = {}
if type(data[metaType]) == "table" then
values = data[metaType]
elseif type(data[metaType]) == "function" then
setfenv(data[metaType], getfenv())
values = data[metaType]()
else
Spring.Echo(type(data[metaModel]))
end
for i = 1, #values do
local value = values[i]
table.insert(metaModel[metaType], value)
end
end
end
table.insert(metaModels, metaModel)
if data ~= nil then
for _, metaType in pairs(metaTypes) do
if data[metaType] then
--Spring.Echo("Loading " .. metaType)
local values = {}
if type(data[metaType]) == "table" then
values = data[metaType]
elseif type(data[metaType]) == "function" then
setfenv(data[metaType], getfenv())
values = data[metaType]()
else
Spring.Echo(type(data[metaModel]))
end
for i = 1, #values do
local value = values[i]
table.insert(metaModel[metaType], value)
end
end
end
table.insert(metaModels, metaModel)
end
end

-- merge meta models
Expand Down
4 changes: 2 additions & 2 deletions scen_edit/view/main_window/tabbed_window.lua
Expand Up @@ -3,7 +3,7 @@ TabbedWindow = LCS.class{}
function TabbedWindow:init()

local generalPanel = GeneralPanel()
local unitPanel = UnitPanel()
local unitFeaturePanel = UnitFeaturePanel()
local terrainPanel = TerrainPanel()
local triggerPanel = TriggerPanel()

Expand All @@ -25,7 +25,7 @@ function TabbedWindow:init()
padding = {0, 0, 0, 0},
tabs = {
{ name = "general", children = {generalPanel:getControl()} },
{ name = "unit", children = {unitPanel:getControl()} },
{ name = "unit", children = {unitFeaturePanel:getControl()} },
{ name = "terrain", children = {terrainPanel:getControl()} },
{ name = "trigger", children = {triggerPanel:getControl()} },
},
Expand Down
4 changes: 2 additions & 2 deletions scen_edit/view/main_window/unit_panel.lua
@@ -1,6 +1,6 @@
UnitPanel = AbstractMainWindowPanel:extends{}
UnitFeaturePanel = AbstractMainWindowPanel:extends{}

function UnitPanel:init()
function UnitFeaturePanel:init()
self:super("init")
self.control:AddChild(Button:New {
height = 80,
Expand Down
File renamed without changes.

0 comments on commit b1d35c6

Please sign in to comment.