2020-07-21 00:07:04 +02:00
import { FixedUiElement } from "./UI/Base/FixedUiElement" ;
2021-01-22 01:03:50 +01:00
import Combine from "./UI/Base/Combine" ;
2021-09-21 02:10:42 +02:00
import MinimapImplementation from "./UI/Base/MinimapImplementation" ;
2021-10-15 05:20:02 +02:00
import { Utils } from "./Utils" ;
import AllThemesGui from "./UI/AllThemesGui" ;
import DetermineLayout from "./Logic/DetermineLayout" ;
import LayoutConfig from "./Models/ThemeConfig/LayoutConfig" ;
2021-11-03 00:44:53 +01:00
import DefaultGUI from "./UI/DefaultGUI" ;
2021-10-15 05:20:02 +02:00
import State from "./State" ;
2021-10-15 14:52:11 +02:00
import ShowOverlayLayerImplementation from "./UI/ShowDataLayer/ShowOverlayLayerImplementation" ;
2021-11-03 00:44:53 +01:00
import { DefaultGuiState } from "./UI/DefaultGuiState" ;
2022-07-13 17:58:01 +02:00
import { QueryParameters } from "./Logic/Web/QueryParameters" ;
import DashboardGui from "./UI/DashboardGui" ;
2022-08-22 13:34:47 +02:00
import StatisticsGUI from "./UI/StatisticsGUI" ;
2021-03-22 02:45:22 +01:00
2021-10-15 14:52:11 +02:00
// Workaround for a stupid crash: inject some functions which would give stupid circular dependencies or crash the other nodejs scripts running from console
2021-09-21 02:10:42 +02:00
MinimapImplementation . initialize ( )
2021-10-15 14:52:11 +02:00
ShowOverlayLayerImplementation . Implement ( ) ;
// Miscelleanous
2021-10-15 05:20:02 +02:00
Utils . DisableLongPresses ( )
2021-03-22 02:45:22 +01:00
2021-10-15 05:20:02 +02:00
class Init {
2021-12-21 19:56:04 +01:00
public static Init ( layoutToUse : LayoutConfig ) {
2020-06-24 00:35:19 +02:00
2021-11-07 16:34:51 +01:00
if ( layoutToUse === null ) {
2021-10-15 05:20:02 +02:00
// Something went wrong, error message is already on screen
return ;
}
2021-11-07 16:34:51 +01:00
2021-10-15 05:20:02 +02:00
if ( layoutToUse === undefined ) {
// No layout found
2022-04-08 04:36:00 +02:00
new AllThemesGui ( ) . setup ( )
2021-10-15 05:20:02 +02:00
return ;
}
2020-06-24 00:35:19 +02:00
2021-10-15 05:20:02 +02:00
const guiState = new DefaultGuiState ( )
State . state = new State ( layoutToUse ) ;
2021-10-31 02:08:39 +01:00
DefaultGuiState . state = guiState ;
2021-10-15 05:20:02 +02:00
// This 'leaks' the global state via the window object, useful for debugging
// @ts-ignore
window . mapcomplete_state = State . state ;
2022-08-22 13:34:47 +02:00
const mode = QueryParameters . GetQueryParameter ( "mode" , "map" , "The mode the application starts in, e.g. 'map', 'dashboard' or 'statistics'" )
2022-08-24 16:02:16 +02:00
if ( mode . data === "dashboard" ) {
2022-07-13 17:58:01 +02:00
new DashboardGui ( State . state , guiState ) . setup ( )
2022-08-22 13:34:47 +02:00
} else {
2022-07-13 17:58:01 +02:00
new DefaultGUI ( State . state , guiState ) . setup ( )
}
2021-05-03 16:04:35 +02:00
}
2021-10-15 05:20:02 +02:00
}
2021-05-28 12:59:48 +02:00
2021-10-15 05:20:02 +02:00
document . getElementById ( "decoration-desktop" ) . remove ( ) ;
2021-05-28 12:59:48 +02:00
new Combine ( [ "Initializing... <br/>" ,
new FixedUiElement ( "<a>If this message persist, something went wrong - click here to try again</a>" )
. SetClass ( "link-underline small" )
. onClick ( ( ) = > {
2021-06-17 00:37:57 +02:00
localStorage . clear ( ) ;
2021-05-28 12:59:48 +02:00
window . location . reload ( true ) ;
} ) ] )
. AttachTo ( "centermessage" ) ; // Add an initialization and reset button if something goes wrong
2021-01-18 19:36:19 +01:00
2021-12-21 18:35:31 +01:00
// @ts-ignore
2021-10-15 05:20:02 +02:00
DetermineLayout . GetLayout ( ) . then ( value = > {
console . log ( "Got " , value )
2021-12-21 19:56:04 +01:00
Init . Init ( value )
2022-01-26 21:40:38 +01:00
} ) . catch ( err = > {
console . error ( "Error while initializing: " , err , err . stack )
} )
2021-10-15 05:20:02 +02:00
2021-05-28 12:59:48 +02:00