Howto:Creating a simple modding framework: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 34: Line 34:


var fgroot = getprop("/sim/fg-root");
var fgroot = getprop("/sim/fg-root");
var modFolder = fgroot ~ '/'~ 'Mods/';
var modFolder = fgroot ~ '/'~ getprop('/sim/modding/mod-directory','Mods/');
# http://wiki.flightgear.org/Nasal_library#directory.28.29
# http://wiki.flightgear.org/Nasal_library#directory.28.29
var modDirectories = directory( modFolder );
var modDirectories = directory( modFolder );

Revision as of 10:18, 10 September 2016

This article is a stub. You can help the wiki by expanding it.


Status

Objective

Background

Directory Structure

Mods should be using their own directory structure, resembling $FG_ROOT (the base package), e.g.:

  • Aircraft
  • GUI
  • Textures
  • Sounds
  • Nasal

etc

Requirements

  • register hooks to invoke callbacks for specific simulator/addon events
  • mutual dependencies

Versioning

1rightarrow.png See FlightGear Version Check for the main article about this subject.

Proof of Concept

The following snippet of code assumes that you put it into $FG_ROOT/Nasal/mod/mod.nas In addition, you need to add a folder to $FG_ROOT named Mods, beneath this folder you can add other folders - with each folder being treated as a separate "mod".

##
# $FG_ROOT/Nasal/mod/loader.nas

var fgroot = getprop("/sim/fg-root");
var modFolder = fgroot ~ '/'~ getprop('/sim/modding/mod-directory','Mods/');
# http://wiki.flightgear.org/Nasal_library#directory.28.29
var modDirectories = directory( modFolder );

# debug.dump( modDirectories );

foreach(var mod; modDirectories) {
print("Mod directory found:", mod);
}

## invoke:
# init code
# setup  code
# loading code
# clean up code