ISerializer Search(string dir, IGeneralConfig generalConfig, AssetInfo info) { var combined = Path.Combine(dir, info.File.Filename); var filename = Path.GetFileName(combined).ToUpperInvariant(); dir = Path.GetDirectoryName(combined); var resolved = generalConfig.ResolvePath(dir); if (!Directory.Exists(resolved)) { return(null); } var directory = Path.Combine(resolved, filename); if (Directory.Exists(directory)) { var s = _containerLoaderRegistry.Load(directory, info, ContainerFormat.Directory); if (s != null) { return(s); } } var files = Directory.GetFiles(resolved); foreach (var path in files.Where(x => Path.GetFileNameWithoutExtension(x).ToUpperInvariant() == filename)) { if (info.File.Sha256Hashes != null) { var hash = GetHash(path); if (info.File.Sha256Hashes.All(x => !hash.Equals(x, StringComparison.OrdinalIgnoreCase))) { var expected = string.Join(", ", info.File.Sha256Hashes); CoreUtil.LogWarn( $"Found file {path} for asset {info.AssetId}, but its " + $"hash ({hash}) did not match any of the expected ones ({expected})"); return(null); } } ISerializer s; var extension = Path.GetExtension(path).ToUpperInvariant(); switch (extension) { case ".XLD": s = _containerLoaderRegistry.Load(path, info, ContainerFormat.Xld); break; case ".ZIP": s = _containerLoaderRegistry.Load(path, info, ContainerFormat.Zip); break; default: s = _containerLoaderRegistry.Load(path, info, info.File.ContainerFormat); break; } if (s != null) { return(s); } } return(null); }
protected override void Subscribed() { if (_labyrinthData != null) { return; } var assets = Resolve <IAssetManager>(); _labyrinthData = assets.LoadLabyrinthData(_mapData.LabDataId); if (_labyrinthData == null) { TileSize = Vector3.One * 512; return; } TileSize = new Vector3(_labyrinthData.EffectiveWallWidth, _labyrinthData.WallHeight, _labyrinthData.EffectiveWallWidth); _selection = AttachChild(new Selection3D()); AttachChild(new MapRenderable3D(MapId, _mapData, _labyrinthData, TileSize)); AttachChild(new ScriptManager()); if (!_labyrinthData.BackgroundId.IsNone) { AttachChild(new Skybox(_labyrinthData.BackgroundId)); } var palette = assets.LoadPalette(_mapData.PaletteId); uint backgroundColour = palette.GetPaletteAtTime(0)[_labyrinthData.BackgroundColour]; _backgroundRed = (backgroundColour & 0xff) / 255.0f; _backgroundGreen = (backgroundColour & 0xff00 >> 8) / 255.0f; _backgroundBlue = (backgroundColour & 0xff0000 >> 16) / 255.0f; //if(_labyrinthData.CameraHeight != 0) // Debugger.Break(); //if(_labyrinthData.Unk12 != 0) // 7=1|2|4 (Jirinaar), 54=32|16|4|2, 156=128|16|8|2 (Tall town) // Debugger.Break(); var maxObjectHeightRaw = _labyrinthData.ObjectGroups.Max(x => x.SubObjects.Max(y => (int?)y.Y)); float objectYScaling = TileSize.Y / _labyrinthData.WallHeight; if (maxObjectHeightRaw > _labyrinthData.WallHeight * 1.5f) { objectYScaling /= 2; // TODO: Figure out the proper way to handle this. } Raise(new LogEvent(LogEvent.Level.Info, $"WallHeight: {_labyrinthData.WallHeight} MaxObj: {maxObjectHeightRaw} EffWallWidth: {_labyrinthData.EffectiveWallWidth}")); foreach (var npc in _mapData.Npcs.Values) { if (npc.SpriteOrGroup.Id >= _labyrinthData.ObjectGroups.Count) { CoreUtil.LogWarn($"[3DMap] Tried to load object group {npc.SpriteOrGroup.Id}, but the max group id is {_labyrinthData.ObjectGroups.Count-1}."); continue; } var objectData = _labyrinthData.ObjectGroups[npc.SpriteOrGroup.Id]; // TODO: Verify SpriteOrGroup is an ObjectGroup // TODO: Build proper NPC objects with AI, sound effects etc foreach (var subObject in objectData.SubObjects) { AttachChild(BuildMapObject(npc.Waypoints[0].X, npc.Waypoints[0].Y, subObject, objectYScaling)); } } for (int y = 0; y < _mapData.Height; y++) { for (int x = 0; x < _mapData.Width; x++) { var contents = _mapData.Contents[y * _mapData.Width + x]; if (contents == 0 || contents >= _labyrinthData.ObjectGroups.Count) { continue; } var objectInfo = _labyrinthData.ObjectGroups[contents - 1]; foreach (var subObject in objectInfo.SubObjects) { AttachChild(BuildMapObject(x, y, subObject, objectYScaling)); } } } Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue)); }