Ticket #3404: 3404_timeElapsed_v1.patch
File 3404_timeElapsed_v1.patch, 3.1 KB (added by , 8 years ago) |
---|
-
source/ps/scripting/JSInterface_VisualReplay.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 48 48 49 49 JS::Value JSI_VisualReplay::GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName) 50 50 { 51 return VisualReplay::GetReplayMetadata( pCxPrivate, directoryName);51 return VisualReplay::GetReplayMetadata(*(pCxPrivate->pScriptInterface), directoryName); 52 52 } 53 53 54 54 void JSI_VisualReplay::SaveReplayMetadata(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& data) -
source/ps/VisualReplay.cpp
238 238 return JSVAL_NULL; 239 239 } 240 240 241 int duration = getReplayDuration(replayStream, fileName, fileSize); 241 int duration = 0; 242 JS::RootedValue metadata(cx, GetReplayMetadata(scriptInterface, directory.string())); 243 if (!metadata.isNull()) 244 { 245 JS::RootedObject metadataObject(cx, &metadata.toObject()); 246 JS::RootedValue timeElapsed(cx); 247 JS_GetProperty(cx, metadataObject, "timeElapsed", &timeElapsed); 248 scriptInterface.FromJSVal(cx, timeElapsed, duration); 249 duration /= 1000; 250 } 251 if (!duration) 252 duration = getReplayDuration(replayStream, fileName, fileSize); 242 253 243 254 SAFE_DELETE(replayStream); 244 255 … … 321 332 return fileInfo.Size() > 0; 322 333 } 323 334 324 JS::Value VisualReplay::GetReplayMetadata(ScriptInterface ::CxPrivate* pCxPrivate, const CStrW& directoryName)335 JS::Value VisualReplay::GetReplayMetadata(ScriptInterface& scriptInterface, const CStrW& directoryName) 325 336 { 326 337 if (!HasReplayMetadata(directoryName)) 327 338 return JSVAL_NULL; 328 339 329 JSContext* cx = pCxPrivate->pScriptInterface->GetContext();340 JSContext* cx = scriptInterface.GetContext(); 330 341 JSAutoRequest rq(cx); 331 342 JS::RootedValue metadata(cx); 332 343 … … 336 347 std::getline(*stream, line); 337 348 stream->close(); 338 349 SAFE_DELETE(stream); 339 pCxPrivate->pScriptInterface->ParseJSON(line, &metadata);350 scriptInterface.ParseJSON(line, &metadata); 340 351 341 352 return metadata; 342 353 } -
source/ps/VisualReplay.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 76 76 /** 77 77 * Returns the metadata of a replay. 78 78 */ 79 JS::Value GetReplayMetadata(ScriptInterface ::CxPrivate* pCxPrivate, const CStrW& directoryName);79 JS::Value GetReplayMetadata(ScriptInterface& scriptInterface, const CStrW& directoryName); 80 80 81 81 /** 82 82 * Saves the metadata from the session to metadata.json