Replace or remove uses of Engine.Console_Write. Patch by Adrian Fatol. Fixes #2141.
Cleans up list utility functions a bit. Removes Engine.Console_Write. This was SVN commit r15556.
This commit is contained in:
parent
4278e93b97
commit
7c82e59ce5
@ -8,69 +8,71 @@
|
||||
// ====================================================================
|
||||
|
||||
// Remove the item at the given index (pos) from the given list object (objectName).
|
||||
function removeItem (objectName, pos)
|
||||
function removeItem(objectName, pos)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "removeItem()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("removeItem(): " + objectName + " not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var list = Engine.GetGUIObjectByName (objectName).list;
|
||||
var selected = Engine.GetGUIObjectByName (objectName).selected;
|
||||
var list = Engine.GetGUIObjectByName(objectName).list;
|
||||
var selected = Engine.GetGUIObjectByName(objectName).selected;
|
||||
|
||||
list.splice(pos, 1);
|
||||
|
||||
Engine.GetGUIObjectByName (objectName).list = list;
|
||||
Engine.GetGUIObjectByName(objectName).list = list;
|
||||
|
||||
// It's important that we update the selection *after*
|
||||
// we've committed the changes to the list.
|
||||
|
||||
// Update the selected so the same element remains selected.
|
||||
if (selected == pos)
|
||||
{
|
||||
Engine.GetGUIObjectByName (objectName).selected = -1;
|
||||
}
|
||||
else
|
||||
if (selected > pos)
|
||||
{
|
||||
Engine.GetGUIObjectByName (objectName).selected = selected - 1;
|
||||
}
|
||||
Engine.GetGUIObjectByName(objectName).selected = -1;
|
||||
else if (selected > pos)
|
||||
Engine.GetGUIObjectByName(objectName).selected = selected - 1;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Add the item at the given index (pos) to the given list object (objectName) with the given value (value).
|
||||
function addItem (objectName, pos, value)
|
||||
function addItem(objectName, pos, value)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "addItem()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("addItem(): " + objectName + " not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var list = Engine.GetGUIObjectByName (objectName).list;
|
||||
var selected = Engine.GetGUIObjectByName (objectName).selected;
|
||||
var list = Engine.GetGUIObjectByName(objectName).list;
|
||||
var selected = Engine.GetGUIObjectByName(objectName).selected;
|
||||
|
||||
list.splice (pos, 0, value);
|
||||
list.splice(pos, 0, value);
|
||||
|
||||
Engine.GetGUIObjectByName (objectName).list = list;
|
||||
Engine.GetGUIObjectByName(objectName).list = list;
|
||||
|
||||
// It's important that we update the selection *after*
|
||||
// we've committed the changes to the list.
|
||||
|
||||
// Update the selected so the same element remains selected.
|
||||
if (selected >= pos)
|
||||
{
|
||||
Engine.GetGUIObjectByName (objectName).selected = selected + 1;
|
||||
}
|
||||
Engine.GetGUIObjectByName(objectName).selected = selected + 1;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Adds an element to the end of the list
|
||||
function pushItem (objectName, value)
|
||||
function pushItem(objectName, value)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "pushItem()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("pushItem(): " + objectName + " not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var list = Engine.GetGUIObjectByName (objectName).list;
|
||||
list.push (value);
|
||||
Engine.GetGUIObjectByName (objectName).list = list;
|
||||
var list = Engine.GetGUIObjectByName(objectName).list;
|
||||
list.push(value);
|
||||
Engine.GetGUIObjectByName(objectName).list = list;
|
||||
// Point to the new item.
|
||||
Engine.GetGUIObjectByName(objectName).selected = getNumItems(objectName)-1;
|
||||
}
|
||||
@ -78,27 +80,31 @@ function pushItem (objectName, value)
|
||||
// ====================================================================
|
||||
|
||||
// Removes the last element
|
||||
function popItem (objectName)
|
||||
function popItem(objectName)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "popItem()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("popItem(): " + objectName + " not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = Engine.GetGUIObjectByName (objectName).selected;
|
||||
var selected = Engine.GetGUIObjectByName(objectName).selected;
|
||||
removeItem(objectName, getNumItems(objectName)-1);
|
||||
|
||||
if (selected == getNumItems(objectName)-1)
|
||||
{
|
||||
Engine.GetGUIObjectByName(objectName).selected = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Retrieves the number of elements in the list
|
||||
function getNumItems (objectName)
|
||||
function getNumItems(objectName)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "getNumItems()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("getNumItems(): " + objectName + " not found.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
var list = Engine.GetGUIObjectByName(objectName).list;
|
||||
return list.length;
|
||||
@ -107,10 +113,13 @@ function getNumItems (objectName)
|
||||
// ====================================================================
|
||||
|
||||
// Retrieves the value of the item at 'pos'
|
||||
function getItemValue (objectName, pos)
|
||||
function getItemValue(objectName, pos)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "getItemValue()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("getItemValue(): " + objectName + " not found.");
|
||||
return "";
|
||||
}
|
||||
|
||||
var list = Engine.GetGUIObjectByName(objectName).list;
|
||||
return list[pos];
|
||||
@ -119,10 +128,13 @@ function getItemValue (objectName, pos)
|
||||
// ====================================================================
|
||||
|
||||
// Retrieves the value of the currently selected item
|
||||
function getCurrItemValue (objectName)
|
||||
function getCurrItemValue(objectName)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName (objectName) == null)
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "getCurrItemValue()", object: objectName }));
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
warn("getCurrItemValue(): " + objectName + " not found.");
|
||||
return "";
|
||||
}
|
||||
|
||||
if (Engine.GetGUIObjectByName(objectName).selected == -1)
|
||||
return "";
|
||||
@ -134,11 +146,11 @@ function getCurrItemValue (objectName)
|
||||
|
||||
// Sets current item to a given string (which must be one of those
|
||||
// already in the list).
|
||||
function setCurrItemValue (objectName, string)
|
||||
function setCurrItemValue(objectName, string)
|
||||
{
|
||||
if (Engine.GetGUIObjectByName(objectName) == null)
|
||||
{
|
||||
Engine.Console_Write (sprintf(translate("%(functionName)s: %(object)s not found."), { functionName: "setCurrItemValue()", object: objectName }));
|
||||
warn("setCurrItemValue(): " + objectName + " not found.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -158,7 +170,7 @@ function setCurrItemValue (objectName, string)
|
||||
}
|
||||
|
||||
// Return -2 if failed to find value in list.
|
||||
Engine.Console_Write (sprintf(translate("Requested string '%(string)s' not found in %(object)s's list."), { string: string, object: objectName }));
|
||||
warn("Requested string '" + string + "' not found in " + objectName + "'s list.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
@ -4,85 +4,6 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Quick run-down of the basic audio commands:
|
||||
|
||||
// Save the specified audio file to handle "s".
|
||||
// s = new Sound( "audio/music/menu_track.ogg" );
|
||||
|
||||
// Play the sound stored at handle "s" one time (it'll be automatically freed when the playback ends):
|
||||
// s.play();
|
||||
|
||||
// Play the sound stored at handle "s" continuously:
|
||||
// s.loop();
|
||||
|
||||
// Close "s" and free it from memory (use in conjunction with loop()):
|
||||
// s.free();
|
||||
|
||||
// Adjust the gain (volume) of a sound (floating point range between 0 (silent) and 1 (max volume)).
|
||||
// s.setGain(value);
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function newRandomSound(soundType, soundSubType, soundPrePath)
|
||||
{
|
||||
// Return a random audio file by category, to be assigned to a handle.
|
||||
var randomSoundPath;
|
||||
|
||||
switch (soundType)
|
||||
{
|
||||
case "music":
|
||||
randomSoundPath = "audio/music/"
|
||||
break;
|
||||
case "ambient":
|
||||
randomSoundPath = "audio/ambient/" + soundPrePath + "/";
|
||||
break;
|
||||
case "effect":
|
||||
randomSoundPath = soundPrePath + "/";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Get names of sounds (attack, command, select, hit, pain).
|
||||
// or
|
||||
// Get names of "peace", "menu" (theme) and "battle" tracks.
|
||||
var soundArray = Engine.BuildDirEntList(randomSoundPath, "*" + soundSubType + "*", false);
|
||||
if (soundArray.length == 0)
|
||||
{
|
||||
Engine.Console_Write (sprintf("Failed to find sounds matching '*%(subtype)s*'", { soundSubType: subtype }));
|
||||
return undefined;
|
||||
}
|
||||
// Get a random number within the sound's range.
|
||||
var randomSound = getRandom (0, soundArray.length-1);
|
||||
// Set name of track.
|
||||
var randomFileName = soundArray[randomSound];
|
||||
|
||||
// Build path to random audio file.
|
||||
randomSoundPath = randomFileName;
|
||||
|
||||
//Engine.Console_Write("Playing " + randomSoundPath + " ...");
|
||||
|
||||
switch (soundType)
|
||||
{
|
||||
case "music":
|
||||
return new MusicSound(randomSoundPath);
|
||||
break;
|
||||
case "ambient":
|
||||
return new AmbientSound(randomSoundPath);
|
||||
break;
|
||||
case "effect":
|
||||
Engine.Console_Write(sprintf("am loading effect '*%(path)s*'", { path: randomSoundPath }));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new Sound(randomSoundPath);
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function fadeOut (soundHandle, fadeDuration)
|
||||
@ -123,49 +44,3 @@ function crossFade (outHandle, inHandle, fadeDuration)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
|
||||
//const AMBIENT_SOUND = "audio/ambient/dayscape/day_temperate_gen_03.ogg";
|
||||
|
||||
|
||||
//const AMBIENT_TEMPERATE = "temperate";
|
||||
//var currentAmbient;
|
||||
|
||||
//function playRandomAmbient(type)
|
||||
//{
|
||||
// switch (type)
|
||||
// {
|
||||
// case AMBIENT_TEMPERATE:
|
||||
// // Seem to need the underscore at the end of "temperate" to avoid crash
|
||||
// // (Might be caused by trying to randomly load day_temperate.xml)
|
||||
// currentAmbient = newRandomSound("ambient", "temperate_", "dayscape");
|
||||
// if (currentAmbient)
|
||||
// {
|
||||
// currentAmbient.loop();
|
||||
// currentAmbient.setGain(0.8);
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// Engine.Console_Write("Unrecognized ambient type: " + type);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//function stopAmbient()
|
||||
//{
|
||||
// if (currentAmbient)
|
||||
// {
|
||||
// currentAmbient.fade(-1, 0.0, 5.0);
|
||||
// currentAmbient = null;
|
||||
// }
|
||||
//}
|
||||
|
||||
//const BUTTON_SOUND = "audio/interface/ui/ui_button_longclick.ogg";
|
||||
//function playButtonSound()
|
||||
//{
|
||||
// var buttonSound = new Sound(BUTTON_SOUND);
|
||||
// buttonSound.play();
|
||||
//}
|
||||
|
@ -19,7 +19,7 @@ function getCheatsData()
|
||||
{
|
||||
var currentCheat = parseJSONData("simulation/data/cheats/"+fileName+".json");
|
||||
if (Object.keys(cheats).indexOf(currentCheat.Name) !== -1)
|
||||
warn(sprintf("Cheat name '%(name)s' is already present", { name: currentCheat.Name }));
|
||||
warn("Cheat name '" + currentCheat.Name + "' is already present");
|
||||
else
|
||||
cheats[currentCheat.Name] = currentCheat.Data;
|
||||
}
|
||||
@ -225,7 +225,7 @@ function handleNetMessage(message)
|
||||
obj.hidden = false;
|
||||
break;
|
||||
default:
|
||||
error(sprintf("Unrecognised netstatus type %(netType)s", { netType: message.status }));
|
||||
error("Unrecognised netstatus type '" + message.status + "'");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -281,7 +281,7 @@ function handleNetMessage(message)
|
||||
break;
|
||||
|
||||
default:
|
||||
error(sprintf("Unrecognised net message type %(messageType)s", { messageType: message.type }));
|
||||
error("Unrecognised net message type '" + message.type + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@ -497,11 +497,6 @@ function addChatMessage(msg, playerAssignments)
|
||||
{
|
||||
if (msg.context !== "")
|
||||
{
|
||||
Engine.Console_Write(sprintf(translate("(%(context)s) * %(user)s %(message)s"), {
|
||||
context: msg.context,
|
||||
user: username,
|
||||
message: message
|
||||
}));
|
||||
formatted = sprintf(translate("(%(context)s) * %(user)s %(message)s"), {
|
||||
context: msg.context,
|
||||
user: "[color=\"" + playerColor + "\"]" + username + "[/color]",
|
||||
@ -510,10 +505,6 @@ function addChatMessage(msg, playerAssignments)
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine.Console_Write(sprintf(translate("* %(user)s %(message)s"), {
|
||||
user: username,
|
||||
message: message
|
||||
}));
|
||||
formatted = sprintf(translate("* %(user)s %(message)s"), {
|
||||
user: "[color=\"" + playerColor + "\"]" + username + "[/color]",
|
||||
message: message
|
||||
@ -526,11 +517,6 @@ function addChatMessage(msg, playerAssignments)
|
||||
var formattedUserTag = sprintf(translate("<%(user)s>"), { user: "[color=\"" + playerColor + "\"]" + username + "[/color]" })
|
||||
if (msg.context !== "")
|
||||
{
|
||||
Engine.Console_Write(sprintf(translate("(%(context)s) %(userTag)s %(message)s"), {
|
||||
context: msg.context,
|
||||
userTag: userTag,
|
||||
message: message
|
||||
}));
|
||||
formatted = sprintf(translate("(%(context)s) %(userTag)s %(message)s"), {
|
||||
context: msg.context,
|
||||
userTag: formattedUserTag,
|
||||
@ -539,7 +525,6 @@ function addChatMessage(msg, playerAssignments)
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine.Console_Write(sprintf(translate("%(userTag)s %(message)s"), { userTag: userTag, message: message}));
|
||||
formatted = sprintf(translate("%(userTag)s %(message)s"), { userTag: formattedUserTag, message: message});
|
||||
}
|
||||
}
|
||||
|
@ -876,16 +876,12 @@ function playRandomAmbient(type)
|
||||
switch (type)
|
||||
{
|
||||
case AMBIENT_TEMPERATE:
|
||||
// Seem to need the underscore at the end of "temperate" to avoid crash
|
||||
// (Might be caused by trying to randomly load day_temperate.xml)
|
||||
// currentAmbient = newRandomSound("ambient", "temperate_", "dayscape");
|
||||
|
||||
const AMBIENT = "audio/ambient/dayscape/day_temperate_gen_03.ogg";
|
||||
Engine.PlayAmbientSound( AMBIENT, true );
|
||||
Engine.PlayAmbientSound(AMBIENT, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
Engine.Console_Write(sprintf(translate("Unrecognized ambient type: %(ambientType)s"), { ambientType: type }));
|
||||
error("Unrecognized ambient type: '" + type + "'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -46,16 +46,8 @@ void JSI_Console::SetVisibleEnabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivat
|
||||
g_Console->SetVisible(Enabled);
|
||||
}
|
||||
|
||||
void JSI_Console::Write(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring output)
|
||||
{
|
||||
if (!CheckGlobalInitialized())
|
||||
return;
|
||||
g_Console->InsertMessageRaw(output);
|
||||
}
|
||||
|
||||
void JSI_Console::RegisterScriptFunctions(ScriptInterface& scriptInterface)
|
||||
{
|
||||
scriptInterface.RegisterFunction<bool, &JSI_Console::GetVisibleEnabled>("Console_GetVisibleEnabled");
|
||||
scriptInterface.RegisterFunction<void, bool, &JSI_Console::SetVisibleEnabled>("Console_SetVisibleEnabled");
|
||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Console::Write>("Console_Write");
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -25,8 +25,7 @@ namespace JSI_Console
|
||||
bool CheckGlobalInitialized();
|
||||
bool GetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate);
|
||||
void SetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate, bool Enabled);
|
||||
void Write(ScriptInterface::CxPrivate* pCxPrivate, std::wstring output);
|
||||
|
||||
|
||||
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user