From ec6350977a2a787790edfd794a3395fe5cb5262b Mon Sep 17 00:00:00 2001 From: Sidi Liang <1467329765@qq.com> Date: Mon, 26 Apr 2021 22:04:12 +0800 Subject: [PATCH] Nasal: Use nodes to manage properties SmartInstrument and systems: Use pre-initialized Nodes instead of props.getNode --- Nasal/SmartInstruments.nas | 9 ++++----- Nasal/node_setup.nas | 12 ++++++++++++ Nasal/systems.nas | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Nasal/SmartInstruments.nas b/Nasal/SmartInstruments.nas index 2adf890..5535f81 100644 --- a/Nasal/SmartInstruments.nas +++ b/Nasal/SmartInstruments.nas @@ -127,8 +127,7 @@ var SmartInstruments = { return me.infoImageIndex; }, update: func(){ - var currentSpeed = props.getNode("/", 1).getValue("sim/multiplay/generic/float[15]"); - var currentSpeedKMH = sprintf("%i", currentSpeed*1.852); + var currentSpeedKMH = sprintf("%i", vehicleInformation.getSpeedKMH()); me.speedometer.updateText(currentSpeedKMH); if(autospeed.active == 1){ me.speedometer.setColor(0.34, 0.63, 1); @@ -149,10 +148,10 @@ var SmartInstruments = { me.driveMode.updateText("Low Power"); } - var tempC = props.getNode("/", 1).getValue("environment/temperature-degc"); + var tempC = vehicleInformation.environment.temperature.getValue(); me.tempDisplay.updateText(sprintf("%0.1f", tempC)~" °C"); - var hour = props.getNode("/", 1).getValue("sim/time/real/hour"); - var minute = props.getNode("/", 1).getValue("sim/time/real/minute"); + var hour = vehicleInformation.getTimeHour(); + var minute = vehicleInformation.getTimeMinute(); if(minute < 10) minute = "0"~minute; me.timeDisplay.updateText(hour~":"~minute); #runtimeTextAdjust(timeDisplay); diff --git a/Nasal/node_setup.nas b/Nasal/node_setup.nas index 7449c65..a13ca94 100644 --- a/Nasal/node_setup.nas +++ b/Nasal/node_setup.nas @@ -4,6 +4,8 @@ var VehicleInformationManager = { m._speedKTSNode = props.getNode("/sim/multiplay/generic/float[15]", 1); m._headingNode = props.getNode("/orientation/heading-deg",1); m._altitudeFTNode = props.getNode("/position/altitude-ft",1); + m._timeHourNode = props.getNode("sim/time/real/hour", 1); + m._timeMinuteNode = props.getNode("sim/time/real/minute", 1); return m; }, getSpeedKMH: func(){ @@ -18,10 +20,20 @@ var VehicleInformationManager = { getAltitudeFT: func(){ return me._altitudeFTNode.getValue(); }, + getTimeHour: func(){ + return me._timeHourNode.getValue(); + }, + getTimeMinute: func(){ + return me._timeMinuteNode.getValue(); + }, }; var vehicleInformation = VehicleInformationManager.new(); + +#//Environment +vehicleInformation.environment.temperature = props.getNode("environment/temperature-degc", 1); + #//For Engine vehicleInformation.engine = {}; vehicleInformation.engine.throttleNode = props.getNode("/controls/engines/engine/throttle",1); diff --git a/Nasal/systems.nas b/Nasal/systems.nas index b6dd099..b673884 100644 --- a/Nasal/systems.nas +++ b/Nasal/systems.nas @@ -144,8 +144,8 @@ var IndicatorController = { leftIndicator : Indicator.new("left"), rightIndicator : Indicator.new("right"), - leftIndicatorSwitchNode: props.getNode("/controls/lighting/indicator/left_switch", 1), - rightIndicatorSwitchNode: props.getNode("/controls/lighting/indicator/right_switch", 1), + leftIndicatorSwitchNode: vehicleInformation.lighting.indicator.leftSwitch, + rightIndicatorSwitchNode: vehicleInformation.lighting.indicator.rightSwitch, mode:0,