Revize 9222f70c
Přidáno uživatelem Fantič před více než 1 rok
src/components/plan/CastlePlanView.tsx | ||
---|---|---|
43 | 43 |
const translateY = useSharedValue(0); |
44 | 44 |
const scale = useSharedValue(DEFAULT_SCALE); |
45 | 45 |
|
46 |
console.log(mapImage.svg.substring(0, 500)) |
|
47 |
|
|
48 | 46 |
const onPanEvent = useAnimatedGestureHandler({ |
49 | 47 |
// handle one finger -> drag / move |
50 | 48 |
onStart: (event, ctx: any) => { |
... | ... | |
138 | 136 |
} |
139 | 137 |
|
140 | 138 |
const handleSvgPress = (event: GestureResponderEvent) => { |
139 |
let locationX = event.nativeEvent.locationX |
|
140 |
let locationY = event.nativeEvent.locationY |
|
141 | 141 |
|
142 |
// TODO ???????????? |
|
143 |
|
|
144 |
const locationX = event.nativeEvent.locationX |
|
145 |
const locationY = event.nativeEvent.locationY |
|
146 |
|
|
147 |
// console.log("x " + event.nativeEvent.locationX + " y " + event.nativeEvent.locationY) |
|
148 |
console.log("view size:") |
|
149 |
console.log("x " + viewSize.width + " y " + viewSize.height) |
|
142 |
// console.log("view size:") |
|
143 |
// console.log("x " + viewSize.width + " y " + viewSize.height) |
|
150 | 144 |
|
151 | 145 |
const viewRatio = viewSize.width / viewSize.height |
152 |
console.log("ratio: " + viewSize.width / viewSize.height) |
|
153 |
console.log("svg size:") |
|
154 |
console.log("x " + mapImage.viewBox.width + " y " + mapImage.viewBox.height) |
|
146 |
// console.log("ratio: " + viewSize.width / viewSize.height)
|
|
147 |
// console.log("svg size:")
|
|
148 |
// console.log("x " + mapImage.viewBox.width + " y " + mapImage.viewBox.height)
|
|
155 | 149 |
const svgRatio = mapImage.viewBox.width / mapImage.viewBox.height |
156 |
console.log("ratio: " + mapImage.viewBox.width / mapImage.viewBox.height) |
|
150 |
// console.log("ratio: " + mapImage.viewBox.width / mapImage.viewBox.height)
|
|
157 | 151 |
|
152 |
|
|
158 | 153 |
let mapX = (locationX / viewSize.width) * mapImage.viewBox.width |
159 | 154 |
let mapY = (locationY / viewSize.height) * mapImage.viewBox.height |
160 | 155 |
|
156 |
// console.log("clicked: x " + locationX + " y " + locationY) |
|
157 |
|
|
161 | 158 |
if(svgRatio > viewRatio){ |
162 | 159 |
// svg is spaced in the middle |
163 | 160 |
// top down is filled |
161 |
let xRatio = viewSize.width / mapImage.viewBox.width |
|
162 |
let yFilled = xRatio * mapImage.viewBox.height |
|
163 |
let offsetY = (viewSize.height - yFilled) / 2 |
|
164 | 164 |
|
165 |
|
|
166 |
// TODO recalculate mapY |
|
165 |
mapY = ((locationY - offsetY) / yFilled) * mapImage.viewBox.height |
|
167 | 166 |
} |
168 | 167 |
else if(svgRatio < viewRatio){ |
169 | 168 |
// svg is spaced in the center |
170 | 169 |
// left right is filled |
170 |
let yRatio = viewSize.height / mapImage.viewBox.height |
|
171 |
let xFilled = yRatio * mapImage.viewBox.width |
|
172 |
let offsetX = (viewSize.width - xFilled) / 2 |
|
171 | 173 |
|
172 |
// TODO recalculate mapX
|
|
174 |
mapX = ((locationX - offsetX) / xFilled) * mapImage.viewBox.width
|
|
173 | 175 |
} |
174 | 176 |
|
175 |
// console.log("x " + mapX + " y " + mapY) |
|
176 |
// console.log("") |
|
177 |
|
|
178 | 177 |
// Check if the touch event is within the bounds of a room |
179 | 178 |
let clickedRoom: Room | undefined = undefined |
180 | 179 |
|
181 |
// TODO set accordingaly |
|
182 | 180 |
const maxNumberDistance = 100 |
183 | 181 |
|
184 | 182 |
let minDistance = Number.MAX_VALUE |
... | ... | |
203 | 201 |
console.log('Room clicked with id:', clickedRoom?.id); |
204 | 202 |
console.log("x " + clickedRoom?.number_x + " y " + clickedRoom?.number_y) |
205 | 203 |
console.log(minDistance) |
206 |
console.log("clicked: x " + locationX + " y " + locationY) |
|
207 | 204 |
console.log("translated clicked: x " + mapX + " y " + mapY) |
208 | 205 |
|
209 | 206 |
if (clickedRoom && minDistance < maxNumberDistance) { |
Také k dispozici: Unified diff
re #10882: CastlePlan: OnTap select room fixed